MediaWiki REL1_34
Collation.php
Go to the documentation of this file.
1<?php
24
29abstract class Collation {
30 private static $instance;
31
36 public static function singleton() {
37 if ( !self::$instance ) {
39 self::$instance = self::factory( $wgCategoryCollation );
40 }
41 return self::$instance;
42 }
43
50 public static function factory( $collationName ) {
51 switch ( $collationName ) {
52 case 'uppercase':
53 return new UppercaseCollation;
54 case 'numeric':
56 MediaWikiServices::getInstance()->getContentLanguage() );
57 case 'identity':
58 return new IdentityCollation;
59 case 'uca-default':
60 return new IcuCollation( 'root' );
61 case 'uca-default-u-kn':
62 return new IcuCollation( 'root-u-kn' );
63 case 'xx-uca-ckb':
64 return new CollationCkb;
65 case 'uppercase-ab':
66 return new AbkhazUppercaseCollation;
67 case 'uppercase-ba':
69 default:
70 $match = [];
71 if ( preg_match( '/^uca-([A-Za-z@=-]+)$/', $collationName, $match ) ) {
72 return new IcuCollation( $match[1] );
73 }
74
75 # Provide a mechanism for extensions to hook in.
76 $collationObject = null;
77 Hooks::run( 'Collation::factory', [ $collationName, &$collationObject ] );
78
79 if ( $collationObject instanceof self ) {
80 return $collationObject;
81 }
82
83 // If all else fails...
84 throw new MWException( __METHOD__ . ": unknown collation type \"$collationName\"" );
85 }
86 }
87
101 abstract function getSortKey( $string );
102
128 abstract function getFirstLetter( $string );
129
130}
$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:36
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:30
static factory( $collationName)
Definition Collation.php:50
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'.