Index: trunk/extensions/Translate/Groups.php |
— | — | @@ -151,6 +151,47 @@ |
152 | 152 | } |
153 | 153 | |
154 | 154 | 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 ) { |
155 | 196 | if ( !isset( $this->conf['TAGS'] ) ) { |
156 | 197 | return array(); |
157 | 198 | } |
— | — | @@ -168,37 +209,8 @@ |
169 | 210 | } |
170 | 211 | |
171 | 212 | 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 ); |
203 | 215 | } |
204 | 216 | } |
205 | 217 | |
— | — | @@ -288,7 +300,7 @@ |
289 | 301 | return ucfirst( str_replace( '-', '_', parent::mapCode( $code ) ) ); |
290 | 302 | } |
291 | 303 | |
292 | | - protected function setTags( MessageCollection $collection ) { |
| 304 | + public function getTags( $type = null ) { |
293 | 305 | $path = $this->getFromConf( 'BASIC', 'metadataPath' ); |
294 | 306 | |
295 | 307 | if ( $path === null ) { |
— | — | @@ -309,10 +321,20 @@ |
310 | 322 | |
311 | 323 | $reader = new ConfEditor( $data ); |
312 | 324 | $vars = $reader->getVars(); |
313 | | - $collection->setTags( 'optional', $vars['wgOptionalMessages'] ); |
314 | | - $collection->setTags( 'ignored', $vars['wgIgnoredMessages'] ); |
315 | 325 | |
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(); |
317 | 339 | } |
318 | 340 | } |
319 | 341 | |
— | — | @@ -397,15 +419,8 @@ |
398 | 420 | public function getTags( $type = null ) { |
399 | 421 | $tags = array(); |
400 | 422 | foreach( $this->getGroups() as $group ) { |
401 | | - //FIXME: is this correct? |
402 | 423 | $tags = array_merge_recursive( $tags, $group->getTags( $type ) ); |
403 | 424 | } |
404 | 425 | return $tags; |
405 | 426 | } |
406 | | - |
407 | | - protected function setTags( MessageCollection $collection ) { |
408 | | - foreach( $this->getGroups() as $group ) { |
409 | | - $group->setTags( $collection ); |
410 | | - } |
411 | | - } |
412 | 427 | } |