Merge "Add CollationFa"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 15 Dec 2016 13:37:56 +0000 (13:37 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 15 Dec 2016 13:37:56 +0000 (13:37 +0000)
autoload.php
includes/collation/Collation.php
includes/collation/CollationFa.php [new file with mode: 0644]

index 0283d3c..9dba6cd 100644 (file)
@@ -260,6 +260,7 @@ $wgAutoloadLocalClasses = [
        'Collation' => __DIR__ . '/includes/collation/Collation.php',
        'CollationCkb' => __DIR__ . '/includes/collation/CollationCkb.php',
        'CollationEt' => __DIR__ . '/includes/collation/CollationEt.php',
+       'CollationFa' => __DIR__ . '/includes/collation/CollationFa.php',
        'CommandLineInc' => __DIR__ . '/maintenance/commandLine.inc',
        'CommandLineInstaller' => __DIR__ . '/maintenance/install.php',
        'CompareParserCache' => __DIR__ . '/maintenance/compareParserCache.php',
index 9950a11..7659d6c 100644 (file)
@@ -63,6 +63,8 @@ abstract class Collation {
                                return new CollationCkb;
                        case 'xx-uca-et':
                                return new CollationEt;
+                       case 'xx-uca-fa':
+                               return new CollationFa;
                        default:
                                $match = [];
                                if ( preg_match( '/^uca-([a-z@=-]+)$/', $collationName, $match ) ) {
diff --git a/includes/collation/CollationFa.php b/includes/collation/CollationFa.php
new file mode 100644 (file)
index 0000000..b7e45cc
--- /dev/null
@@ -0,0 +1,44 @@
+<?php
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * Temporary workaround for incorrect collation of Persian language ('fa') in ICU (bug T139110).
+ *
+ * 'ا' and 'و' should not be considered the same letter for the purposes of collation in Persian.
+ *
+ * @since 1.29
+ */
+class CollationFa extends IcuCollation {
+       private $tertiaryCollator;
+
+       public function __construct() {
+               parent::__construct( 'fa' );
+               $this->tertiaryCollator = Collator::create( 'fa' );
+       }
+
+       public function getPrimarySortKey( $string ) {
+               $firstLetter = mb_substr( $string, 0, 1 );
+               if ( $firstLetter === 'و' || $firstLetter === 'ا' ) {
+                       return $this->tertiaryCollator->getSortKey( $string );
+               }
+
+               return parent::getPrimarySortKey( $string );
+       }
+}