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