MediaWiki  1.33.0
Collation.php
Go to the documentation of this file.
1 <?php
24 
29 abstract class Collation {
30  private static $instance;
31 
36  public static function singleton() {
37  if ( !self::$instance ) {
38  global $wgCategoryCollation;
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':
55  return new NumericUppercaseCollation(
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':
68  return new BashkirUppercaseCollation;
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 }
AbkhazUppercaseCollation
Definition: AbkhazUppercaseCollation.php:23
CollationCkb
Workaround for the lack of support of Sorani Kurdish / Central Kurdish language ('ckb') in ICU.
Definition: CollationCkb.php:28
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:23
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:29
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
Collation\singleton
static singleton()
Definition: Collation.php:36
MWException
MediaWiki exception.
Definition: MWException.php:26
NumericUppercaseCollation
Collation that orders text with numbers "naturally", so that 'Foo 1' < 'Foo 2' < 'Foo 12'.
Definition: NumericUppercaseCollation.php:35
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
IdentityCollation
Collation class that's essentially a no-op.
Definition: IdentityCollation.php:31
BashkirUppercaseCollation
Definition: BashkirUppercaseCollation.php:23
$wgCategoryCollation
$wgCategoryCollation
Specify how category names should be sorted, when listed on a category page.
Definition: DefaultSettings.php:7658
Collation\$instance
static $instance
Definition: Collation.php:30
MediaWikiServices
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
Collation\factory
static factory( $collationName)
Definition: Collation.php:50
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
IcuCollation
Definition: IcuCollation.php:24