r68601 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68600‎ | r68601 | r68602 >
Date:07:35, 26 June 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
r68514 didn't work properly. This should fix it.
Modified paths:
  • /trunk/extensions/Translate/SpecialTranslationStats.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/SpecialTranslationStats.php
@@ -290,38 +290,36 @@
291291 $increment = 3600 * 24;
292292 if ( $opts['scale'] === 'hours' ) $increment = 3600;
293293
 294+ $labels = $so->labels();
 295+ if ( count($labels) ) {
 296+ $keys = array_keys( $labels );
 297+ $values = array_pad( array(), count( $labels ), 0 );
 298+ $defaults = array_combine( $keys, $values );
 299+ } else {
 300+ $defaults = array( '0' => '0' );
 301+ }
 302+
294303 $data = array();
295304 while ( $cutoff < $now ) {
296305 $date = $wgLang->sprintfDate( $dateFormat, wfTimestamp( TS_MW, $cutoff ) );
297306 $cutoff += $increment;
298 - $data[$date] = array();
 307+ $data[$date] = $defaults;
299308 }
300309
301310 // Processing
 311+ $labelToIndex = array_flip( $labels );
302312 foreach ( $res as $row ) {
303313 $date = $wgLang->sprintfDate( $dateFormat, $row->rc_timestamp );
304314
305 - $indexes = $so->indexOf( $row );
306 - if ( $indexes === false ) continue;
 315+ $indexLabels = $so->indexOf( $row );
 316+ if ( $indexLabels === false ) continue;
307317
308 - foreach ( (array) $indexes as $index ) {
309 - if ( !isset( $data[$date][$index] ) ) $data[$date][$index] = 0;
310 - $data[$date][$index]++;
 318+ foreach ( (array) $indexLabels as $i ) {
 319+ if ( !isset( $labelToIndex[$i] ) ) continue;
 320+ $data[$date][$labelToIndex[$i]]++;
311321 }
312322 }
313323
314 - $labels = $so->labels();
315 -
316 - /* Make sure there is empty entries for silent days, or otherwise
317 - * they will be skipped alltogether. */
318 - foreach ( $data as &$date ) {
319 - foreach ( $labels as $label ) {
320 - if ( !isset( $date[$label] ) ) {
321 - $date[$label] = 0;
322 - }
323 - }
324 - }
325 -
326324 return array( $labels, $data );
327325 }
328326
@@ -360,9 +358,11 @@
361359 if ( $legend !== null )
362360 $plot->SetLegend( $legend );
363361
364 - $plot->setFont( 'x_label', null, 8 );
365 - $plot->setFont( 'y_label', null, 8 );
 362+ $numberFont = FCFontFinder::find( 'en' );
366363
 364+ $plot->setFont( 'x_label', $numberFont, 8 );
 365+ $plot->setFont( 'y_label', $numberFont, 8 );
 366+
367367 $yTitle = wfMsg( 'translate-stats-' . $opts['count'] );
368368
369369 // Turn off X axis ticks and labels because they get in the way:
@@ -459,42 +459,52 @@
460460
461461 list( $key, $code ) = TranslateUtils::figureMessage( $row->rc_title );
462462
 463+ $groups = array();
 464+ $codes = array();
 465+
463466 if ( $this->groups ) {
464467 /* Get list of keys that the message belongs to, and filter
465468 * out those which are not requested */
466469 $groups = TranslateUtils::messageKeyToGroups( $row->rc_namespace, $key );
467 - $keys = array_intersect( $this->groups, $groups );
468 - } else {
469 - $keys[] = '';
 470+ $groups = array_intersect( $this->groups, $groups );
470471 }
 472+
471473 if ( $this->codes ) {
472 - foreach ( $keys as &$value ) {
473 - if ( $value === '' ) {
474 - $value = $code;
475 - } else {
476 - $value .= " ($code)";
477 - }
478 - }
 474+ $codes = array( $code );
479475 }
480 - return $keys;
 476+ return $this->combineTwoArrays( $groups, $codes );
481477 }
482478
483479 public function labels() {
484 - $labels = array();
485 - if ( $this->groups && $this->codes ) {
486 - foreach ( $this->codes as $code ) {
487 - foreach ( $this->groups as $group ) {
488 - $labels[] = "$group ($code)";
489 - }
490 - }
491 - } elseif ( $this->groups ) {
492 - $labels = $this->groups;
493 - } elseif ( $this->codes ) {
494 - $labels = $this->codes;
 480+ return $this->combineTwoArrays( $this->groups, $this->codes );
 481+ }
 482+
 483+ protected function makeLabel( $group, $code ) {
 484+ if ( $code ) {
 485+ global $wgLang;
 486+ $code = TranslateUtils::getLanguageName( $code, false, $wgLang->getCode() ) . " ($code)";
 487+ }
 488+
 489+ if ( $group && $code ) {
 490+ return "$group @ $code";
 491+ } elseif ( $group || $code ) {
 492+ return "$group$code";
495493 } else {
496 - $labels = array();
 494+ return "Test";
497495 }
498 - return $labels;
499496 }
500497
 498+ protected function combineTwoArrays( $groups, $codes ) {
 499+ if ( !count( $groups ) ) $groups[] = false;
 500+ if ( !count( $codes ) ) $codes[] = false;
 501+
 502+ $items = array();
 503+ foreach ( $groups as $group ) {
 504+ foreach ( $codes as $code ) {
 505+ $items[] = $this->makeLabel( $group, $code );
 506+ }
 507+ }
 508+ return $items;
 509+ }
 510+
501511 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r68514Try to unbreak per-language graphs....nikerabbit13:15, 24 June 2010

Status & tagging log