r72101 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72100‎ | r72101 | r72102 >
Date:12:30, 1 September 2010
Author:siebrand
Status:deferred
Tags:
Comment:
* update some documentation
* move class and function from a random place in the code to the bottom.
Modified paths:
  • /trunk/extensions/Translate/scripts/groupStatistics.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/scripts/groupStatistics.php
@@ -1,21 +1,29 @@
22 <?php
33 /**
4 - * Statistics about message groups.
 4+ * Commandline script to general statistics about the localisation level of
 5+ * localisation for one or more message groups.
56 *
 7+ * @file
 8+ * @ingroup Script Stats
69 * @author Niklas Laxstrom
710 * @author Siebrand Mazeland
811 * @copyright Copyright © 2007-2010, Niklas Laxström, Siebrand Mazeland
912 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
10 - * @file
11 - * @ingroup Script Stats
1213 */
1314
1415 /**
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+ *
1626 */
1727 $mostSpokenLanguages = array(
18 - // 'language code' => array( position, speakers in millions, continent ),
19 - // Source: http://stats.wikimedia.org/EN/Sitemap.htm
2028 'en' => array( 1, 1500, 'multiple' ),
2129 'zh-hans' => array( 2, 1300, 'asia' ),
2230 'zh-hant' => array( 2, 1300, 'asia' ),
@@ -73,16 +81,21 @@
7482 );
7583
7684 /**
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.
7891 */
7992 $localisedWeights = array(
8093 'wikimedia' => array(
81 - 'core-0-mostused' => 40,
 94+ 'core-0-mostused' => 40,
8295 'core' => 30,
8396 'ext-0-wikimedia' => 30
8497 ),
8598 'mediawiki' => array(
86 - 'core-0-mostused' => 30,
 99+ 'core-0-mostused' => 30,
87100 'core' => 30,
88101 'ext-0-wikimedia' => 20,
89102 'ext-0-all' => 20
@@ -91,7 +104,7 @@
92105
93106 /**
94107 * 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
96109 * of the localisation code is the WMF project name otherwise (zh-hans -> zh).
97110 */
98111 $wikimediaCodeMap = array(
@@ -163,26 +176,10 @@
164177 $optionsWithArgs = array( 'groups', 'output', 'skiplanguages', 'legenddetail', 'legendsummary' );
165178 require( dirname( __FILE__ ) . '/cli.inc' );
166179
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();
183182 }
184183
185 -if ( isset( $options['help'] ) ) showUsage();
186 -
187184 // Show help and exit if '--most' does not have a valid value and no groups set
188185 if ( isset( $options['most'] ) && !isset( $localisedWeights[$options['most']] ) && !isset( $options['groups'] ) ) {
189186 showUsage();
@@ -192,54 +189,6 @@
193190 $options['output'] = 'default';
194191 }
195192
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 -
244193 # Select an output engine
245194 switch ( $options['output'] ) {
246195 case 'wiki':
@@ -480,11 +429,15 @@
481430
482431 $allZero = true;
483432 foreach ( $columns as $fields ) {
484 - if ( intval( $fields[1] ) !== 0 ) $allZero = false;
 433+ if ( intval( $fields[1] ) !== 0 ) {
 434+ $allZero = false;
 435+ }
485436 }
486437
487438 // Skip dummy languages if requested
488 - if ( $allZero && isset( $options['skipzero'] ) ) continue;
 439+ if ( $allZero && isset( $options['skipzero'] ) ) {
 440+ continue;
 441+ }
489442
490443 // Output the the row
491444 if ( !$wmfscore ) {
@@ -646,3 +599,69 @@
647600 echo $code . ';' . number_format( $stats['score'] ) . ";\n";
648601 }
649602 }
 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+}

Follow-up revisions

RevisionCommit summaryAuthorDate
r72176Fix broken r72101. Class needs to be at the top of the file.siebrand23:14, 1 September 2010

Status & tagging log