From da2cc1283df5e099bf24ef7796a8bc979f33e798 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Sat, 10 Sep 2011 11:15:15 +0000 Subject: [PATCH] * Use local context instead of global variables * Call Linker methods statically --- .../specials/SpecialGlobalTemplateUsage.php | 76 ++++++++----------- 1 file changed, 33 insertions(+), 43 deletions(-) diff --git a/includes/specials/SpecialGlobalTemplateUsage.php b/includes/specials/SpecialGlobalTemplateUsage.php index 42118b89be..5cecc0ee3c 100644 --- a/includes/specials/SpecialGlobalTemplateUsage.php +++ b/includes/specials/SpecialGlobalTemplateUsage.php @@ -18,37 +18,32 @@ class SpecialGlobalTemplateUsage extends SpecialPage { * Entry point */ public function execute( $par ) { - global $wgOut, $wgRequest; - - $target = $par ? $par : $wgRequest->getVal( 'target' ); + $target = $par ? $par : $this->getRequest()->getVal( 'target' ); $this->target = Title::newFromText( $target ); $this->setHeaders(); $this->showForm(); - if ( is_null( $this->target ) ) { - $wgOut->setPageTitle( wfMsg( 'globaltemplateusage' ) ); - return; - } - - $wgOut->setPageTitle( wfMsg( 'globaltemplateusage-for', $this->target->getPrefixedText() ) ); + if ( $this->target !== null ) { + $this->getOutput()->setPageTitle( wfMsg( 'globaltemplateusage-for', $this->target->getPrefixedText() ) ); - $this->showResult(); + $this->showResult(); + } } /** * Shows the search form */ private function showForm() { - global $wgScript, $wgOut, $wgRequest; + global $wgScript; /* Build form */ $html = Xml::openElement( 'form', array( 'action' => $wgScript ) ) . "\n"; // Name of SpecialPage - $html .= Html::hidden( 'title', $this->getTitle( )->getPrefixedText( ) ) . "\n"; + $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n"; // Limit - $html .= Html::hidden( 'limit', $wgRequest->getInt( 'limit', 50 ) ); + $html .= Html::hidden( 'limit', $this->getRequest()->getInt( 'limit', 50 ) ); // Input box with target prefilled if available $formContent = "\t" . Xml::input( 'target', 40, is_null( $this->target ) ? '' : $this->target->getPrefixedText( ) ) @@ -61,34 +56,32 @@ class SpecialGlobalTemplateUsage extends SpecialPage { // Wrap the entire form in a nice fieldset $html .= Xml::fieldSet( wfMsg( 'globaltemplateusage-text' ), $formContent ) . "\n"; - $wgOut->addHtml( $html ); + $this->getOutput()->addHtml( $html ); } /** - * Creates as queryer and executes it based on $wgRequest + * Creates as queryer and executes it based on the WebRequest object */ private function showResult() { - global $wgRequest; - + $request = $this->getRequest(); $query = new GlobalUsageQuery( $this->target ); - // Extract params from $wgRequest - if ( $wgRequest->getText( 'from' ) ) { - $query->setOffset( $wgRequest->getText( 'from' ) ); - } elseif ( $wgRequest->getText( 'to' ) ) { - $query->setOffset( $wgRequest->getText( 'to' ), true ); + // Extract params from the WebRequest object + if ( $request->getText( 'from' ) ) { + $query->setOffset( $request->getText( 'from' ) ); + } elseif ( $request->getText( 'to' ) ) { + $query->setOffset( $request->getText( 'to' ), true ); } - $query->setLimit( $wgRequest->getInt( 'limit', 50 ) ); + $query->setLimit( $request->getInt( 'limit', 50 ) ); // Perform query $query->searchTemplate(); - // Show result - global $wgOut; + $out = $this->getOutput(); // Don't show form element if there is no data if ( $query->count() == 0 ) { - $wgOut->addWikiMsg( 'globaltemplateusage-no-results', $this->target->getPrefixedText( ) ); + $out->addWikiMsg( 'globaltemplateusage-no-results', $this->target->getPrefixedText( ) ); return; } @@ -96,24 +89,24 @@ class SpecialGlobalTemplateUsage extends SpecialPage { $targetName = $this->target->getPrefixedText( ); // Top navbar - $wgOut->addHtml( $navbar ); + $out->addHtml( $navbar ); - $wgOut->addHtml( '
' ); + $out->addHtml( '
' ); foreach ( $query->getSingleResult() as $wiki => $result ) { - $wgOut->addHtml( + $out->addHtml( '

' . wfMsgExt( 'globaltemplateusage-on-wiki', 'parseinline', $targetName, WikiMap::getWikiName( $wiki ) ) . "

    \n" ); foreach ( $result as $item ) { - $wgOut->addHtml( "\t
  • " . self::formatItem( $item ) . "
  • \n" ); + $out->addHtml( "\t
  • " . self::formatItem( $item ) . "
  • \n" ); } - $wgOut->addHtml( "
\n" ); + $out->addHtml( "\n" ); } - $wgOut->addHtml( '
' ); + $out->addHtml( '
' ); // Bottom navbar - $wgOut->addHtml( $navbar ); + $out->addHtml( $navbar ); } /** @@ -139,13 +132,10 @@ class SpecialGlobalTemplateUsage extends SpecialPage { * @return string Navbar HTML */ protected function getNavBar( $query ) { - global $wgLang, $wgUser; - - $skin = $wgUser->getSkin(); - + $lang = $this->getLang(); $target = $this->target->getPrefixedText(); $limit = $query->getLimit(); - $fmtLimit = $wgLang->formatNum( $limit ); + $fmtLimit = $lang->formatNum( $limit ); # Find out which strings are for the prev and which for the next links $offset = $query->getOffsetString(); @@ -172,7 +162,7 @@ class SpecialGlobalTemplateUsage extends SpecialPage { if ( $to ) { $attr = array( 'title' => $pTitle, 'class' => 'mw-prevlink' ); $q = array( 'limit' => $limit, 'to' => $to, 'target' => $target ); - $plink = $skin->link( $title, $prev, $attr, $q ); + $plink = Linker::link( $title, $prev, $attr, $q ); } else { $plink = $prev; } @@ -181,7 +171,7 @@ class SpecialGlobalTemplateUsage extends SpecialPage { if ( $from ) { $attr = array( 'title' => $nTitle, 'class' => 'mw-nextlink' ); $q = array( 'limit' => $limit, 'from' => $from, 'target' => $target ); - $nlink = $skin->link( $title, $next, $attr, $q ); + $nlink = Linker::link( $title, $next, $attr, $q ); } else { $nlink = $next; } @@ -189,15 +179,15 @@ class SpecialGlobalTemplateUsage extends SpecialPage { # Make links to set number of items per page $numLinks = array(); foreach ( array( 20, 50, 100, 250, 500 ) as $num ) { - $fmtLimit = $wgLang->formatNum( $num ); + $fmtLimit = $lang->formatNum( $num ); $q = array( 'offset' => $offset, 'limit' => $num, 'target' => $target ); $lTitle = wfMsgExt( 'shown-title', array( 'parsemag', 'escape' ), $num ); $attr = array( 'title' => $lTitle, 'class' => 'mw-numlink' ); - $numLinks[] = $skin->link( $title, $fmtLimit, $attr, $q ); + $numLinks[] = Linker::link( $title, $fmtLimit, $attr, $q ); } - $nums = $wgLang->pipeList( $numLinks ); + $nums = $lang->pipeList( $numLinks ); return wfMsgHtml( 'viewprevnext', $plink, $nlink, $nums ); } -- 2.20.1