r71469 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71468‎ | r71469 | r71470 >
Date:11:02, 23 August 2010
Author:siebrand
Status:deferred
Tags:
Comment:
Update code formatting.
Modified paths:
  • /trunk/extensions/Translate/SpecialTranslationStats.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/SpecialTranslationStats.php
@@ -14,10 +14,9 @@
1515 * @ingroup SpecialPage
1616 * @todo Needs documentation.
1717 */
18 -class SpecialTranslationStats extends SpecialPage {
 18+class SpecialTranslationStats extends IncludableSpecialPage {
1919 public function __construct() {
2020 parent::__construct( 'TranslationStats' );
21 - $this->includable( true );
2221 }
2322
2423 public function execute( $par ) {
@@ -37,11 +36,16 @@
3837 $opts->fetchValuesFromRequest( $wgRequest );
3938
4039 $pars = explode( ';', $par );
 40+
4141 foreach ( $pars as $item ) {
42 - if ( strpos( $item, '=' ) === false ) continue;
 42+ if ( strpos( $item, '=' ) === false ) {
 43+ continue;
 44+ }
 45+
4346 list( $key, $value ) = array_map( 'trim', explode( '=', $item, 2 ) );
44 - if ( isset( $opts[$key] ) )
 47+ if ( isset( $opts[$key] ) ) {
4548 $opts[$key] = $value;
 49+ }
4650 }
4751
4852 $opts->validateIntBounds( 'days', 1, 10000 );
@@ -49,11 +53,18 @@
5054 $opts->validateIntBounds( 'height', 200, 1000 );
5155
5256 $validScales = array( 'months', 'weeks', 'days', 'hours' );
53 - if ( !in_array( $opts['scale'], $validScales ) ) $opts['scale'] = 'days';
54 - if ( $opts['scale'] === 'hours' ) $opts->validateIntBounds( 'days', 1, 4 );
 57+ if ( !in_array( $opts['scale'], $validScales ) ) {
 58+ $opts['scale'] = 'days';
 59+ }
5560
 61+ if ( $opts['scale'] === 'hours' ) {
 62+ $opts->validateIntBounds( 'days', 1, 4 );
 63+ }
 64+
5665 $validCounts = array( 'edits', 'users', 'registrations' );
57 - if ( !in_array( $opts['count'], $validCounts ) ) $opts['count'] = 'edits';
 66+ if ( !in_array( $opts['count'], $validCounts ) ) {
 67+ $opts['count'] = 'edits';
 68+ }
5869
5970 foreach ( array( 'group', 'language' ) as $t ) {
6071 $values = array_map( 'trim', explode( ',', $opts[$t] ) );
@@ -70,7 +81,10 @@
7182 // Cache for two hours
7283 if ( !$opts['preview'] ) {
7384 $lastMod = $wgOut->checkLastModified( wfTimestamp( TS_MW, time() - 2 * 3600 ) );
74 - if ( $lastMod ) return;
 85+
 86+ if ( $lastMod ) {
 87+ return;
 88+ }
7589 }
7690
7791 if ( !$wgRequest->getBool( 'debug' ) ) {
@@ -124,16 +138,26 @@
125139 '</fieldset>'
126140 );
127141
128 - if ( !$opts['preview'] ) return;
 142+ if ( !$opts['preview'] ) {
 143+ return;
 144+ }
129145
130146 $spiParams = '';
131147 foreach ( $opts->getChangedValues() as $key => $v ) {
132 - if ( $key === 'preview' ) continue;
133 - if ( $spiParams !== '' ) $spiParams .= ';';
 148+ if ( $key === 'preview' ) {
 149+ continue;
 150+ }
 151+
 152+ if ( $spiParams !== '' ) {
 153+ $spiParams .= ';';
 154+ }
 155+
134156 $spiParams .= wfEscapeWikiText( "$key=$v" );
135157 }
136158
137 - if ( $spiParams !== '' ) $spiParams = '/' . $spiParams;
 159+ if ( $spiParams !== '' ) {
 160+ $spiParams = '/' . $spiParams;
 161+ }
138162
139163 $titleText = $this->getTitle()->getPrefixedText();
140164
@@ -160,6 +184,7 @@
161185 protected function eLabel( $name ) {
162186 $label = 'translate-statsf-' . $name;
163187 $label = wfMsgExt( $label, array( 'parsemag', 'escapenoentities' ) );
 188+
164189 return Xml::tags( 'label', array( 'for' => $name ), $label );
165190 }
166191
@@ -177,8 +202,8 @@
178203 }
179204
180205 $s .= implode( ' ', $options );
 206+ $s .= '</td></tr>' . "\n";
181207
182 - $s .= '</td></tr>' . "\n";
183208 return $s;
184209 }
185210
@@ -249,6 +274,7 @@
250275
251276 $jsSelect = new JsSelectToInput( $selector );
252277 $jsSelect->setSourceId( 'mw-group-selector' );
 278+
253279 return $jsSelect;
254280 }
255281
@@ -256,6 +282,7 @@
257283 $title = $this->getTitle();
258284 $cgiparams = wfArrayToCgi( array( 'graphit' => true ), $opts->getAllValues() );
259285 $href = $title->getLocalUrl( $cgiparams );
 286+
260287 return Xml::element( 'img',
261288 array(
262289 'src' => $href,
@@ -276,6 +303,7 @@
277304 }
278305
279306 $now = time();
 307+
280308 /* Ensure that the first item in the graph has full data even
281309 * if it doesn't align with the given 'days' boundary */
282310 $cutoff = $now - ( 3600 * 24 * $opts->getValue( 'days' ) );
@@ -286,11 +314,15 @@
287315 } elseif ( $opts['scale'] === 'weeks' ) {
288316 /* Here we assume that week starts on monday, which does not
289317 * always hold true. Go backwards day by day until we are on monday */
290 - while ( date( 'D', $cutoff ) !== "Mon" ) { $cutoff -= 86400; }
 318+ while ( date( 'D', $cutoff ) !== "Mon" ) {
 319+ $cutoff -= 86400;
 320+ }
291321 $cutoff -= ( $cutoff % 86400 );
292322 } elseif ( $opts['scale'] === 'months' ) {
293323 // Go backwards day by day until we are on the first day of the month
294 - while ( date( 'j', $cutoff ) !== "1" ) { $cutoff -= 86400; }
 324+ while ( date( 'j', $cutoff ) !== "1" ) {
 325+ $cutoff -= 86400;
 326+ }
295327 $cutoff -= ( $cutoff % 86400 );
296328 }
297329
@@ -323,15 +355,24 @@
324356
325357 // Processing
326358 $labelToIndex = array_flip( $labels );
 359+
327360 foreach ( $res as $row ) {
328361 $indexLabels = $so->indexOf( $row );
329 - if ( $indexLabels === false ) continue;
 362+ if ( $indexLabels === false ) {
 363+ continue;
 364+ }
330365
331366 foreach ( (array) $indexLabels as $i ) {
332 - if ( !isset( $labelToIndex[$i] ) ) continue;
 367+ if ( !isset( $labelToIndex[$i] ) ) {
 368+ continue;
 369+
 370+ }
333371 $date = $wgLang->sprintfDate( $dateFormat, $so->getTimestamp( $row ) );
334372 // Ignore values outside range
335 - if ( !isset( $data[$date] ) ) continue;
 373+ if ( !isset( $data[$date] ) ) {
 374+ continue;
 375+ }
 376+
336377 $data[$date][$labelToIndex[$i]]++;
337378 }
338379 }
@@ -359,19 +400,23 @@
360401 $count = count( $resData );
361402 $skip = intval( $count / ( $width / 60 ) - 1 );
362403 $i = $count;
 404+
363405 foreach ( $resData as $date => $edits ) {
364406 if ( $skip > 0 ) {
365407 if ( ( $count - $i ) % $skip !== 0 ) $date = '';
366408 }
 409+
367410 if ( strpos( $date, ';' ) !== false ) {
368411 list( , $date ) = explode( ';', $date, 2 );
369412 }
 413+
370414 array_unshift( $edits, $date );
371415 $data[] = $edits;
372416 $i--;
373417 }
374418
375419 $font = FCFontFinder::find( $wgLang->getCode() );
 420+
376421 if ( $font ) {
377422 $plot->SetDefaultTTFont( $font );
378423 } else {
@@ -379,8 +424,9 @@
380425 }
381426 $plot->SetDataValues( $data );
382427
383 - if ( $legend !== null )
 428+ if ( $legend !== null ) {
384429 $plot->SetLegend( $legend );
 430+ }
385431
386432 $numberFont = FCFontFinder::find( 'en' );
387433
@@ -401,7 +447,10 @@
402448 $max = round( $max, intval( -log( $max, 10 ) ) );
403449
404450 $yTick = 10;
405 - while ( $max / $yTick > $height / 20 ) $yTick *= 2;
 451+ while ( $max / $yTick > $height / 20 ) {
 452+ $yTick *= 2;
 453+ }
 454+
406455 // If we have very small case, ensure that there is at least one tick
407456 $yTick = min( $max, $yTick );
408457 $yTick = self::roundToSignificant( $yTick );
@@ -434,6 +483,7 @@
435484 } elseif ( $scale === 'hours' ) {
436485 $increment = 3600;
437486 }
 487+
