Jdlrobson has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/376580 )
Change subject: Refactor ShortUrl to allow it to be used in printed version ...................................................................... Refactor ShortUrl to allow it to be used in printed version I9232084e049a08ab4221633a446e7c78b2f50bdc will allow us to render short urls inside the printed versions. Change-Id: I07f90c9e98c324c1773c233cb2bca9085dec70b5 --- M ShortUrl.hooks.php 1 file changed, 32 insertions(+), 18 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ShortUrl refs/changes/80/376580/1 diff --git a/ShortUrl.hooks.php b/ShortUrl.hooks.php index 44db8fe..64a68c8 100644 --- a/ShortUrl.hooks.php +++ b/ShortUrl.hooks.php @@ -27,14 +27,12 @@ } /** - * @param $tpl SkinTemplate - * @return bool + * Return the URL to show in the printed version of the page + * + * @return string url for printed version */ - public static function addToolboxLink( &$tpl ) { - global $wgShortUrlTemplate, $wgServer, $wgShortUrlReadOnly; - if ( $wgShortUrlReadOnly ) { - return true; - } + public static function getShortURL( $title, $oldid ) { + global $wgShortUrlTemplate, $wgServer; if ( !is_string( $wgShortUrlTemplate ) ) { $urlTemplate = SpecialPage::getTitleFor( 'ShortUrl', '$1' )->getFullUrl(); @@ -42,7 +40,6 @@ $urlTemplate = $wgServer . $wgShortUrlTemplate; } - $title = $tpl->getSkin()->getTitle(); if ( ShortUrlUtils::needsShortUrl( $title ) ) { try { $shortId = ShortUrlUtils::encodeTitle( $title ); @@ -50,18 +47,35 @@ $shortId = false; } if ( $shortId !== false ) { - $shortURL = str_replace( '$1', $shortId, $urlTemplate ); - $html = Html::rawElement( 'li', [ 'id' => 't-shorturl' ], - Html::Element( 'a', [ - 'href' => $shortURL, - 'title' => wfMessage( 'shorturl-toolbox-title' )->text() - ], - wfMessage( 'shorturl-toolbox-text' )->text() ) - ); - - echo $html; + return str_replace( '$1', $shortId, $urlTemplate ); } } + return false; + } + + /** + * @param $tpl SkinTemplate + * @return bool + */ + public static function addToolboxLink( &$tpl ) { + global $wgShortUrlReadOnly; + if ( $wgShortUrlReadOnly ) { + return true; + } + + $shortURL = self::getShortURL( $tpl->getSkin()->getTitle() ); + if ( $shortURL ) { + $html = Html::rawElement( 'li', [ 'id' => 't-shorturl' ], + Html::Element( 'a', [ + 'href' => $shortURL, + 'title' => wfMessage( 'shorturl-toolbox-title' )->text() + ], + wfMessage( 'shorturl-toolbox-text' )->text() ) + ); + + echo $html; + } + return true; } -- To view, visit https://gerrit.wikimedia.org/r/376580 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I07f90c9e98c324c1773c233cb2bca9085dec70b5 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ShortUrl Gerrit-Branch: master Gerrit-Owner: Jdlrobson <jrob...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits