Merge "Perform a permission check on the title when changing the page language"
[lhc/web/wiklou.git] / includes / collation / CollationFa.php
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21 /**
22 * Temporary workaround for incorrect collation of Persian language ('fa') in ICU 52 (bug T139110).
23 *
24 * Replace with other letters that appear in an okish spot in the alphabet
25 *
26 * - Characters 'و' 'ا' (often appear at the beginning of words)
27 * - Characters 'ٲ' 'ٳ' (may appear at the beginning of words in loanwords)
28 *
29 * @since 1.29
30 */
31 class CollationFa extends IcuCollation {
32
33 // Really hacky - replace with stuff from other blocks.
34 private $override = [
35 "\xd8\xa7" => "\xd8\xa1",
36 "\xd9\x88" => "\xd9\x89",
37 "\xd9\xb2" => "\xF3\xB3\x80\x81",
38 "\xd9\xb3" => "\xF3\xB3\x80\x82",
39 ];
40
41 public function __construct() {
42 parent::__construct( 'fa' );
43 }
44
45 public function getSortKey( $string ) {
46 $modified = strtr( $string, $this->override );
47 return parent::getSortKey( $modified );
48 }
49
50 public function getFirstLetter( $string ) {
51 if ( isset( $this->override[substr( $string, 0, 2 )] ) ) {
52 return substr( $string, 0, 2 );
53 }
54 return parent::getFirstLetter( $string );
55 }
56 }