438488 return $increment;
439489 }
440490 }
@@ -480,6 +530,7 @@
481531 } elseif ( $this->opts['scale'] === 'hours' ) {
482532 $dateFormat .= ';H';
483533 }
 534+
484535 return $dateFormat;
485536 }
486537 }
@@ -542,9 +593,15 @@
543594 }
544595
545596 $fields[] = 'rc_title';
546 - if ( $this->groups ) $fields[] = 'rc_namespace';
547 - if ( $this->opts['count'] === 'users' ) $fields[] = 'rc_user_text';
548597
 598+ if ( $this->groups ) {
 599+ $fields[] = 'rc_namespace';
 600+ }
 601+
 602+ if ( $this->opts['count'] === 'users' ) {
 603+ $fields[] = 'rc_user_text';
 604+ }
 605+
549606 $type .= '-perlang';
550607 }
551608
@@ -565,12 +622,16 @@
566623 /**
567624 * Do not consider language-less pages.
568625 */
569 - if ( strpos( $row->rc_title, '/' ) === false ) return false;
 626+ if ( strpos( $row->rc_title, '/' ) === false ) {
 627+ return false;
 628+ }
570629
571630 /**
572631 * No filters, just one key to track.
573632 */
574 - if ( !$this->groups && !$this->codes ) return 'all';
 633+ if ( !$this->groups && !$this->codes ) {
 634+ return 'all';
 635+ }
