Merge "Add support for PHP7 random_bytes in favor of mcrypt_create_iv"
[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 * All of the following will be considered separate letters for category headings in Persian:
25 * - Characters 'و' 'ا' (often appear at the beginning of words)
26 * - Characters 'ٲ' 'ٳ' (may appear at the beginning of words in loanwords)
27 * - Characters 'ء' 'ئ' (don't appear at the beginning of words, but it's easier to implement)
28 *
29 * @since 1.29
30 */
31 class CollationFa extends IcuCollation {
32 private $tertiaryCollator;
33
34 public function __construct() {
35 parent::__construct( 'fa' );
36 $this->tertiaryCollator = Collator::create( 'fa' );
37 }
38
39 public function getPrimarySortKey( $string ) {
40 $primary = parent::getPrimarySortKey( $string );
41 // We have to use a tertiary sortkey for everything with the primary sortkey of 2627.
42 // Otherwise, the "Remove duplicate prefixes" logic in IcuCollation would remove them.
43 // This matches sortkeys for the following characters: ء ئ ا و ٲ ٳ
44 if ( substr( $primary, 0, 2 ) === "\x26\x27" ) {
45 wfDebug( "Using tertiary sortkey for '$string'\n" );
46 return $this->tertiaryCollator->getSortKey( $string );
47 }
48 return $primary;
49 }
50 }