Merge "Add unicode mapping for ICU 60 and 61"
[lhc/web/wiklou.git] / includes / collation / IcuCollation.php
index 36efdb3..f38396d 100644 (file)
@@ -333,7 +333,7 @@ class IcuCollation extends Collation {
                                static::class,
                                $this->locale,
                                $this->digitTransformLanguage->getCode(),
-                               self::getICUVersion(),
+                               INTL_ICU_VERSION,
                                self::FIRST_LETTER_VERSION
                        );
                        $this->firstLetterData = $cache->getWithSetCallback( $cacheKey, $cache::TTL_WEEK, function () {
@@ -384,9 +384,17 @@ class IcuCollation extends Collation {
                foreach ( $letters as $letter ) {
                        $key = $this->getPrimarySortKey( $letter );
                        if ( isset( $letterMap[$key] ) ) {
-                               // Primary collision
-                               // Keep whichever one sorts first in the main collator
-                               if ( $this->mainCollator->compare( $letter, $letterMap[$key] ) < 0 ) {
+                               // Primary collision (two characters with the same sort position).
+                               // Keep whichever one sorts first in the main collator.
+                               $comp = $this->mainCollator->compare( $letter, $letterMap[$key] );
+                               wfDebug( "Primary collision '$letter' '{$letterMap[$key]}' (comparison: $comp)\n" );
+                               // If that also has a collision, use codepoint as a tiebreaker.
+                               if ( $comp === 0 ) {
+                                       // TODO Use <=> operator when PHP 7 is allowed.
+                                       $comp = UtfNormal\Utils::utf8ToCodepoint( $letter ) -
+                                               UtfNormal\Utils::utf8ToCodepoint( $letterMap[$key] );
+                               }
+                               if ( $comp < 0 ) {
                                        $letterMap[$key] = $letter;
                                }
                        } else {
@@ -520,18 +528,14 @@ class IcuCollation extends Collation {
         * can't be determined.
         *
         * The constant INTL_ICU_VERSION this function refers to isn't really
-        * documented. It is available since PHP 5.3.7 (see PHP 54561
-        * https://bugs.php.net/bug.php?id=54561). This function will return
-        * false on older PHPs.
-        *
-        * TODO: Remove the backwards-compatibility as MediaWiki now requires
-        * higher levels of PHP.
+        * documented, but see https://bugs.php.net/bug.php?id=54561.
         *
         * @since 1.21
-        * @return string|bool
+        * @deprecated since 1.32, use INTL_ICU_VERSION directly
+        * @return string
         */
        static function getICUVersion() {
-               return defined( 'INTL_ICU_VERSION' ) ? INTL_ICU_VERSION : false;
+               return INTL_ICU_VERSION;
        }
 
        /**
@@ -542,7 +546,7 @@ class IcuCollation extends Collation {
         * @return string|bool
         */
        static function getUnicodeVersionForICU() {
-               $icuVersion = self::getICUVersion();
+               $icuVersion = INTL_ICU_VERSION;
                if ( !$icuVersion ) {
                        return false;
                }
@@ -550,6 +554,8 @@ class IcuCollation extends Collation {
                $versionPrefix = substr( $icuVersion, 0, 3 );
                // Source: http://site.icu-project.org/download
                $map = [
+                       '61.' => '10.0',
+                       '60.' => '10.0',
                        '59.' => '9.0',
                        '58.' => '9.0',
                        '57.' => '8.0',