Add CollationFa
authorAmir Sarabadani <Ladsgroup@gmail.com>
Sun, 31 Jul 2016 14:36:49 +0000 (19:06 +0430)
committerBartosz Dziewoński <matma.rex@gmail.com>
Thu, 15 Dec 2016 13:25:56 +0000 (13:25 +0000)
Bug: T139110
Change-Id: Ie15a2ee1c22ff4a1d2b721ed137227fe83dd12ea

autoload.php
includes/collation/Collation.php
includes/collation/CollationFa.php [new file with mode: 0644]

index 5808040..f8b6f23 100644 (file)
@@ -257,6 +257,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 fe254af..0e0ee2f 100644 (file)
@@ -59,6 +59,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 );
+       }
+}