r96589 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96588‎ | r96589 | r96590 >
Date:17:34, 8 September 2011
Author:ialex
Status:ok
Tags:
Comment:
* Use local context instead of global variables
* Call Linker methods statically
* Fixed call to non-existing method Linker::makeImageLinkObj()
Modified paths:
  • /trunk/phase3/includes/specials/SpecialGlobalFileUsage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialGlobalFileUsage.php
@@ -13,39 +13,34 @@
1414 * Entry point
1515 */
1616 public function execute( $par ) {
17 - global $wgOut, $wgRequest;
18 -
19 - $target = $par ? $par : $wgRequest->getVal( 'target' );
 17+ $request = $this->getRequest();
 18+ $target = $par ? $par : $request->getVal( 'target' );
2019 $this->target = Title::makeTitleSafe( NS_FILE, $target );
2120
22 - $this->filterLocal = $wgRequest->getCheck( 'filterlocal' );
 21+ $this->filterLocal = $request->getCheck( 'filterlocal' );
2322
2423 $this->setHeaders();
2524
2625 $this->showForm();
2726
28 - if ( is_null( $this->target ) ) {
29 - $wgOut->setPageTitle( wfMsg( 'globalfileusage' ) );
30 - return;
 27+ if ( !is_null( $this->target ) ) {
 28+ $this->getOutput()->setPageTitle( wfMsg( 'globalfileusage-for', $this->target->getPrefixedText() ) );
 29+ $this->showResult();
3130 }
32 -
33 - $wgOut->setPageTitle( wfMsg( 'globalfileusage-for', $this->target->getPrefixedText() ) );
34 -
35 - $this->showResult();
3631 }
3732
3833 /**
3934 * Shows the search form
4035 */
4136 private function showForm() {
42 - global $wgScript, $wgOut, $wgRequest;
 37+ global $wgScript, $wgContLang;
4338
4439 /* Build form */
4540 $html = Xml::openElement( 'form', array( 'action' => $wgScript ) ) . "\n";
4641 // Name of SpecialPage
4742 $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
4843 // Limit
49 - $html .= Html::hidden( 'limit', $wgRequest->getInt( 'limit', 50 ) );
 44+ $html .= Html::hidden( 'limit', $this->getRequest()->getInt( 'limit', 50 ) );
5045 // Input box with target prefilled if available
5146 $formContent = "\t" . Xml::input( 'target', 40, is_null( $this->target ) ? ''
5247 : $this->target->getText() )
@@ -58,50 +53,46 @@
5954 . "\n\t<p>" . Xml::checkLabel( wfMsg( 'globalfileusage-filterlocal' ),
6055 'filterlocal', 'mw-filterlocal', $this->filterLocal ) . '</p>';
6156
62 - if ( !is_null( $this->target ) && wfFindFile( $this->target ) ) {
63 - // Show the image if it exists
64 - global $wgUser, $wgContLang;
65 - $skin = $wgUser->getSkin();
66 -
67 - $html .= $skin->makeImageLinkObj( $this->target,
68 - $this->target->getPrefixedText(),
69 - /* $alt */ '', /* $align */ $wgContLang->alignEnd(),
70 - /* $handlerParams */ array(), /* $framed */ false,
71 - /* $thumb */ true );
 57+ if ( !is_null( $this->target ) ) {
 58+ $file = wfFindFile( $this->target );
 59+ if ( $file !== null ) {
 60+ // Show the image if it exists
 61+ $html .= Linker::makeImageLink2( $this->target, $file,
 62+ array( 'align' => $this->getLang()->alignEnd(), 'thumbnail' => true ) );
 63+ }
7264 }
7365
7466 // Wrap the entire form in a nice fieldset
7567 $html .= Xml::fieldSet( wfMsg( 'globalfileusage-text' ), $formContent ) . "\n</form>";
7668
77 - $wgOut->addHtml( $html );
 69+ $this->getOutput()->addHtml( $html );
7870 }
7971
8072 /**
81 - * Creates as queryer and executes it based on $wgRequest
 73+ * Creates as queryer and executes it based on the WebRequest object
8274 */
8375 private function showResult() {
84 - global $wgRequest;
85 -
 76+ $request = $this->getRequest();
8677 $query = new GlobalUsageQuery( $this->target );
8778
88 - // Extract params from $wgRequest
89 - if ( $wgRequest->getText( 'from' ) ) {
90 - $query->setOffset( $wgRequest->getText( 'from' ) );
91 - } elseif ( $wgRequest->getText( 'to' ) ) {
92 - $query->setOffset( $wgRequest->getText( 'to' ), true );
 79+ // Extract params from the WebRequest object
 80+ if ( $request->getText( 'from' ) ) {
 81+ $query->setOffset( $request->getText( 'from' ) );
 82+ } elseif ( $request->getText( 'to' ) ) {
 83+ $query->setOffset( $request->getText( 'to' ), true );
9384 }
94 - $query->setLimit( $wgRequest->getInt( 'limit', 50 ) );
 85+ $query->setLimit( $request->getInt( 'limit', 50 ) );
9586 $query->filterLocal( $this->filterLocal );
9687
9788 // Perform query
9889 $query->searchFile();
9990
10091 // Show result
101 - global $wgOut;
 92+ $out = $this->getOutput();
10293
10394 // Don't show form element if there is no data
10495 if ( $query->count() == 0 ) {
105 - $wgOut->addWikiMsg( 'globalfileusage-no-results', $this->target->getPrefixedText() );
 96+ $out->addWikiMsg( 'globalfileusage-no-results', $this->target->getPrefixedText() );
10697 return;
10798 }
10899
@@ -110,24 +101,24 @@
111102 $targetName = $this->target->getText();
112103
113104 // Top navbar
114 - $wgOut->addHtml( $navbar );
 105+ $out->addHtml( $navbar );
115106
116 - $wgOut->addHtml( '<div id="mw-globalfileusage-result">' );
 107+ $out->addHtml( '<div id="mw-globalfileusage-result">' );
117108 foreach ( $query->getSingleResult() as $wiki => $result ) {
118 - $wgOut->addHtml(
 109+ $out->addHtml(
119110 '<h2>' . wfMsgExt(
120111 'globalfileusage-on-wiki', 'parseinline',
121112 $targetName, WikiMap::getWikiName( $wiki ) )
122113 . "</h2><ul>\n" );
123114 foreach ( $result as $item ) {
124 - $wgOut->addHtml( "\t<li>" . self::formatItem( $item ) . "</li>\n" );
 115+ $out->addHtml( "\t<li>" . self::formatItem( $item ) . "</li>\n" );
125116 }
126 - $wgOut->addHtml( "</ul>\n" );
 117+ $out->addHtml( "</ul>\n" );
127118 }
128 - $wgOut->addHtml( '</div>' );
 119+ $out->addHtml( '</div>' );
129120
130121 // Bottom navbar
131 - $wgOut->addHtml( $navbar );
 122+ $out->addHtml( $navbar );
132123 }
133124
134125 /**
@@ -153,13 +144,10 @@
154145 * @return string Navbar HTML
155146 */
156147 protected function getNavBar( $query ) {
157 - global $wgLang, $wgUser;
158 -
159 - $skin = $wgUser->getSkin();
160 -
 148+ $lang = $this->getLang();
161149 $target = $this->target->getText();
162150 $limit = $query->getLimit();
163 - $fmtLimit = $wgLang->formatNum( $limit );
 151+ $fmtLimit = $lang->formatNum( $limit );
164152
165153 # Find out which strings are for the prev and which for the next links
166154 $offset = $query->getOffsetString();
@@ -188,7 +176,7 @@
189177 $q = array( 'limit' => $limit, 'to' => $to, 'target' => $target );
190178 if ( $this->filterLocal )
191179 $q['filterlocal'] = '1';
192 - $plink = $skin->link( $title, $prev, $attr, $q );
 180+ $plink = Linker::link( $title, $prev, $attr, $q );
193181 } else {
194182 $plink = $prev;
195183 }
@@ -199,7 +187,7 @@
200188 $q = array( 'limit' => $limit, 'from' => $from, 'target' => $target );
201189 if ( $this->filterLocal )
202190 $q['filterlocal'] = '1';
203 - $nlink = $skin->link( $title, $next, $attr, $q );
 191+ $nlink = Linker::link( $title, $next, $attr, $q );
204192 } else {
205193 $nlink = $next;
206194 }
@@ -207,7 +195,7 @@
208196 # Make links to set number of items per page
209197 $numLinks = array();
210198 foreach ( array( 20, 50, 100, 250, 500 ) as $num ) {
211 - $fmtLimit = $wgLang->formatNum( $num );
 199+ $fmtLimit = $lang->formatNum( $num );
212200
213201 $q = array( 'offset' => $offset, 'limit' => $num, 'target' => $target );
214202 if ( $this->filterLocal )
@@ -215,9 +203,9 @@
216204 $lTitle = wfMsgExt( 'shown-title', array( 'parsemag', 'escape' ), $num );
217205 $attr = array( 'title' => $lTitle, 'class' => 'mw-numlink' );
218206
219 - $numLinks[] = $skin->link( $title, $fmtLimit, $attr, $q );
 207+ $numLinks[] = Linker::link( $title, $fmtLimit, $attr, $q );
220208 }
221 - $nums = $wgLang->pipeList( $numLinks );
 209+ $nums = $lang->pipeList( $numLinks );
222210
223211 return wfMsgHtml( 'viewprevnext', $plink, $nlink, $nums );
224212 }

Status & tagging log