MediaWiki  master
Collation.php
Go to the documentation of this file.
1 <?php
24 
30 abstract class Collation {
31  private static $instance;
32 
37  public static function singleton() {
38  if ( !self::$instance ) {
39  global $wgCategoryCollation;
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':
56  return new NumericUppercaseCollation(
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':
69  return new BashkirUppercaseCollation;
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 }
AbkhazUppercaseCollation
Definition: AbkhazUppercaseCollation.php:25
CollationCkb
Workaround for the lack of support of Sorani Kurdish / Central Kurdish language ('ckb') in ICU.
Definition: CollationCkb.php:30
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:154
Collation\getSortKey
getSortKey( $string)
Given a string, convert it to a (hopefully short) key that can be used for efficient sorting.
UppercaseCollation
Definition: UppercaseCollation.php:25
Collation\getFirstLetter
getFirstLetter( $string)
Given a string, return the logical "first letter" to be used for grouping on category pages and so on...
Collation
Definition: Collation.php:30
Collation\singleton
static singleton()
Definition: Collation.php:37
MWException
MediaWiki exception.
Definition: MWException.php:29
NumericUppercaseCollation
Collation that orders text with numbers "naturally", so that 'Foo 1' < 'Foo 2' < 'Foo 12'.
Definition: NumericUppercaseCollation.php:35
Hooks\runner
static runner()
Get a HookRunner instance for calling hooks using the new interfaces.
Definition: Hooks.php:172
IdentityCollation
Collation class that's essentially a no-op.
Definition: IdentityCollation.php:31
BashkirUppercaseCollation
Definition: BashkirUppercaseCollation.php:25
$wgCategoryCollation
$wgCategoryCollation
Specify how category names should be sorted, when listed on a category page.
Definition: DefaultSettings.php:8108
Collation\$instance
static $instance
Definition: Collation.php:31
Collation\factory
static factory( $collationName)
Definition: Collation.php:51
IcuCollation
Definition: IcuCollation.php:26