Index: trunk/extensions/Translate/SpecialTranslationStats.php |
— | — | @@ -290,38 +290,36 @@ |
291 | 291 | $increment = 3600 * 24; |
292 | 292 | if ( $opts['scale'] === 'hours' ) $increment = 3600; |
293 | 293 | |
| 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 | + |
294 | 303 | $data = array(); |
295 | 304 | while ( $cutoff < $now ) { |
296 | 305 | $date = $wgLang->sprintfDate( $dateFormat, wfTimestamp( TS_MW, $cutoff ) ); |
297 | 306 | $cutoff += $increment; |
298 | | - $data[$date] = array(); |
| 307 | + $data[$date] = $defaults; |
299 | 308 | } |
300 | 309 | |
301 | 310 | // Processing |
| 311 | + $labelToIndex = array_flip( $labels ); |
302 | 312 | foreach ( $res as $row ) { |
303 | 313 | $date = $wgLang->sprintfDate( $dateFormat, $row->rc_timestamp ); |
304 | 314 | |
305 | | - $indexes = $so->indexOf( $row ); |
306 | | - if ( $indexes === false ) continue; |
| 315 | + $indexLabels = $so->indexOf( $row ); |
| 316 | + if ( $indexLabels === false ) continue; |
307 | 317 | |
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]]++; |
311 | 321 | } |
312 | 322 | } |
313 | 323 | |
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 | | - |
326 | 324 | return array( $labels, $data ); |
327 | 325 | } |
328 | 326 | |
— | — | @@ -360,9 +358,11 @@ |
361 | 359 | if ( $legend !== null ) |
362 | 360 | $plot->SetLegend( $legend ); |
363 | 361 | |
364 | | - $plot->setFont( 'x_label', null, 8 ); |
365 | | - $plot->setFont( 'y_label', null, 8 ); |
| 362 | + $numberFont = FCFontFinder::find( 'en' ); |
366 | 363 | |
| 364 | + $plot->setFont( 'x_label', $numberFont, 8 ); |
| 365 | + $plot->setFont( 'y_label', $numberFont, 8 ); |
| 366 | + |
367 | 367 | $yTitle = wfMsg( 'translate-stats-' . $opts['count'] ); |
368 | 368 | |
369 | 369 | // Turn off X axis ticks and labels because they get in the way: |
— | — | @@ -459,42 +459,52 @@ |
460 | 460 | |
461 | 461 | list( $key, $code ) = TranslateUtils::figureMessage( $row->rc_title ); |
462 | 462 | |
| 463 | + $groups = array(); |
| 464 | + $codes = array(); |
| 465 | + |
463 | 466 | if ( $this->groups ) { |
464 | 467 | /* Get list of keys that the message belongs to, and filter |
465 | 468 | * out those which are not requested */ |
466 | 469 | $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 ); |
470 | 471 | } |
| 472 | + |
471 | 473 | 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 ); |
479 | 475 | } |
480 | | - return $keys; |
| 476 | + return $this->combineTwoArrays( $groups, $codes ); |
481 | 477 | } |
482 | 478 | |
483 | 479 | 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"; |
495 | 493 | } else { |
496 | | - $labels = array(); |
| 494 | + return "Test"; |
497 | 495 | } |
498 | | - return $labels; |
499 | 496 | } |
500 | 497 | |
| 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 | + |
501 | 511 | } |