r72440 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72439‎ | r72440 | r72441 >
Date:14:53, 5 September 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
Add optional aggregate group for all translatable pages
Modified paths:
  • /trunk/extensions/Translate/Groups.php (modified) (history)
  • /trunk/extensions/Translate/groups/PageTranslationAgg.yaml (added) (history)

Diff [purge]

Index: trunk/extensions/Translate/groups/PageTranslationAgg.yaml
@@ -0,0 +1,15 @@
 2+# Enable this group if you want to have aggregate group for all page
 3+# page translation groups. You can also add this configuration:
 4+# $wgTranslateGroupStructure['/^page/'] = array( 'page' );
 5+
 6+BASIC:
 7+ id: page-0-all
 8+ label: All translatable pages
 9+ display: page
 10+ meta: yes
 11+ class: AggregateMessageGroup
 12+ description: 'All translatable pages'
 13+ namespace: NS_TRANSLATIONS
 14+
 15+GROUPS:
 16+ - page|*
Index: trunk/extensions/Translate/Groups.php
@@ -455,9 +455,7 @@
456456 class AggregateMessageGroup extends MessageGroupBase {
457457
458458 public function exists() {
459 - /**
460 - * Group exists if there are any subgroups.
461 - */
 459+ // Group exists if there are any subgroups.
462460 $exists = (bool) $this->conf['GROUPS'];
463461
464462 if ( !$exists ) {
@@ -488,6 +486,7 @@
489487 if ( !isset( $this->groups ) ) {
490488 $groups = array();
491489 $ids = (array) $this->conf['GROUPS'];
 490+ $ids = $this->expandWildcards( $ids );
492491
493492 foreach ( $ids as $id ) {
494493 // Do not try to include self and go to infinite loop.
@@ -507,6 +506,34 @@
508507 return $this->groups;
509508 }
510509
 510+ /**
 511+ * If the list of group ids contains wildcards, this function will match
 512+ * them against the list of all supported groups and return matched group
 513+ * names.
 514+ * @param $ids \list{String}
 515+ * @return \list{String}
 516+ */
 517+ protected function expandWildcards( $ids ) {
 518+ $hasWild = false;
 519+ foreach ( $ids as $id ) {
 520+ if ( strpos( $id, '*' ) !== false ) {
 521+ $hasWild = true;
 522+ break;
 523+ }
 524+ }
 525+
 526+ if ( !$hasWild ) return $ids;
 527+
 528+ $matcher = new StringMatcher( '', $ids );
 529+ $all = array();
 530+ foreach ( MessageGroups::singleton()->getGroups() as $id => $_ ) {
 531+ if ( $matcher->match( $id ) ) {
 532+ $all[] = $id;
 533+ }
 534+ }
 535+ return $all;
 536+ }
 537+
511538 public function initCollection( $code ) {
512539 $messages = array();
513540 foreach ( $this->getGroups() as $group ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r72446Follow-up r72440. Update group label and add i18n for group description.siebrand15:22, 5 September 2010

Status & tagging log