r111358 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111357‎ | r111358 | r111359 >
Date:10:37, 13 February 2012
Author:nikerabbit
Status:ok
Tags:
Comment:
Address some of the issues in r111272
Modified paths:
  • /trunk/extensions/Translate/MessageGroups.php (modified) (history)
  • /trunk/extensions/Translate/scripts/export.php (modified) (history)
  • /trunk/extensions/Translate/scripts/sync-group.php (modified) (history)
  • /trunk/extensions/Translate/scripts/tm-export.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/scripts/tm-export.php
@@ -3,7 +3,6 @@
44 * Script to bootstrap translatetoolkit translation memory
55 *
66 * @author Niklas Laxstrom
7 - *
87 * @copyright Copyright © 2010-2011, Niklas Laxström
98 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
109 * @file
Index: trunk/extensions/Translate/scripts/sync-group.php
@@ -46,10 +46,16 @@
4747 }
4848
4949 // In case both group and groupprefix would be set, MessageGroups::getGroups
50 -// will give preference to groupIds.
51 -$groupIds = isset( $options['group'] ) ? explode( ',', trim( $options['group'] ) ) : null;
52 -$groupPrefix = isset( $options['groupprefix'] ) ? $options['groupprefix'] : null;
53 -$groups = MessageGroups::singleton()->getGroups( $groupIds, $groupPrefix );
 50+// will give preference to group. @TODO: get rid of groupprefix
 51+$groupIds = array();
 52+if ( isset( $options['groupprefix'] ) ) {
 53+ $groupIds[] = $options['groupprefix'] . '*';
 54+}
 55+if ( isset( $options['group'] ) ) {
 56+ $groupIds = explode( ',', trim( $options['group'] ) );
 57+}
 58+$groupIds = MessageGroups::expandWildcards( $groupIds );
 59+$groups = MessageGroups::getGroupsById( $groupIds );
5460
5561 if ( !count( $groups ) ) {
5662 STDERR( "ESG2: No valid message groups identified." );
Index: trunk/extensions/Translate/scripts/export.php
@@ -89,13 +89,19 @@
9090 $reqLangs = Cli::parseLanguageCodes( $options['lang'] );
9191
9292 // In case both group and groupprefix would be set, MessageGroups::getGroups
93 -// will give preference to groupIds.
94 -$groupIds = isset( $options['group'] ) ? explode( ',', trim( $options['group'] ) ) : null;
95 -$groupPrefix = isset( $options['groupprefix'] ) ? $options['groupprefix'] : null;
96 -$groups = MessageGroups::singleton()->getGroups( $groupIds, $groupPrefix );
 93+// will give preference to group. @TODO: get rid of groupprefix
 94+$groupIds = array();
 95+if ( isset( $options['groupprefix'] ) ) {
 96+ $groupIds[] = $options['groupprefix'] . '*';
 97+}
 98+if ( isset( $options['group'] ) ) {
 99+ $groupIds = explode( ',', trim( $options['group'] ) );
 100+}
 101+$groupIds = MessageGroups::expandWildcards( $groupIds );
 102+$groups = MessageGroups::getGroupsById( $groupIds );
97103
98104 if ( !count( $groups ) ) {
99 - STDERR( "No valid message groups identified." );
 105+ STDERR( "EE1: No valid message groups identified." );
100106 exit( 1 );
101107 }
102108
Index: trunk/extensions/Translate/MessageGroups.php
@@ -1299,7 +1299,7 @@
13001300 * Get all enabled message groups.
13011301 * @return \array
13021302 */
1303 - public function getAllMessageGroups() {
 1303+ public function getGroups() {
13041304 if ( $this->classes === null ) {
13051305 $this->classes = array();
13061306 global $wgTranslateEC, $wgTranslateCC;
@@ -1317,40 +1317,47 @@
13181318 }
13191319
13201320 /**
1321 - * Get message groups.
 1321+ * Get message groups for corresponding message group ids.
13221322 *
1323 - * @para $groups \array Group IDs
1324 - * @para $groupPrefix \string Prefix for groups
1325 - * @return \array
 1323+ * @param $groups array Group IDs
 1324+ * @param $groupPrefix string Prefix for groups
 1325+ * @return array
 1326+ * @since 2012-02-13
13261327 */
1327 - public function getGroups( $groups = null, $groupPrefix = null ) {
1328 - if ( count( $groups ) ) {
1329 - // Get groups and add groups to array
1330 - foreach ( $groups as $groupId ) {
1331 - $group = self::getGroup( $groupId );
 1328+ public static function getGroupsById( array $ids ) {
 1329+ $groups = array();
 1330+ foreach ( $ids as $id ) {
 1331+ $group = self::getGroup( $id );
13321332
1333 - if ( $group !== null ) {
1334 - $groups[$groupId] = $group;
1335 - } else {
1336 - wfDebug( __METHOD__ . ": Invalid group $groupId\n" );
1337 - }
 1333+ if ( $group !== null ) {
 1334+ $groups[$id] = $group;
 1335+ } else {
 1336+ wfDebug( __METHOD__ . ": Invalid message group id: $id\n" );
13381337 }
 1338+ }
13391339
1340 - return $groups;
1341 - } elseif ( $groupPrefix !== null ) {
1342 - $allGroups = self::singleton()->getGroups();
 1340+ return $groups;
 1341+ }
13431342
1344 - // Add matching groups to groups array.
1345 - foreach ( $allGroups as $groupId => $messageGroup ) {
1346 - if ( strpos( $groupId, $groupPrefix ) === 0 && !$messageGroup->isMeta() ) {
1347 - $groups[$groupId] = $messageGroup;
1348 - }
 1343+ /**
 1344+ * If the list of message group ids contains wildcards, this function will match
 1345+ * them against the list of all supported message groups and return matched
 1346+ * message group ids.
 1347+ * @param $ids \list{String}|String
 1348+ * @return \list{String}
 1349+ * @since 2012-02-13
 1350+ */
 1351+ public static function expandWildcards( $ids ) {
 1352+ $all = array();
 1353+
 1354+ $matcher = new StringMatcher( '', (array) $ids );
 1355+ foreach ( self::singleton()->getGroups() as $id => $_ ) {
 1356+ if ( $matcher->match( $id ) ) {
 1357+ $all[] = $id;
13491358 }
 1359+ }
13501360
1351 - return $groups;
1352 - } else {
1353 - return self::getAllMessageGroups();
1354 - }
 1361+ return $all;
13551362 }
13561363
13571364 /**

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r111272* Move hard coded styles in MessageWebImporter to CSS....siebrand04:45, 12 February 2012

Status & tagging log