http://www.mediawiki.org/wiki/Special:Code/MediaWiki/68601

Revision: 68601
Author:   nikerabbit
Date:     2010-06-26 07:35:26 +0000 (Sat, 26 Jun 2010)

Log Message:
-----------
r68514 didn't work properly. This should fix it.

Modified Paths:
--------------
    trunk/extensions/Translate/SpecialTranslationStats.php

Modified: trunk/extensions/Translate/SpecialTranslationStats.php
===================================================================
--- trunk/extensions/Translate/SpecialTranslationStats.php      2010-06-26 
06:21:55 UTC (rev 68600)
+++ trunk/extensions/Translate/SpecialTranslationStats.php      2010-06-26 
07:35:26 UTC (rev 68601)
@@ -290,38 +290,36 @@
                $increment = 3600 * 24;
                if ( $opts['scale'] === 'hours' ) $increment = 3600;
 
+               $labels = $so->labels();
+               if ( count($labels) ) {
+                       $keys = array_keys( $labels );
+                       $values = array_pad( array(), count( $labels ), 0 );
+                       $defaults = array_combine( $keys, $values );
+               } else {
+                       $defaults = array( '0' => '0' );
+               }
+
                $data = array();
                while ( $cutoff < $now ) {
                        $date = $wgLang->sprintfDate( $dateFormat, wfTimestamp( 
TS_MW, $cutoff ) );
                        $cutoff += $increment;
-                       $data[$date] = array();
+                       $data[$date] = $defaults;
                }
 
                // Processing
+               $labelToIndex = array_flip( $labels );
                foreach ( $res as $row ) {
                        $date = $wgLang->sprintfDate( $dateFormat, 
$row->rc_timestamp );
 
-                       $indexes = $so->indexOf( $row );
-                       if ( $indexes === false ) continue;
+                       $indexLabels = $so->indexOf( $row );
+                       if ( $indexLabels === false ) continue;
 
-                       foreach ( (array) $indexes as $index ) {
-                               if ( !isset( $data[$date][$index] ) ) 
$data[$date][$index] = 0;
-                               $data[$date][$index]++;
+                       foreach ( (array) $indexLabels as $i ) {
+                               if ( !isset( $labelToIndex[$i] ) ) continue;
+                               $data[$date][$labelToIndex[$i]]++;
                        }
                }
 
-               $labels = $so->labels();
-
-               /* Make sure there is empty entries for silent days, or 
otherwise
-                * they will be skipped alltogether. */
-               foreach ( $data as &$date ) {
-                       foreach ( $labels as $label ) {
-                               if ( !isset( $date[$label] ) ) {
-                                       $date[$label] = 0;
-                               }
-                       }
-               }
-
                return array( $labels, $data );
        }
 
@@ -360,9 +358,11 @@
                if ( $legend !== null )
                        $plot->SetLegend( $legend );
 
-               $plot->setFont( 'x_label', null, 8 );
-               $plot->setFont( 'y_label', null, 8 );
+               $numberFont = FCFontFinder::find( 'en' );
 
+               $plot->setFont( 'x_label', $numberFont, 8 );
+               $plot->setFont( 'y_label', $numberFont, 8 );
+
                $yTitle = wfMsg( 'translate-stats-' . $opts['count'] );
 
                // Turn off X axis ticks and labels because they get in the way:
@@ -459,42 +459,52 @@
 
                list( $key, $code ) = TranslateUtils::figureMessage( 
$row->rc_title );
 
+               $groups = array();
+               $codes = array();
+
                if ( $this->groups ) {
                        /* Get list of keys that the message belongs to, and 
filter
                         * out those which are not requested */
                        $groups = TranslateUtils::messageKeyToGroups( 
$row->rc_namespace, $key );
-                       $keys = array_intersect( $this->groups, $groups );
-               } else {
-                       $keys[] = '';
+                       $groups = array_intersect( $this->groups, $groups );
                }
+
                if ( $this->codes ) {
-                       foreach ( $keys as &$value ) {
-                               if ( $value === '' ) {
-                                       $value = $code;
-                               } else {
-                                       $value .= " ($code)";
-                               }
-                       }
+                       $codes = array( $code );
                }
-               return $keys;
+               return $this->combineTwoArrays( $groups, $codes );
        }
 
        public function labels() {
-               $labels = array();
-               if ( $this->groups && $this->codes ) {
-                       foreach ( $this->codes as $code ) {
-                               foreach ( $this->groups as $group ) {
-                                       $labels[] = "$group ($code)";
-                               }
-                       }
-               } elseif ( $this->groups ) {
-                               $labels = $this->groups;
-               } elseif ( $this->codes ) {
-                       $labels = $this->codes;
+               return $this->combineTwoArrays( $this->groups, $this->codes );
+       }
+
+       protected function makeLabel( $group, $code ) {
+               if ( $code ) {
+                       global $wgLang;
+                       $code = TranslateUtils::getLanguageName( $code, false, 
$wgLang->getCode() ) . " ($code)";
+               }
+
+               if ( $group && $code ) {
+                       return "$group @ $code";
+               } elseif ( $group || $code ) {
+                       return "$group$code";
                } else {
-                       $labels = array();
+                       return "Test";
                }
-               return $labels;
        }
 
+       protected function combineTwoArrays( $groups, $codes ) {
+               if ( !count( $groups ) ) $groups[] = false;
+               if ( !count( $codes ) ) $codes[] = false;
+
+               $items = array();
+               foreach ( $groups as $group ) {
+               foreach ( $codes as $code ) {
+                       $items[] = $this->makeLabel( $group, $code );
+               }
+               }
+               return $items;
+       }
+
 }



_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to