r69050 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69049‎ | r69050 | r69051 >
Date:10:53, 5 July 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
Fix handling of tags in aggregate message groups.

Previously tags of later message groups would override
the ones set by previous message groups. This should also
fix few bugs where getTags was used directly, since it
didn't process wildcards.
Modified paths:
  • /trunk/extensions/Translate/Groups.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/Groups.php
@@ -151,6 +151,47 @@
152152 }
153153
154154 public function getTags( $type = null ) {
 155+ if ( $type === null ) {
 156+ $taglist = array();
 157+ foreach ( $this->getRawTags() as $type => $patterns ) {
 158+ $taglist[$type] = $this->parseTags( $patterns );
 159+ }
 160+ return $taglist;
 161+ } else {
 162+ return $this->parse( $this->getRawTags( $type ) );
 163+ }
 164+ }
 165+
 166+ protected function parseTags( $patterns ) {
 167+ $cache = new MessageGroupCache( $this->getId() );
 168+ $messageKeys = $cache->getKeys();
 169+
 170+ $matches = array();
 171+
 172+ // Collect exact keys, no point running them trough string matcher
 173+ foreach ( $patterns as $index => $pattern ) {
 174+ if ( strpos( $pattern, '*' ) === false ) {
 175+ $matches[] = $pattern;
 176+ unset( $patterns[$index] );
 177+ }
 178+ }
 179+
 180+ if ( count( $patterns ) ) {
 181+ // Rest of the keys contain wildcards
 182+ $mangler = new StringMatcher( '', $patterns );
 183+
 184+ // Use mangler to find messages that match
 185+ foreach ( $messageKeys as $key ) {
 186+ if ( $mangler->match( $key ) ) {
 187+ $matches[] = $key;
 188+ }
 189+ }
 190+ }
 191+
 192+ return $matches;
 193+ }
 194+
 195+ protected function getRawTags( $type = null ) {
155196 if ( !isset( $this->conf['TAGS'] ) ) {
156197 return array();
157198 }
@@ -168,37 +209,8 @@
169210 }
170211
171212 protected function setTags( MessageCollection $collection ) {
172 - $tags = $this->getTags();
173 -
174 - $cache = new MessageGroupCache( $this->getId() );
175 - $messageKeys = $cache->getKeys();
176 -
177 - // Loop trough all tag types
178 - foreach ( $tags as $type => $patterns ) {
179 - $matches = array();
180 -
181 - // Collect exact keys, no point running them trough string matcher
182 - foreach ( $patterns as $index => $pattern ) {
183 - if ( strpos( $pattern, '*' ) === false ) {
184 - $matches[] = $pattern;
185 - unset( $patterns[$index] );
186 - }
187 - }
188 -
189 - if ( count( $patterns ) ) {
190 - // Rest of the keys contain wildcards
191 - $mangler = new StringMatcher( '', $patterns );
192 -
193 - // Use mangler to find messages that match
194 - foreach ( $messageKeys as $key ) {
195 - if ( $mangler->match( $key ) ) {
196 - $matches[] = $key;
197 - }
198 - }
199 - }
200 -
201 - // Add the combined matches
202 - $collection->setTags( $type, $matches );
 213+ foreach ( $this->getTags() as $type => $tags ) {
 214+ $collection->setTags( $type, $tags );
203215 }
204216 }
205217
@@ -288,7 +300,7 @@
289301 return ucfirst( str_replace( '-', '_', parent::mapCode( $code ) ) );
290302 }
291303
292 - protected function setTags( MessageCollection $collection ) {
 304+ public function getTags( $type = null ) {
293305 $path = $this->getFromConf( 'BASIC', 'metadataPath' );
294306
295307 if ( $path === null ) {
@@ -309,10 +321,20 @@
310322
311323 $reader = new ConfEditor( $data );
312324 $vars = $reader->getVars();
313 - $collection->setTags( 'optional', $vars['wgOptionalMessages'] );
314 - $collection->setTags( 'ignored', $vars['wgIgnoredMessages'] );
315325
316 - parent::setTags( $collection );
 326+ $tags = array();
 327+ $tags['optional'] = $vars['wgOptionalMessages'];
 328+ $tags['ignored'] = $vars['wgIgnoredMessages'];
 329+
 330+ if ( !$type ) {
 331+ return $tags;
 332+ }
 333+
 334+ if ( isset( $tags[$type] ) ) {
 335+ return $tags[$type];
 336+ }
 337+
 338+ return array();
317339 }
318340 }
319341
@@ -397,15 +419,8 @@
398420 public function getTags( $type = null ) {
399421 $tags = array();
400422 foreach( $this->getGroups() as $group ) {
401 - //FIXME: is this correct?
402423 $tags = array_merge_recursive( $tags, $group->getTags( $type ) );
403424 }
404425 return $tags;
405426 }
406 -
407 - protected function setTags( MessageCollection $collection ) {
408 - foreach( $this->getGroups() as $group ) {
409 - $group->setTags( $collection );
410 - }
411 - }
412427 }

Status & tagging log