MediaWiki REL1_35
Collation.php
Go to the documentation of this file.
1<?php
24
30abstract class Collation {
31 private static $instance;
32
37 public static function singleton() {
38 if ( !self::$instance ) {
40 self::$instance = self::factory( $wgCategoryCollation );
41 }
42 return self::$instance;
43 }
44
51 public static function factory( $collationName ) {
52 switch ( $collationName ) {
53 case 'uppercase':
54 return new UppercaseCollation;
55 case 'numeric':
57 MediaWikiServices::getInstance()->getContentLanguage() );
58 case 'identity':
59 return new IdentityCollation;
60 case 'uca-default':
61 return new IcuCollation( 'root' );
62 case 'uca-default-u-kn':
63 return new IcuCollation( 'root-u-kn' );
64 case 'xx-uca-ckb':
65 return new CollationCkb;
66 case 'uppercase-ab':
67 return new AbkhazUppercaseCollation;
68 case 'uppercase-ba':
70 default:
71 $match = [];
72 if ( preg_match( '/^uca-([A-Za-z@=-]+)$/', $collationName, $match ) ) {
73 return new IcuCollation( $match[1] );
74 }
75
76 # Provide a mechanism for extensions to hook in.
77 $collationObject = null;
78 Hooks::runner()->onCollation__factory( $collationName, $collationObject );
79
80 if ( $collationObject instanceof self ) {
81 return $collationObject;
82 }
83
84 // If all else fails...
85 throw new MWException( __METHOD__ . ": unknown collation type \"$collationName\"" );
86 }
87 }
88
102 abstract public function getSortKey( $string );
103
129 abstract public function getFirstLetter( $string );
130
131}
$wgCategoryCollation
Specify how category names should be sorted, when listed on a category page.
Workaround for the lack of support of Sorani Kurdish / Central Kurdish language ('ckb') in ICU.
static singleton()
Definition Collation.php:37
getSortKey( $string)
Given a string, convert it to a (hopefully short) key that can be used for efficient sorting.
getFirstLetter( $string)
Given a string, return the logical "first letter" to be used for grouping on category pages and so on...
static $instance
Definition Collation.php:31
static factory( $collationName)
Definition Collation.php:51
Collation class that's essentially a no-op.
MediaWiki exception.
MediaWikiServices is the service locator for the application scope of MediaWiki.
Collation that orders text with numbers "naturally", so that 'Foo 1' < 'Foo 2' < 'Foo 12'.