MediaWiki REL1_30
CustomUppercaseCollation.php
Go to the documentation of this file.
1<?php
40
42 private $alphabet;
43
45 private $puaSubset;
46
53 public function __construct( array $alphabet, Language $lang ) {
54 // It'd be trivial to extend this past 64, you'd just
55 // need a bit of bit-fiddling. Doesn't seem necessary right
56 // now.
57 if ( count( $alphabet ) < 1 || count( $alphabet ) >= 64 ) {
58 throw new UnexpectedValueException( "Alphabet must be < 64 items" );
59 }
60 $this->alphabet = $alphabet;
61
62 $this->puaSubset = [];
63 $len = count( $alphabet );
64 for ( $i = 0; $i < $len; $i++ ) {
65 $this->puaSubset[] = "\xF3\xB3\x80" . chr( $i + 128 );
66 }
67 parent::__construct( $lang );
68 }
69
70 private function convertToPua( $string ) {
71 return str_replace( $this->alphabet, $this->puaSubset, $string );
72 }
73
74 public function getSortKey( $string ) {
75 return $this->convertToPua( parent::getSortKey( $string ) );
76 }
77
78 public function getFirstLetter( $string ) {
79 // In case a title has a PUA code in it, make it sort
80 // under the header for the character it would replace
81 // to avoid inconsistent behaviour. This class mostly
82 // assumes that people will not use PUA codes.
83 return parent::getFirstLetter(
84 str_replace( $this->puaSubset, $this->alphabet, $string )
85 );
86 }
87}
Resort normal UTF-8 order by putting a bunch of stuff in PUA.
getSortKey( $string)
Given a string, convert it to a (hopefully short) key that can be used for efficient sorting.
__construct(array $alphabet, Language $lang)
getFirstLetter( $string)
Given a string, return the logical "first letter" to be used for grouping on category pages and so on...
Internationalisation code.
Definition Language.php:35
Collation that orders text with numbers "naturally", so that 'Foo 1' < 'Foo 2' < 'Foo 12'.