575636
576637 /**
577638 * The key-building needs to be in sync with ::labels().
@@ -592,6 +653,7 @@
593654 if ( $this->codes ) {
594655 $codes = array( $code );
595656 }
 657+
596658 return $this->combineTwoArrays( $groups, $codes );
597659 }
598660
@@ -619,25 +681,38 @@
620682 }
621683
622684 protected function combineTwoArrays( $groups, $codes ) {
623 - if ( !count( $groups ) ) $groups[] = false;
624 - if ( !count( $codes ) ) $codes[] = false;
 685+ if ( !count( $groups ) ) {
 686+ $groups[] = false;
 687+ }
625688
 689+ if ( !count( $codes ) ) {
 690+ $codes[] = false;
 691+ }
 692+
626693 $items = array();
627694 foreach ( $groups as $group ) {
628 - foreach ( $codes as $code ) {
629 - $items[] = $this->makeLabel( $group, $code );
 695+ foreach ( $codes as $code ) {
 696+ $items[] = $this->makeLabel( $group, $code );
 697+ }
630698 }
631 - }
632699 return $items;
633700 }
634701
635702 protected function formatTimestamp( $timestamp ) {
636703 global $wgContLang;
 704+
637705 switch ( $this->opts['scale'] ) {
638 - case 'hours' : $cut = 4; break;
639 - case 'days' : $cut = 6; break;
640 - case 'months': $cut = 8; break;
641 - default : return $wgContLang->sprintfDate( $this->getDateFormat(), $timestamp );
 706+ case 'hours' :
 707+ $cut = 4;
 708+ break;
 709+ case 'days' :
 710+ $cut = 6;
 711+ break;
 712+ case 'months':
 713+ $cut = 8;
 714+ break;
 715+ default :
 716+ return $wgContLang->sprintfDate( $this->getDateFormat(), $timestamp );
642717 }
643718
644719 return substr( $timestamp, 0, -$cut );

Status & tagging log