Index: trunk/extensions/Translate/scripts/groupStatistics.php |
— | — | @@ -1,21 +1,29 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | | - * Statistics about message groups. |
| 4 | + * Commandline script to general statistics about the localisation level of |
| 5 | + * localisation for one or more message groups. |
5 | 6 | * |
| 7 | + * @file |
| 8 | + * @ingroup Script Stats |
6 | 9 | * @author Niklas Laxstrom |
7 | 10 | * @author Siebrand Mazeland |
8 | 11 | * @copyright Copyright © 2007-2010, Niklas Laxström, Siebrand Mazeland |
9 | 12 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
10 | | - * @file |
11 | | - * @ingroup Script Stats |
12 | 13 | */ |
13 | 14 | |
14 | 15 | /** |
15 | | - * @todo Needs documentation. |
| 16 | + * Array of the most spoken languages in the world. |
| 17 | + * Source: http://stats.wikimedia.org/EN/Sitemap.htm. |
| 18 | + * |
| 19 | + * Key value pairs of: |
| 20 | + * [MediaWiki localisation code] => array( |
| 21 | + * [position in top 50], |
| 22 | + * [speakers in millions], |
| 23 | + * [continent where localisation is spoken] |
| 24 | + * ) |
| 25 | + * |
16 | 26 | */ |
17 | 27 | $mostSpokenLanguages = array( |
18 | | - // 'language code' => array( position, speakers in millions, continent ), |
19 | | - // Source: http://stats.wikimedia.org/EN/Sitemap.htm |
20 | 28 | 'en' => array( 1, 1500, 'multiple' ), |
21 | 29 | 'zh-hans' => array( 2, 1300, 'asia' ), |
22 | 30 | 'zh-hant' => array( 2, 1300, 'asia' ), |
— | — | @@ -73,16 +81,21 @@ |
74 | 82 | ); |
75 | 83 | |
76 | 84 | /** |
77 | | - * @todo Needs documentation. |
| 85 | + * Variable with key-value pairs with a named index and an array of key-value |
| 86 | + * pairs where the key is a MessageGroup ID and the value is a weight of the |
| 87 | + * group in the sum of the values for all the groups in the array. |
| 88 | + * |
| 89 | + * Definitions in this variable can be used to report weighted meta localisation |
| 90 | + * scores. |
78 | 91 | */ |
79 | 92 | $localisedWeights = array( |
80 | 93 | 'wikimedia' => array( |
81 | | - 'core-0-mostused' => 40, |
| 94 | + 'core-0-mostused' => 40, |
82 | 95 | 'core' => 30, |
83 | 96 | 'ext-0-wikimedia' => 30 |
84 | 97 | ), |
85 | 98 | 'mediawiki' => array( |
86 | | - 'core-0-mostused' => 30, |
| 99 | + 'core-0-mostused' => 30, |
87 | 100 | 'core' => 30, |
88 | 101 | 'ext-0-wikimedia' => 20, |
89 | 102 | 'ext-0-all' => 20 |
— | — | @@ -91,7 +104,7 @@ |
92 | 105 | |
93 | 106 | /** |
94 | 107 | * Code map to map localisation codes to Wikimedia project codes. Only |
95 | | - * exclusions and remapping is defined here. It is assumed that the first part |
| 108 | + * exclusion and remapping is defined here. It is assumed that the first part |
96 | 109 | * of the localisation code is the WMF project name otherwise (zh-hans -> zh). |
97 | 110 | */ |
98 | 111 | $wikimediaCodeMap = array( |
— | — | @@ -163,26 +176,10 @@ |
164 | 177 | $optionsWithArgs = array( 'groups', 'output', 'skiplanguages', 'legenddetail', 'legendsummary' ); |
165 | 178 | require( dirname( __FILE__ ) . '/cli.inc' ); |
166 | 179 | |
167 | | -/** |
168 | | - * @todo Needs documentation. |
169 | | - * @ingroup Stats |
170 | | - */ |
171 | | -class TranslateStatsOutput extends wikiStatsOutput { |
172 | | - function heading() { |
173 | | - echo '{| class="sortable wikitable" border="2" cellpadding="4" cellspacing="0" style="background-color: #F9F9F9; border: 1px #AAAAAA solid; border-collapse: collapse; clear:both;" width="100%"' . "\n"; |
174 | | - } |
175 | | - |
176 | | - function summaryheading() { |
177 | | - echo "\n" . '{| class="sortable wikitable" border="2" cellpadding="4" cellspacing="0" style="background-color: #F9F9F9; border: 1px #AAAAAA solid; border-collapse: collapse; clear:both;"' . "\n"; |
178 | | - } |
179 | | - |
180 | | - function addFreeText( $freeText ) { |
181 | | - echo $freeText; |
182 | | - } |
| 180 | +if ( isset( $options['help'] ) ) { |
| 181 | + showUsage(); |
183 | 182 | } |
184 | 183 | |
185 | | -if ( isset( $options['help'] ) ) showUsage(); |
186 | | - |
187 | 184 | // Show help and exit if '--most' does not have a valid value and no groups set |
188 | 185 | if ( isset( $options['most'] ) && !isset( $localisedWeights[$options['most']] ) && !isset( $options['groups'] ) ) { |
189 | 186 | showUsage(); |
— | — | @@ -192,54 +189,6 @@ |
193 | 190 | $options['output'] = 'default'; |
194 | 191 | } |
195 | 192 | |
196 | | -/** |
197 | | - * Print a usage message. |
198 | | - */ |
199 | | -function showUsage() { |
200 | | - $msg = <<<END |
201 | | - --help : this help message |
202 | | - --groups LIST: comma separated list of groups |
203 | | - --skiplanguages LIST: comma separated list of skipped languages |
204 | | - --skipzero : skip languages that do not have any localisation at all |
205 | | - --fuzzy : add column for fuzzy counts |
206 | | - --output TYPE: select an another output engine |
207 | | - * 'csv' : Comma Separated Values. |
208 | | - * 'wiki' : MediaWiki syntax. |
209 | | - * 'text' : Text with tabs. |
210 | | - --most : [SCOPE]: report on the 50 most spoken languages. Skipzero is |
211 | | - ignored. If a valid scope is defined, the group list |
212 | | - and fuzzy are ignored and the localisation levels are |
213 | | - weighted and reported. |
214 | | - * mediawiki: |
215 | | - core-0-mostused (30%) |
216 | | - core (30%) |
217 | | - ext-0-wikimedia (20%) |
218 | | - ext-0-all (20%) |
219 | | - * wikimedia: |
220 | | - core-0-mostused (40%) |
221 | | - core (30%) |
222 | | - ext-0-wikimedia (30%) |
223 | | - --speakers : add column for number of speakers (est.). Only valid when |
224 | | - combined with --most. |
225 | | - --nol10n : do not add localised language name if I18ntags is installed. |
226 | | - --continent : add a continent column. Only available when output is |
227 | | - 'wiki' or not specified. |
228 | | - --summary : add a summary with counts and scores per continent category |
229 | | - and totals. Only available for a valid 'most' value. |
230 | | - --legenddetail : Page name for legend to be transcluded at the top of |
231 | | - the details table |
232 | | - --legendsummary : Page name for legend to be transcluded at the top of |
233 | | - the summary table |
234 | | - --wmfscore : Only output WMF language code and weighted score for all |
235 | | - language codes for weighing group 'wikimedia' in CSV. This |
236 | | - report must keep a stable layout as it is used/will be |
237 | | - used in the Wikimedia statistics. |
238 | | - |
239 | | -END; |
240 | | - STDERR( $msg ); |
241 | | - exit( 1 ); |
242 | | -} |
243 | | - |
244 | 193 | # Select an output engine |
245 | 194 | switch ( $options['output'] ) { |
246 | 195 | case 'wiki': |
— | — | @@ -480,11 +429,15 @@ |
481 | 430 | |
482 | 431 | $allZero = true; |
483 | 432 | foreach ( $columns as $fields ) { |
484 | | - if ( intval( $fields[1] ) !== 0 ) $allZero = false; |
| 433 | + if ( intval( $fields[1] ) !== 0 ) { |
| 434 | + $allZero = false; |
| 435 | + } |
485 | 436 | } |
486 | 437 | |
487 | 438 | // Skip dummy languages if requested |
488 | | - if ( $allZero && isset( $options['skipzero'] ) ) continue; |
| 439 | + if ( $allZero && isset( $options['skipzero'] ) ) { |
| 440 | + continue; |
| 441 | + } |
489 | 442 | |
490 | 443 | // Output the the row |
491 | 444 | if ( !$wmfscore ) { |
— | — | @@ -646,3 +599,69 @@ |
647 | 600 | echo $code . ';' . number_format( $stats['score'] ) . ";\n"; |
648 | 601 | } |
649 | 602 | } |
| 603 | + |
| 604 | +/** |
| 605 | + * Print a usage message. |
| 606 | + */ |
| 607 | +function showUsage() { |
| 608 | + $msg = <<<PHP |
| 609 | + --help : this help message |
| 610 | + --groups LIST: comma separated list of groups |
| 611 | + --skiplanguages LIST: comma separated list of skipped languages |
| 612 | + --skipzero : skip languages that do not have any localisation at all |
| 613 | + --fuzzy : add column for fuzzy counts |
| 614 | + --output TYPE: select an another output engine |
| 615 | + * 'csv' : Comma Separated Values. |
| 616 | + * 'wiki' : MediaWiki syntax. |
| 617 | + * 'text' : Text with tabs. |
| 618 | + --most : [SCOPE]: report on the 50 most spoken languages. Skipzero is |
| 619 | + ignored. If a valid scope is defined, the group list |
| 620 | + and fuzzy are ignored and the localisation levels are |
| 621 | + weighted and reported. |
| 622 | + * mediawiki: |
| 623 | + core-0-mostused (30%) |
| 624 | + core (30%) |
| 625 | + ext-0-wikimedia (20%) |
| 626 | + ext-0-all (20%) |
| 627 | + * wikimedia: |
| 628 | + core-0-mostused (40%) |
| 629 | + core (30%) |
| 630 | + ext-0-wikimedia (30%) |
| 631 | + --speakers : add column for number of speakers (est.). Only valid when |
| 632 | + combined with --most. |
| 633 | + --nol10n : do not add localised language name if I18ntags is installed. |
| 634 | + --continent : add a continent column. Only available when output is |
| 635 | + 'wiki' or not specified. |
| 636 | + --summary : add a summary with counts and scores per continent category |
| 637 | + and totals. Only available for a valid 'most' value. |
| 638 | + --legenddetail : Page name for legend to be transcluded at the top of |
| 639 | + the details table |
| 640 | + --legendsummary : Page name for legend to be transcluded at the top of |
| 641 | + the summary table |
| 642 | + --wmfscore : Only output WMF language code and weighted score for all |
| 643 | + language codes for weighing group 'wikimedia' in CSV. This |
| 644 | + report must keep a stable layout as it is used/will be |
| 645 | + used in the Wikimedia statistics. |
| 646 | + |
| 647 | +PHP; |
| 648 | + STDERR( $msg ); |
| 649 | + exit( 1 ); |
| 650 | +} |
| 651 | + |
| 652 | +/** |
| 653 | + * @todo Needs documentation. |
| 654 | + * @ingroup Stats |
| 655 | + */ |
| 656 | +class TranslateStatsOutput extends wikiStatsOutput { |
| 657 | + function heading() { |
| 658 | + echo '{| class="sortable wikitable" border="2" cellpadding="4" cellspacing="0" style="background-color: #F9F9F9; border: 1px #AAAAAA solid; border-collapse: collapse; clear:both;" width="100%"' . "\n"; |
| 659 | + } |
| 660 | + |
| 661 | + function summaryheading() { |
| 662 | + echo "\n" . '{| class="sortable wikitable" border="2" cellpadding="4" cellspacing="0" style="background-color: #F9F9F9; border: 1px #AAAAAA solid; border-collapse: collapse; clear:both;"' . "\n"; |
| 663 | + } |
| 664 | + |
| 665 | + function addFreeText( $freeText ) { |
| 666 | + echo $freeText; |
| 667 | + } |
| 668 | +} |