* @file
*/
+/**
+ * @since 1.16.3
+ */
class IcuCollation extends Collation {
const FIRST_LETTER_VERSION = 2;
'smn' => [ "Á", "Č", "Đ", "Ŋ", "Š", "Ŧ", "Ž", "Æ", "Ø", "Å", "Ä", "Ö" ],
'sq' => [ "Ç", "Dh", "Ë", "Gj", "Ll", "Nj", "Rr", "Sh", "Th", "Xh", "Zh" ],
'sr' => [],
+ 'ta' => [
+ "\xE0\xAE\x82", "ஃ", "க்ஷ", "க்", "ங்", "ச்", "ஞ்", "ட்", "ண்", "த்", "ந்",
+ "ப்", "ம்", "ய்", "ர்", "ல்", "வ்", "ழ்", "ள்", "ற்", "ன்", "ஜ்", "ஶ்", "ஷ்",
+ "ஸ்", "ஹ்", "க்ஷ்"
+ ],
'tk' => [ "Ç", "Ä", "Ž", "Ň", "Ö", "Ş", "Ü", "Ý" ],
'tl' => [ "Ñ", "Ng" ],
'tr' => [ "Ç", "Ğ", "İ", "Ö", "Ş", "Ü" ],
'uz' => [ "Ch", "G'", "Ng", "O'", "Sh" ],
];
+ /**
+ * @since 1.16.3
+ */
const RECORD_LENGTH = 14;
public function __construct( $locale ) {
}
public function getSortKey( $string ) {
- // intl extension produces non null-terminated
- // strings. Appending '' fixes it so that it doesn't generate
- // a warning on each access in debug php.
- MediaWiki\suppressWarnings();
- $key = $this->mainCollator->getSortKey( $string ) . '';
- MediaWiki\restoreWarnings();
- return $key;
+ return $this->mainCollator->getSortKey( $string );
}
public function getPrimarySortKey( $string ) {
- MediaWiki\suppressWarnings();
- $key = $this->primaryCollator->getSortKey( $string ) . '';
- MediaWiki\restoreWarnings();
- return $key;
+ return $this->primaryCollator->getSortKey( $string );
}
public function getFirstLetter( $string ) {
return $this->getLetterByIndex( $min );
}
+ /**
+ * @since 1.16.3
+ * @return array
+ */
public function getFirstLetterData() {
- if ( $this->firstLetterData !== null ) {
- return $this->firstLetterData;
- }
-
- $cache = wfGetCache( CACHE_ANYTHING );
- $cacheKey = wfMemcKey(
- 'first-letters',
- $this->locale,
- $this->digitTransformLanguage->getCode(),
- self::getICUVersion()
- );
- $cacheEntry = $cache->get( $cacheKey );
-
- if ( $cacheEntry && isset( $cacheEntry['version'] )
- && $cacheEntry['version'] == self::FIRST_LETTER_VERSION
- ) {
- $this->firstLetterData = $cacheEntry;
- return $this->firstLetterData;
+ if ( $this->firstLetterData === null ) {
+ $cache = ObjectCache::getLocalServerInstance( CACHE_ANYTHING );
+ $cacheKey = $cache->makeKey(
+ 'first-letters',
+ $this->locale,
+ $this->digitTransformLanguage->getCode(),
+ self::getICUVersion(),
+ self::FIRST_LETTER_VERSION
+ );
+ $this->firstLetterData = $cache->getWithSetCallback( $cacheKey, $cache::TTL_WEEK, function () {
+ return $this->fetchFirstLetterData();
+ } );
}
+ return $this->firstLetterData;
+ }
+ /**
+ * @return array
+ * @throws MWException
+ */
+ private function fetchFirstLetterData() {
// Generate data from serialized data file
-
if ( isset( self::$tailoringFirstLetters[$this->locale] ) ) {
- $letters = wfGetPrecompiledData( "first-letters-root.ser" );
+ $letters = wfGetPrecompiledData( 'first-letters-root.ser' );
// Append additional characters
$letters = array_merge( $letters, self::$tailoringFirstLetters[$this->locale] );
// Remove unnecessary ones, if any
$data = [
'chars' => array_values( $letterMap ),
'keys' => array_keys( $letterMap ),
- 'version' => self::FIRST_LETTER_VERSION,
];
// Reduce memory usage before caching
unset( $letterMap );
- // Save to cache
- $this->firstLetterData = $data;
- $cache->set( $cacheKey, $data, $cache::TTL_WEEK );
return $data;
}
+ /**
+ * @since 1.16.3
+ */
public function getLetterByIndex( $index ) {
- if ( $this->firstLetterData === null ) {
- $this->getFirstLetterData();
- }
- return $this->firstLetterData['chars'][$index];
+ return $this->getFirstLetterData()['chars'][$index];
}
+ /**
+ * @since 1.16.3
+ */
public function getSortKeyByLetterIndex( $index ) {
- if ( $this->firstLetterData === null ) {
- $this->getFirstLetterData();
- }
- return $this->firstLetterData['keys'][$index];
+ return $this->getFirstLetterData()['keys'][$index];
}
+ /**
+ * @since 1.16.3
+ */
public function getFirstLetterCount() {
- if ( $this->firstLetterData === null ) {
- $this->getFirstLetterData();
- }
- return count( $this->firstLetterData['chars'] );
+ return count( $this->getFirstLetterData()['chars'] );
}
- static function isCjk( $codepoint ) {
+ /**
+ * @since 1.16.3
+ */
+ public static function isCjk( $codepoint ) {
foreach ( self::$cjkBlocks as $block ) {
if ( $codepoint >= $block[0] && $codepoint <= $block[1] ) {
return true;