r82223 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82222‎ | r82223 | r82224 >
Date:07:37, 16 February 2011
Author:catrope
Status:ok
Tags:
Comment:
1.17wmf1: MFT r82221
Modified paths:
  • /branches/wmf/1.17wmf1/includes/LocalisationCache.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/MagicWord.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.17wmf1/includes/LocalisationCache.php
@@ -457,7 +457,8 @@
458458 } else {
459459 $oldSynonyms = array_slice( $fallbackInfo, 1 );
460460 $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 ) ) );
462463 $value[$magicName] = array_merge( array( $fallbackInfo[0] ), $synonyms );
463464 }
464465 }
Property changes on: branches/wmf/1.17wmf1/includes/LocalisationCache.php
___________________________________________________________________
Modified: svn:mergeinfo
465466 Merged /trunk/phase3/includes/LocalisationCache.php:r82221
Index: branches/wmf/1.17wmf1/includes/MagicWord.php
@@ -272,13 +272,13 @@
273273 * @private
274274 */
275275 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' ) );
280280
281281 $escSyn = array();
282 - foreach ( $this->mSynonyms as $synonym )
 282+ foreach ( $synonyms as $synonym )
283283 // In case a magic word contains /, like that's going to happen;)
284284 $escSyn[] = preg_quote( $synonym, '/' );
285285 $this->mBaseRegex = implode( '|', $escSyn );
@@ -292,6 +292,23 @@
293293 }
294294
295295 /**
 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+ /**
296313 * Gets a regex representing matching the word
297314 */
298315 function getRegex() {

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r82221* Fix for r81960: List the local magic word synonyms first, so that they will...tstarling07:24, 16 February 2011

Status & tagging log