https://www.mediawiki.org/wiki/Special:Code/MediaWiki/110381

Revision: 110381
Author:   siebrand
Date:     2012-01-31 10:49:44 +0000 (Tue, 31 Jan 2012)
Log Message:
-----------
* add "groupprefix" in sync-group.php.
* add FIXME for code duplication.

Modified Paths:
--------------
    trunk/extensions/Translate/README
    trunk/extensions/Translate/scripts/export.php
    trunk/extensions/Translate/scripts/sync-group.php

Modified: trunk/extensions/Translate/README
===================================================================
--- trunk/extensions/Translate/README   2012-01-31 10:43:30 UTC (rev 110380)
+++ trunk/extensions/Translate/README   2012-01-31 10:49:44 UTC (rev 110381)
@@ -30,10 +30,9 @@
 
 == Change log ==
 * 2012-01-31
-- export.php changes:
-  - switch "grouptrail" renamed to "groupprefix"
-  - switch "groups" dropped. "group" now takes a comma separated list of group
-    IDs, too.
+- export.php: switch "grouptrail" renamed to "groupprefix" and switch "groups"
+  was dropped. "group" now takes a comma separated list of groups IDs, too.
+- sync-group.php: switch "groupprefix" added.
 * 2012-01-13
 - export.php has a switch "--no-fuzzy" that will filter out fuzzy messages
   for file based message groups.

Modified: trunk/extensions/Translate/scripts/export.php
===================================================================
--- trunk/extensions/Translate/scripts/export.php       2012-01-31 10:43:30 UTC 
(rev 110380)
+++ trunk/extensions/Translate/scripts/export.php       2012-01-31 10:49:44 UTC 
(rev 110381)
@@ -90,6 +90,7 @@
 
 $groups = array();
 
+// @todo FIXME: Code duplication with sync-group.php
 if ( isset( $options['group'] ) ) {
        // Explode parameter
        $groupIds = explode( ',', trim( $options['group'] ) );

Modified: trunk/extensions/Translate/scripts/sync-group.php
===================================================================
--- trunk/extensions/Translate/scripts/sync-group.php   2012-01-31 10:43:30 UTC 
(rev 110380)
+++ trunk/extensions/Translate/scripts/sync-group.php   2012-01-31 10:49:44 UTC 
(rev 110381)
@@ -10,7 +10,7 @@
 
 /// @cond
 
-$optionsWithArgs = array( 'group', 'lang', 'start', 'end' );
+$optionsWithArgs = array( 'group', 'groupprefix', 'lang', 'start', 'end' );
 require( dirname( __FILE__ ) . '/cli.inc' );
 
 # Override the memory limit for wfShellExec, 100 MB seems to be too little for 
svn
@@ -19,13 +19,15 @@
 function showUsage() {
        STDERR( <<<EOT
 Options:
-  --group       Comma separated list of group IDs or *
+  --group       Comma separated list of group IDs
+  --groupprefix Prefix of group IDs to be exported message groups (cannot use
+                group)
   --lang        Comma separated list of language codes or *
   --norc        Do not add entries to recent changes table
   --help        This help message
   --noask       Skip all conflicts
-  --start       Start of the last export (changes in wiki after this will 
conflict)
-  --end         End of the last export (changes in source before this wont 
conflict)
+  --start       Start of the last export (changes in wiki after will conflict)
+  --end         End of the last export (changes in source after will conflict)
   --nocolor     Without colours
 EOT
 );
@@ -36,24 +38,43 @@
        showUsage();
 }
 
-if ( !isset( $options['group'] ) ) {
-       STDERR( "ESG1: Message group id must be supplied with group parameter." 
);
+if ( !isset( $options['group'] ) && !isset( $options['groupprefix'] ) ) {
+       STDERR( "ESG1: Message group id must be supplied with group or 
groupprefix parameter." );
        exit( 1 );
 }
 
-$group = MessageGroups::getGroup( $options['group'] );
-if ( $group === null ) {
-       if ( $options['group'] === '*' ) {
-               $mg = MessageGroups::singleton();
-               $groups = $mg->getGroups();
-       } else {
-               STDERR( "ESG2: Invalid message group was given." );
-               exit( 1 );
+$groups = array();
+
+// @todo FIXME: Code duplication with export.php
+if ( isset( $options['group'] ) ) {
+       // Explode parameter
+       $groupIds = explode( ',', trim( $options['group'] ) );
+
+       // Get groups and add groups to array
+       foreach ( $groupIds as $groupId ) {
+               $group = MessageGroups::getGroup( $groupId );
+
+               if( $group !== null ) {
+                       $groups[$groupId] = $group;
+               }
        }
 } else {
-       $groups = array( $group );
+       // Apparently using option groupprefix. Find groups that match.
+       $allGroups = MessageGroups::singleton()->getGroups();
+
+       // Add matching groups to groups array.
+       foreach ( $allGroups as $groupId => $messageGroup ) {
+               if ( strpos( $groupId, $options['groupprefix'] ) === 0 && 
!$messageGroup->isMeta() ) {
+                       $groups[$groupId] = $messageGroup;
+               }
+       }
 }
 
+if( !count( $groups ) {
+       STDERR( "ESG2: No valid message groups identified." );
+       exit( 1 );
+}
+
 if ( !isset( $options['lang'] ) || strval( $options['lang'] ) === '' ) {
        STDERR( "ESG3: List of language codes must be supplied with lang 
parameter." );
        exit( 1 );


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

Reply via email to