Index: branches/wmf/1.17wmf1/includes/LocalisationCache.php |
— | — | @@ -457,7 +457,8 @@ |
458 | 458 | } else { |
459 | 459 | $oldSynonyms = array_slice( $fallbackInfo, 1 ); |
460 | 460 | $newSynonyms = array_slice( $value[$magicName], 1 ); |
461 | | - $synonyms = array_unique( array_merge( $oldSynonyms, $newSynonyms ) ); |
| 461 | + $synonyms = array_values( array_unique( array_merge( |
| 462 | + $newSynonyms, $oldSynonyms ) ) ); |
462 | 463 | $value[$magicName] = array_merge( array( $fallbackInfo[0] ), $synonyms ); |
463 | 464 | } |
464 | 465 | } |
Property changes on: branches/wmf/1.17wmf1/includes/LocalisationCache.php |
___________________________________________________________________ |
Modified: svn:mergeinfo |
465 | 466 | Merged /trunk/phase3/includes/LocalisationCache.php:r82221 |
Index: branches/wmf/1.17wmf1/includes/MagicWord.php |
— | — | @@ -272,13 +272,13 @@ |
273 | 273 | * @private |
274 | 274 | */ |
275 | 275 | function initRegex() { |
276 | | - #$variableClass = Title::legalChars(); |
277 | | - # This was used for matching "$1" variables, but different uses of the feature will have |
278 | | - # different restrictions, which should be checked *after* the MagicWord has been matched, |
279 | | - # not here. - IMSoP |
| 276 | + // Sort the synonyms by length, descending, so that the longest synonym |
| 277 | + // matches in precedence to the shortest |
| 278 | + $synonyms = $this->mSynonyms; |
| 279 | + usort( $synonyms, array( $this, 'compareStringLength' ) ); |
280 | 280 | |
281 | 281 | $escSyn = array(); |
282 | | - foreach ( $this->mSynonyms as $synonym ) |
| 282 | + foreach ( $synonyms as $synonym ) |
283 | 283 | // In case a magic word contains /, like that's going to happen;) |
284 | 284 | $escSyn[] = preg_quote( $synonym, '/' ); |
285 | 285 | $this->mBaseRegex = implode( '|', $escSyn ); |
— | — | @@ -292,6 +292,23 @@ |
293 | 293 | } |
294 | 294 | |
295 | 295 | /** |
| 296 | + * A comparison function that returns -1, 0 or 1 depending on whether the |
| 297 | + * first string is longer, the same length or shorter than the second |
| 298 | + * string. |
| 299 | + */ |
| 300 | + function compareStringLength( $s1, $s2 ) { |
| 301 | + $l1 = strlen( $s1 ); |
| 302 | + $l2 = strlen( $s2 ); |
| 303 | + if ( $l1 < $l2 ) { |
| 304 | + return 1; |
| 305 | + } elseif ( $l1 > $l2 ) { |
| 306 | + return -1; |
| 307 | + } else { |
| 308 | + return 0; |
| 309 | + } |
| 310 | + } |
| 311 | + |
| 312 | + /** |
296 | 313 | * Gets a regex representing matching the word |
297 | 314 | */ |
298 | 315 | function getRegex() { |