r110828 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110827‎ | r110828 | r110829 >
Date:09:28, 7 February 2012
Author:bawolff
Status:ok (Comments)
Tags:miscextensions 
Comment:
Make extension not use global $wgOut where it can avoid it
Modified paths:
  • /trunk/extensions/ShortUrl/ShortUrl.hooks.php (modified) (history)
  • /trunk/extensions/ShortUrl/SpecialShortUrl.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ShortUrl/SpecialShortUrl.php
@@ -33,14 +33,14 @@
3434 * @param $par Mixed: Parameters passed to the page
3535 */
3636 public function execute( $par ) {
37 - global $wgOut;
 37+ $out = $this->getOutput();
3838
3939 $title = ShortUrlUtils::decodeURL( $par );
4040 if ( $title !== false ) {
41 - $wgOut->redirect( $title->getFullURL(), '301' );
 41+ $out->redirect( $title->getFullURL(), '301' );
4242 } else {
4343 $parEsc = wfEscapeWikiText( $par );
44 - $wgOut->showErrorPage( 'shorturl-not-found-title', 'shorturl-not-found-message', array( $parEsc ) );
 44+ $out->showErrorPage( 'shorturl-not-found-title', 'shorturl-not-found-message', array( $parEsc ) );
4545 }
4646 }
4747 }
Index: trunk/extensions/ShortUrl/ShortUrl.hooks.php
@@ -19,7 +19,7 @@
2020 * @return bool
2121 */
2222 public static function addToolboxLink( &$tpl ) {
23 - global $wgOut, $wgShortUrlPrefix;
 23+ global $wgShortUrlPrefix;
2424
2525 if ( !is_string( $wgShortUrlPrefix ) ) {
2626 $urlPrefix = SpecialPage::getTitleFor( 'ShortUrl' )->getCanonicalUrl() . '/';
@@ -27,7 +27,7 @@
2828 $urlPrefix = $wgShortUrlPrefix;
2929 }
3030
31 - $title = $wgOut->getTitle();
 31+ $title = $tpl->getSkin()->getTitle();
3232 if ( ShortUrlUtils::needsShortUrl( $title ) ) {
3333 $shortId = ShortUrlUtils::encodeTitle( $title );
3434 $shortURL = $urlPrefix . $shortId;
@@ -50,10 +50,9 @@
5151 * @return bool
5252 */
5353 public static function onOutputPageBeforeHTML( &$out, &$text ) {
54 - global $wgOut;
55 - $title = $wgOut->getTitle();
 54+ $title = $out->getTitle();
5655 if ( ShortUrlUtils::needsShortUrl( $title ) ) {
57 - $wgOut->addModules( 'ext.shortUrl' );
 56+ $out->addModules( 'ext.shortUrl' );
5857 }
5958 return true;
6059 }

Comments

#Comment by Reedy (talk | contribs)   12:35, 7 February 2012

I was going to ask if this was 1.18 compatible, but I just won't bother merging it to 1.18wmf1 unless I have to for some reason later

#Comment by Bawolff (talk | contribs)   12:49, 7 February 2012

It is actually compatible with 1.18.1 (or at least should be, didn't test it on that version)

Status & tagging log