r110381 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110380‎ | r110381 | r110382 >
Date:10:49, 31 January 2012
Author:siebrand
Status:resolved (Comments)
Tags:i18nreview 
Comment:
* add "groupprefix" in sync-group.php.
* add FIXME for code duplication.
Modified paths:
  • /trunk/extensions/Translate/README (modified) (history)
  • /trunk/extensions/Translate/scripts/export.php (modified) (history)
  • /trunk/extensions/Translate/scripts/sync-group.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/scripts/sync-group.php
@@ -10,7 +10,7 @@
1111
1212 /// @cond
1313
14 -$optionsWithArgs = array( 'group', 'lang', 'start', 'end' );
 14+$optionsWithArgs = array( 'group', 'groupprefix', 'lang', 'start', 'end' );
1515 require( dirname( __FILE__ ) . '/cli.inc' );
1616
1717 # Override the memory limit for wfShellExec, 100 MB seems to be too little for svn
@@ -19,13 +19,15 @@
2020 function showUsage() {
2121 STDERR( <<<EOT
2222 Options:
23 - --group Comma separated list of group IDs or *
 23+ --group Comma separated list of group IDs
 24+ --groupprefix Prefix of group IDs to be exported message groups (cannot use
 25+ group)
2426 --lang Comma separated list of language codes or *
2527 --norc Do not add entries to recent changes table
2628 --help This help message
2729 --noask Skip all conflicts
28 - --start Start of the last export (changes in wiki after this will conflict)
29 - --end End of the last export (changes in source before this wont conflict)
 30+ --start Start of the last export (changes in wiki after will conflict)
 31+ --end End of the last export (changes in source after will conflict)
3032 --nocolor Without colours
3133 EOT
3234 );
@@ -36,24 +38,43 @@
3739 showUsage();
3840 }
3941
40 -if ( !isset( $options['group'] ) ) {
41 - STDERR( "ESG1: Message group id must be supplied with group parameter." );
 42+if ( !isset( $options['group'] ) && !isset( $options['groupprefix'] ) ) {
 43+ STDERR( "ESG1: Message group id must be supplied with group or groupprefix parameter." );
4244 exit( 1 );
4345 }
4446
45 -$group = MessageGroups::getGroup( $options['group'] );
46 -if ( $group === null ) {
47 - if ( $options['group'] === '*' ) {
48 - $mg = MessageGroups::singleton();
49 - $groups = $mg->getGroups();
50 - } else {
51 - STDERR( "ESG2: Invalid message group was given." );
52 - exit( 1 );
 47+$groups = array();
 48+
 49+// @todo FIXME: Code duplication with export.php
 50+if ( isset( $options['group'] ) ) {
 51+ // Explode parameter
 52+ $groupIds = explode( ',', trim( $options['group'] ) );
 53+
 54+ // Get groups and add groups to array
 55+ foreach ( $groupIds as $groupId ) {
 56+ $group = MessageGroups::getGroup( $groupId );
 57+
 58+ if( $group !== null ) {
 59+ $groups[$groupId] = $group;
 60+ }
5361 }
5462 } else {
55 - $groups = array( $group );
 63+ // Apparently using option groupprefix. Find groups that match.
 64+ $allGroups = MessageGroups::singleton()->getGroups();
 65+
 66+ // Add matching groups to groups array.
 67+ foreach ( $allGroups as $groupId => $messageGroup ) {
 68+ if ( strpos( $groupId, $options['groupprefix'] ) === 0 && !$messageGroup->isMeta() ) {
 69+ $groups[$groupId] = $messageGroup;
 70+ }
 71+ }
5672 }
5773
 74+if( !count( $groups ) {
 75+ STDERR( "ESG2: No valid message groups identified." );
 76+ exit( 1 );
 77+}
 78+
5879 if ( !isset( $options['lang'] ) || strval( $options['lang'] ) === '' ) {
5980 STDERR( "ESG3: List of language codes must be supplied with lang parameter." );
6081 exit( 1 );
Index: trunk/extensions/Translate/scripts/export.php
@@ -90,6 +90,7 @@
9191
9292 $groups = array();
9393
 94+// @todo FIXME: Code duplication with sync-group.php
9495 if ( isset( $options['group'] ) ) {
9596 // Explode parameter
9697 $groupIds = explode( ',', trim( $options['group'] ) );
Index: trunk/extensions/Translate/README
@@ -30,10 +30,9 @@
3131
3232 == Change log ==
3333 * 2012-01-31
34 -- export.php changes:
35 - - switch "grouptrail" renamed to "groupprefix"
36 - - switch "groups" dropped. "group" now takes a comma separated list of group
37 - IDs, too.
 34+- export.php: switch "grouptrail" renamed to "groupprefix" and switch "groups"
 35+ was dropped. "group" now takes a comma separated list of groups IDs, too.
 36+- sync-group.php: switch "groupprefix" added.
3837 * 2012-01-13
3938 - export.php has a switch "--no-fuzzy" that will filter out fuzzy messages
4039 for file based message groups.

Sign-offs

UserFlagDate
Reedyinspected16:58, 3 February 2012
Siebrandtested10:07, 6 February 2012

Follow-up revisions

RevisionCommit summaryAuthorDate
r110382Fix syntax error r110381.siebrand10:51, 31 January 2012

Comments

#Comment by Nikerabbit (talk | contribs)   11:07, 13 February 2012

With my recent changes this is unnecessary, you can now use wildcards in group param.

Status & tagging log