r96719 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96718‎ | r96719 | r96720 >
Date:11:15, 10 September 2011
Author:ialex
Status:ok
Tags:
Comment:
* Use local context instead of global variables
* Call Linker methods statically
Modified paths:
  • /trunk/phase3/includes/specials/SpecialGlobalTemplateUsage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialGlobalTemplateUsage.php
@@ -18,37 +18,32 @@
1919 * Entry point
2020 */
2121 public function execute( $par ) {
22 - global $wgOut, $wgRequest;
23 -
24 - $target = $par ? $par : $wgRequest->getVal( 'target' );
 22+ $target = $par ? $par : $this->getRequest()->getVal( 'target' );
2523 $this->target = Title::newFromText( $target );
2624
2725 $this->setHeaders();
2826
2927 $this->showForm();
3028
31 - if ( is_null( $this->target ) ) {
32 - $wgOut->setPageTitle( wfMsg( 'globaltemplateusage' ) );
33 - return;
34 - }
 29+ if ( $this->target !== null ) {
 30+ $this->getOutput()->setPageTitle( wfMsg( 'globaltemplateusage-for', $this->target->getPrefixedText() ) );
3531
36 - $wgOut->setPageTitle( wfMsg( 'globaltemplateusage-for', $this->target->getPrefixedText() ) );
37 -
38 - $this->showResult();
 32+ $this->showResult();
 33+ }
3934 }
4035
4136 /**
4237 * Shows the search form
4338 */
4439 private function showForm() {
45 - global $wgScript, $wgOut, $wgRequest;
 40+ global $wgScript;
4641
4742 /* Build form */
4843 $html = Xml::openElement( 'form', array( 'action' => $wgScript ) ) . "\n";
4944 // Name of SpecialPage
50 - $html .= Html::hidden( 'title', $this->getTitle( )->getPrefixedText( ) ) . "\n";
 45+ $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
5146 // Limit
52 - $html .= Html::hidden( 'limit', $wgRequest->getInt( 'limit', 50 ) );
 47+ $html .= Html::hidden( 'limit', $this->getRequest()->getInt( 'limit', 50 ) );
5348 // Input box with target prefilled if available
5449 $formContent = "\t" . Xml::input( 'target', 40, is_null( $this->target ) ? ''
5550 : $this->target->getPrefixedText( ) )
@@ -61,34 +56,32 @@
6257 // Wrap the entire form in a nice fieldset
6358 $html .= Xml::fieldSet( wfMsg( 'globaltemplateusage-text' ), $formContent ) . "\n</form>";
6459
65 - $wgOut->addHtml( $html );
 60+ $this->getOutput()->addHtml( $html );
6661 }
6762
6863 /**
69 - * Creates as queryer and executes it based on $wgRequest
 64+ * Creates as queryer and executes it based on the WebRequest object
7065 */
7166 private function showResult() {
72 - global $wgRequest;
73 -
 67+ $request = $this->getRequest();
7468 $query = new GlobalUsageQuery( $this->target );
7569
76 - // Extract params from $wgRequest
77 - if ( $wgRequest->getText( 'from' ) ) {
78 - $query->setOffset( $wgRequest->getText( 'from' ) );
79 - } elseif ( $wgRequest->getText( 'to' ) ) {
80 - $query->setOffset( $wgRequest->getText( 'to' ), true );
 70+ // Extract params from the WebRequest object
 71+ if ( $request->getText( 'from' ) ) {
 72+ $query->setOffset( $request->getText( 'from' ) );
 73+ } elseif ( $request->getText( 'to' ) ) {
 74+ $query->setOffset( $request->getText( 'to' ), true );
8175 }
82 - $query->setLimit( $wgRequest->getInt( 'limit', 50 ) );
 76+ $query->setLimit( $request->getInt( 'limit', 50 ) );
8377
8478 // Perform query
8579 $query->searchTemplate();
8680
87 - // Show result
88 - global $wgOut;
 81+ $out = $this->getOutput();
8982
9083 // Don't show form element if there is no data
9184 if ( $query->count() == 0 ) {
92 - $wgOut->addWikiMsg( 'globaltemplateusage-no-results', $this->target->getPrefixedText( ) );
 85+ $out->addWikiMsg( 'globaltemplateusage-no-results', $this->target->getPrefixedText( ) );
9386 return;
9487 }
9588
@@ -96,24 +89,24 @@
9790 $targetName = $this->target->getPrefixedText( );
9891
9992 // Top navbar
100 - $wgOut->addHtml( $navbar );
 93+ $out->addHtml( $navbar );
10194
102 - $wgOut->addHtml( '<div id="mw-globaltemplateusage-result">' );
 95+ $out->addHtml( '<div id="mw-globaltemplateusage-result">' );
10396 foreach ( $query->getSingleResult() as $wiki => $result ) {
104 - $wgOut->addHtml(
 97+ $out->addHtml(
10598 '<h2>' . wfMsgExt(
10699 'globaltemplateusage-on-wiki', 'parseinline',
107100 $targetName, WikiMap::getWikiName( $wiki ) )
108101 . "</h2><ul>\n" );
109102 foreach ( $result as $item ) {
110 - $wgOut->addHtml( "\t<li>" . self::formatItem( $item ) . "</li>\n" );
 103+ $out->addHtml( "\t<li>" . self::formatItem( $item ) . "</li>\n" );
111104 }
112 - $wgOut->addHtml( "</ul>\n" );
 105+ $out->addHtml( "</ul>\n" );
113106 }
114 - $wgOut->addHtml( '</div>' );
 107+ $out->addHtml( '</div>' );
115108
116109 // Bottom navbar
117 - $wgOut->addHtml( $navbar );
 110+ $out->addHtml( $navbar );
118111 }
119112
120113 /**
@@ -139,13 +132,10 @@
140133 * @return string Navbar HTML
141134 */
142135 protected function getNavBar( $query ) {
143 - global $wgLang, $wgUser;
144 -
145 - $skin = $wgUser->getSkin();
146 -
 136+ $lang = $this->getLang();
147137 $target = $this->target->getPrefixedText();
148138 $limit = $query->getLimit();
149 - $fmtLimit = $wgLang->formatNum( $limit );
 139+ $fmtLimit = $lang->formatNum( $limit );
150140
151141 # Find out which strings are for the prev and which for the next links
152142 $offset = $query->getOffsetString();
@@ -172,7 +162,7 @@
173163 if ( $to ) {
174164 $attr = array( 'title' => $pTitle, 'class' => 'mw-prevlink' );
175165 $q = array( 'limit' => $limit, 'to' => $to, 'target' => $target );
176 - $plink = $skin->link( $title, $prev, $attr, $q );
 166+ $plink = Linker::link( $title, $prev, $attr, $q );
177167 } else {
178168 $plink = $prev;
179169 }
@@ -181,7 +171,7 @@
182172 if ( $from ) {
183173 $attr = array( 'title' => $nTitle, 'class' => 'mw-nextlink' );
184174 $q = array( 'limit' => $limit, 'from' => $from, 'target' => $target );
185 - $nlink = $skin->link( $title, $next, $attr, $q );
 175+ $nlink = Linker::link( $title, $next, $attr, $q );
186176 } else {
187177 $nlink = $next;
188178 }
@@ -189,15 +179,15 @@
190180 # Make links to set number of items per page
191181 $numLinks = array();
192182 foreach ( array( 20, 50, 100, 250, 500 ) as $num ) {
193 - $fmtLimit = $wgLang->formatNum( $num );
 183+ $fmtLimit = $lang->formatNum( $num );
194184
195185 $q = array( 'offset' => $offset, 'limit' => $num, 'target' => $target );
196186 $lTitle = wfMsgExt( 'shown-title', array( 'parsemag', 'escape' ), $num );
197187 $attr = array( 'title' => $lTitle, 'class' => 'mw-numlink' );
198188
199 - $numLinks[] = $skin->link( $title, $fmtLimit, $attr, $q );
 189+ $numLinks[] = Linker::link( $title, $fmtLimit, $attr, $q );
200190 }
201 - $nums = $wgLang->pipeList( $numLinks );
 191+ $nums = $lang->pipeList( $numLinks );
202192
203193 return wfMsgHtml( 'viewprevnext', $plink, $nlink, $nums );
204194 }

Status & tagging log