r54643 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54642‎ | r54643 | r54644 >
Date:22:33, 8 August 2009
Author:demon
Status:ok
Tags:
Comment:
Move a few more of these to subclass Maintenance.
Modified paths:
  • /trunk/phase3/maintenance/language/countMessages.php (modified) (history)
  • /trunk/phase3/maintenance/language/date-formats.php (modified) (history)
  • /trunk/phase3/maintenance/language/dumpMessages.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/dumpMessages.php
@@ -1,18 +1,44 @@
22 <?php
33 /**
4 - * @todo document
5 - * @file
 4+ * Dump an entire language, using the keys from English
 5+ * so we get all the values, not just the customized ones
 6+ *
 7+ * This program is free software; you can redistribute it and/or modify
 8+ * it under the terms of the GNU General Public License as published by
 9+ * the Free Software Foundation; either version 2 of the License, or
 10+ * (at your option) any later version.
 11+ *
 12+ * This program is distributed in the hope that it will be useful,
 13+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 15+ * GNU General Public License for more details.
 16+ *
 17+ * You should have received a copy of the GNU General Public License along
 18+ * with this program; if not, write to the Free Software Foundation, Inc.,
 19+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 20+ * http://www.gnu.org/copyleft/gpl.html
 21+ *
622 * @ingroup MaintenanceLanguage
 23+ * @todo Make this more useful, right now just dumps $wgContentLang
724 */
825
9 -/** */
10 -require_once( dirname(__FILE__).'/../commandLine.inc' );
11 -$messages = array();
12 -$wgEnglishMessages = array_keys( Language::getMessagesFor( 'en' ) );
13 -foreach ( $wgEnglishMessages as $key ) {
14 - $messages[$key] = wfMsg( $key );
 26+require_once( dirname(__FILE__) . '/../Maintenance.php' );
 27+
 28+class DumpMessages extends Maintenance {
 29+ public function __construct() {
 30+ parent::__construct();
 31+ $this->mDescription = "Dump an entire language, using the keys from English";
 32+ }
 33+
 34+ public function execute() {
 35+ $messages = array();
 36+ foreach ( array_keys( Language::getMessagesFor( 'en' ) ) as $key ) {
 37+ $messages[$key] = wfMsg( $key );
 38+ }
 39+ $this->output( "MediaWiki $wgVersion language file\n" );
 40+ $this->output( serialize( $messages ) );
 41+ }
1542 }
16 -print "MediaWiki $wgVersion language file\n";
17 -print serialize( $messages );
1843
19 -
 44+$maintClass = "DumpMessages";
 45+require_once( DO_MAINTENANCE );
Index: trunk/phase3/maintenance/language/countMessages.php
@@ -1,40 +1,65 @@
22 <?php
 3+/**
 4+ * Count how many messages we have defined for each language.
 5+ *
 6+ * This program is free software; you can redistribute it and/or modify
 7+ * it under the terms of the GNU General Public License as published by
 8+ * the Free Software Foundation; either version 2 of the License, or
 9+ * (at your option) any later version.
 10+ *
 11+ * This program is distributed in the hope that it will be useful,
 12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 14+ * GNU General Public License for more details.
 15+ *
 16+ * You should have received a copy of the GNU General Public License along
 17+ * with this program; if not, write to the Free Software Foundation, Inc.,
 18+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 19+ * http://www.gnu.org/copyleft/gpl.html
 20+ *
 21+ * @ingroup MaintenanceLanguage
 22+ */
323
4 -require_once( dirname(__FILE__).'/../commandLine.inc' );
 24+require_once( dirname(__FILE__) . '/../Maintenance.php' );
525
6 -global $IP;
 26+class CountMessages extends Maintenance {
 27+ public function __construct() {
 28+ parent::__construct();
 29+ $this->mDescription = "Count how many messages we have defined for each language";
 30+ }
731
8 -if ( !isset( $args[0] ) ) {
9 - $dir = "$IP/languages/messages";
10 -} else {
11 - $dir = $args[0];
12 -}
13 -
14 -$total = 0;
15 -$nonZero = 0;
16 -foreach ( glob( "$dir/*.php" ) as $file ) {
17 - $baseName = basename( $file );
18 - if( !preg_match( '/Messages([A-Z][a-z_]+)\.php$/', $baseName, $m ) ) {
19 - continue;
 32+ public function execute() {
 33+ global $IP;
 34+ $dir = $this->getArg( 0, "$IP/languages/messages" );
 35+ $total = 0;
 36+ $nonZero = 0;
 37+ foreach ( glob( "$dir/*.php" ) as $file ) {
 38+ $baseName = basename( $file );
 39+ if( !preg_match( '/Messages([A-Z][a-z_]+)\.php$/', $baseName, $m ) ) {
 40+ continue;
 41+ }
 42+ $code = str_replace( '_', '-', strtolower( $m[1] ) );
 43+ $numMessages = $this->getNumMessages( $file );
 44+ //print "$code: $numMessages\n";
 45+ $total += $numMessages;
 46+ if ( $numMessages > 0 ) {
 47+ $nonZero ++;
 48+ }
 49+ }
 50+ $this->output( "\nTotal: $total\n" );
 51+ $this->output( "Languages: $nonZero\n" );
2052 }
21 - $code = str_replace( '_', '-', strtolower( $m[1] ) );
22 - $numMessages = wfGetNumMessages( $file );
23 - //print "$code: $numMessages\n";
24 - $total += $numMessages;
25 - if ( $numMessages > 0 ) {
26 - $nonZero ++;
27 - }
28 -}
29 -print "\nTotal: $total\n";
30 -print "Languages: $nonZero\n";
3153
32 -function wfGetNumMessages( $file ) {
33 - // Separate function to limit scope
34 - require( $file );
35 - if ( isset( $messages ) ) {
36 - return count( $messages );
37 - } else {
38 - return 0;
 54+ private function getNumMessages( $file ) {
 55+ // Separate function to limit scope
 56+ require( $file );
 57+ if ( isset( $messages ) ) {
 58+ return count( $messages );
 59+ } else {
 60+ return 0;
 61+ }
3962 }
4063 }
4164
 65+$maintClass = "CountMessages";
 66+require_once( DO_MAINTENANCE );
Index: trunk/phase3/maintenance/language/date-formats.php
@@ -1,50 +1,76 @@
22 <?php
33 /**
4 - * @file
 4+ * Test various language time and date functions
 5+ *
 6+ * This program is free software; you can redistribute it and/or modify
 7+ * it under the terms of the GNU General Public License as published by
 8+ * the Free Software Foundation; either version 2 of the License, or
 9+ * (at your option) any later version.
 10+ *
 11+ * This program is distributed in the hope that it will be useful,
 12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 14+ * GNU General Public License for more details.
 15+ *
 16+ * You should have received a copy of the GNU General Public License along
 17+ * with this program; if not, write to the Free Software Foundation, Inc.,
 18+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 19+ * http://www.gnu.org/copyleft/gpl.html
 20+ *
521 * @ingroup MaintenanceLanguage
622 */
723
8 -$ts = '20010115123456';
 24+require_once( dirname(__FILE__) . '/../Maintenance.php' );
925
10 -
11 -$IP = dirname( __FILE__ ) . '/../..';
12 -require_once( dirname(__FILE__).'/../commandLine.inc' );
 26+class DateFormats extends Maintenance {
1327
14 -foreach ( glob( "$IP/languages/messages/Messages*.php" ) as $filename ) {
15 - $base = basename( $filename );
16 - $m = array();
17 - if ( !preg_match( '/Messages(.*)\.php$/', $base, $m ) ) {
18 - continue;
 28+ private $ts = '20010115123456';
 29+
 30+ public function __construct() {
 31+ parent::__construct();
 32+ $this->mDescription = "Test various language time and date functions";
1933 }
20 - $code = str_replace( '_', '-', strtolower( $m[1] ) );
21 - print "$code ";
22 - $lang = Language::factory( $code );
23 - $prefs = $lang->getDatePreferences();
24 - if ( !$prefs ) {
25 - $prefs = array( 'default' );
26 - }
27 - print "date: ";
28 - foreach ( $prefs as $index => $pref ) {
29 - if ( $index > 0 ) {
30 - print ' | ';
 34+
 35+ public function execute() {
 36+ global $IP;
 37+ foreach ( glob( "$IP/languages/messages/Messages*.php" ) as $filename ) {
 38+ $base = basename( $filename );
 39+ $m = array();
 40+ if ( !preg_match( '/Messages(.*)\.php$/', $base, $m ) ) {
 41+ continue;
 42+ }
 43+ $code = str_replace( '_', '-', strtolower( $m[1] ) );
 44+ $this->output( "$code " );
 45+ $lang = Language::factory( $code );
 46+ $prefs = $lang->getDatePreferences();
 47+ if ( !$prefs ) {
 48+ $prefs = array( 'default' );
 49+ }
 50+ $this->output( "date: " );
 51+ foreach ( $prefs as $index => $pref ) {
 52+ if ( $index > 0 ) {
 53+ $this->output( ' | ' );
 54+ }
 55+ $this->output( $lang->date( $this->ts, false, $pref ) );
 56+ }
 57+ $this->output( "\n$code time: " );
 58+ foreach ( $prefs as $index => $pref ) {
 59+ if ( $index > 0 ) {
 60+ $this->output( ' | ' );
 61+ }
 62+ $this->output( $lang->time( $this->ts, false, $pref ) );
 63+ }
 64+ $this->output( "\n$code both: " );
 65+ foreach ( $prefs as $index => $pref ) {
 66+ if ( $index > 0 ) {
 67+ $this->output( ' | ' );
 68+ }
 69+ $this->output( $lang->timeanddate( $this->ts, false, $pref ) );
 70+ }
 71+ $this->output( "\n\n" );
3172 }
32 - print $lang->date( $ts, false, $pref );
3373 }
34 - print "\n$code time: ";
35 - foreach ( $prefs as $index => $pref ) {
36 - if ( $index > 0 ) {
37 - print ' | ';
38 - }
39 - print $lang->time( $ts, false, $pref );
40 - }
41 - print "\n$code both: ";
42 - foreach ( $prefs as $index => $pref ) {
43 - if ( $index > 0 ) {
44 - print ' | ';
45 - }
46 - print $lang->timeanddate( $ts, false, $pref );
47 - }
48 - print "\n\n";
4974 }
5075
51 -
 76+$maintClass = "DateFormats";
 77+require_once( DO_MAINTENANCE );

Status & tagging log