r92438 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92437‎ | r92438 | r92439 >
Date:15:41, 18 July 2011
Author:ialex
Status:ok
Tags:
Comment:
* Use local context instead of global variables
* Call Linker methods statically
* Use Linker::linkKnown() instead of Linker::link() where possible
Modified paths:
  • /trunk/phase3/includes/specials/SpecialStatistics.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialStatistics.php
@@ -37,11 +37,10 @@
3838 }
3939
4040 public function execute( $par ) {
41 - global $wgOut, $wgMemc;
42 - global $wgDisableCounters, $wgMiserMode;
 41+ global $wgMemc, $wgDisableCounters, $wgMiserMode;
4342
4443 $this->setHeaders();
45 - $wgOut->addModuleStyles( 'mediawiki.special' );
 44+ $this->getOutput()->addModuleStyles( 'mediawiki.special' );
4645
4746 $this->views = SiteStats::views();
4847 $this->edits = SiteStats::edits();
@@ -103,7 +102,7 @@
104103 $text .= "\n" . $footer->parse();
105104 }
106105
107 - $wgOut->addHTML( $text );
 106+ $this->getOutput()->addHTML( $text );
108107 }
109108
110109 /**
@@ -136,60 +135,53 @@
137136 * @return string
138137 */
139138 private function getPageStats() {
140 - global $wgLang;
141139 return Xml::openElement( 'tr' ) .
142140 Xml::tags( 'th', array( 'colspan' => '2' ), wfMsgExt( 'statistics-header-pages', array( 'parseinline' ) ) ) .
143141 Xml::closeElement( 'tr' ) .
144142 $this->formatRow( wfMsgExt( 'statistics-articles', array( 'parseinline' ) ),
145 - $wgLang->formatNum( $this->good ),
 143+ $this->getLang()->formatNum( $this->good ),
146144 array( 'class' => 'mw-statistics-articles' ) ) .
147145 $this->formatRow( wfMsgExt( 'statistics-pages', array( 'parseinline' ) ),
148 - $wgLang->formatNum( $this->total ),
 146+ $this->getLang()->formatNum( $this->total ),
149147 array( 'class' => 'mw-statistics-pages' ),
150148 'statistics-pages-desc' ) .
151149 $this->formatRow( wfMsgExt( 'statistics-files', array( 'parseinline' ) ),
152 - $wgLang->formatNum( $this->images ),
 150+ $this->getLang()->formatNum( $this->images ),
153151 array( 'class' => 'mw-statistics-files' ) );
154152 }
155153 private function getEditStats() {
156 - global $wgLang;
157154 return Xml::openElement( 'tr' ) .
158155 Xml::tags( 'th', array( 'colspan' => '2' ), wfMsgExt( 'statistics-header-edits', array( 'parseinline' ) ) ) .
159156 Xml::closeElement( 'tr' ) .
160157 $this->formatRow( wfMsgExt( 'statistics-edits', array( 'parseinline' ) ),
161 - $wgLang->formatNum( $this->edits ),
 158+ $this->getLang()->formatNum( $this->edits ),
162159 array( 'class' => 'mw-statistics-edits' ) ) .
163160 $this->formatRow( wfMsgExt( 'statistics-edits-average', array( 'parseinline' ) ),
164 - $wgLang->formatNum( sprintf( '%.2f', $this->total ? $this->edits / $this->total : 0 ) ),
 161+ $this->getLang()->formatNum( sprintf( '%.2f', $this->total ? $this->edits / $this->total : 0 ) ),
165162 array( 'class' => 'mw-statistics-edits-average' ) );
166163 }
167164
168165 private function getUserStats() {
169 - global $wgLang, $wgActiveUserDays;
170 - $sk = $this->getSkin();
 166+ global $wgActiveUserDays;
171167 return Xml::openElement( 'tr' ) .
172168 Xml::tags( 'th', array( 'colspan' => '2' ), wfMsgExt( 'statistics-header-users', array( 'parseinline' ) ) ) .
173169 Xml::closeElement( 'tr' ) .
174170 $this->formatRow( wfMsgExt( 'statistics-users', array( 'parseinline' ) ),
175 - $wgLang->formatNum( $this->users ),
 171+ $this->getLang()->formatNum( $this->users ),
176172 array( 'class' => 'mw-statistics-users' ) ) .
177173 $this->formatRow( wfMsgExt( 'statistics-users-active', array( 'parseinline' ) ) . ' ' .
178 - $sk->link(
 174+ Linker::linkKnown(
179175 SpecialPage::getTitleFor( 'Activeusers' ),
180 - wfMsgHtml( 'listgrouprights-members' ),
181 - array(),
182 - array(),
183 - 'known'
 176+ wfMsgHtml( 'listgrouprights-members' )
184177 ),
185 - $wgLang->formatNum( $this->activeUsers ),
 178+ $this->getLang()->formatNum( $this->activeUsers ),
186179 array( 'class' => 'mw-statistics-users-active' ),
187180 'statistics-users-active-desc',
188 - $wgLang->formatNum( $wgActiveUserDays ) );
 181+ $this->getLang()->formatNum( $wgActiveUserDays ) );
189182 }
190183
191184 private function getGroupStats() {
192 - global $wgGroupPermissions, $wgImplicitGroups, $wgLang;
193 - $sk = $this->getSkin();
 185+ global $wgGroupPermissions, $wgImplicitGroups;
194186 $text = '';
195187 foreach( $wgGroupPermissions as $group => $permissions ) {
196188 # Skip generic * and implicit groups
@@ -210,16 +202,15 @@
211203 $grouppageLocalized = $msg->text();
212204 }
213205 $linkTarget = Title::newFromText( $grouppageLocalized );
214 - $grouppage = $sk->link(
 206+ $grouppage = Linker::link(
215207 $linkTarget,
216208 htmlspecialchars( $groupnameLocalized )
217209 );
218 - $grouplink = $sk->link(
 210+ $grouplink = Linker::linkKnown(
219211 SpecialPage::getTitleFor( 'Listusers' ),
220212 wfMsgHtml( 'listgrouprights-members' ),
221213 array(),
222 - array( 'group' => $group ),
223 - 'known'
 214+ array( 'group' => $group )
224215 );
225216 # Add a class when a usergroup contains no members to allow hiding these rows
226217 $classZero = '';
@@ -228,31 +219,28 @@
229220 $classZero = ' statistics-group-zero';
230221 }
231222 $text .= $this->formatRow( $grouppage . ' ' . $grouplink,
232 - $wgLang->formatNum( $countUsers ),
 223+ $this->getLang()->formatNum( $countUsers ),
233224 array( 'class' => 'statistics-group-' . Sanitizer::escapeClass( $group ) . $classZero ) );
234225 }
235226 return $text;
236227 }
237228
238229 private function getViewsStats() {
239 - global $wgLang;
240230 return Xml::openElement( 'tr' ) .
241231 Xml::tags( 'th', array( 'colspan' => '2' ), wfMsgExt( 'statistics-header-views', array( 'parseinline' ) ) ) .
242232 Xml::closeElement( 'tr' ) .
243233 $this->formatRow( wfMsgExt( 'statistics-views-total', array( 'parseinline' ) ),
244 - $wgLang->formatNum( $this->views ),
 234+ $this->getLang()->formatNum( $this->views ),
245235 array ( 'class' => 'mw-statistics-views-total' ), 'statistics-views-total-desc' ) .
246236 $this->formatRow( wfMsgExt( 'statistics-views-peredit', array( 'parseinline' ) ),
247 - $wgLang->formatNum( sprintf( '%.2f', $this->edits ?
 237+ $this->getLang()->formatNum( sprintf( '%.2f', $this->edits ?
248238 $this->views / $this->edits : 0 ) ),
249239 array ( 'class' => 'mw-statistics-views-peredit' ) );
250240 }
251241
252242 private function getMostViewedPages() {
253 - global $wgLang;
254243 $text = '';
255244 $dbr = wfGetDB( DB_SLAVE );
256 - $sk = $this->getSkin();
257245 $res = $dbr->select(
258246 'page',
259247 array(
@@ -277,8 +265,8 @@
278266 foreach ( $res as $row ) {
279267 $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
280268 if( $title instanceof Title ) {
281 - $text .= $this->formatRow( $sk->link( $title ),
282 - $wgLang->formatNum( $row->page_counter ) );
 269+ $text .= $this->formatRow( Linker::link( $title ),
 270+ $this->getLang()->formatNum( $row->page_counter ) );
283271
284272 }
285273 }
@@ -288,8 +276,6 @@
289277 }
290278
291279 private function getOtherStats( $stats ) {
292 - global $wgLang;
293 -
294280 if ( !count( $stats ) )
295281 return '';
296282
@@ -301,7 +287,7 @@
302288 $name = htmlspecialchars( $name );
303289 $number = htmlspecialchars( $number );
304290
305 - $return .= $this->formatRow( $name, $wgLang->formatNum( $number ), array( 'class' => 'mw-statistics-hook' ) );
 291+ $return .= $this->formatRow( $name, $this->getLang()->formatNum( $number ), array( 'class' => 'mw-statistics-hook' ) );
306292 }
307293
308294 return $return;

Status & tagging log