From: Bartosz DziewoƄski Date: Wed, 27 Jul 2016 14:43:01 +0000 (+0200) Subject: Implement NumericUppercaseCollation X-Git-Tag: 1.31.0-rc.0~5927 X-Git-Url: http://git.cyclocoop.org/%7B%7B%20url_for%28%27admin_vote_del%27%2C%20idvote=vote.voteid%29%20%7D%7D?a=commitdiff_plain;h=3b84eb02c2ded04e8819ac5bbdb5c99505e63682;p=lhc%2Fweb%2Fwiklou.git Implement NumericUppercaseCollation This collation orders text with numbers "naturally", so that 'Foo 1' < 'Foo 2' < 'Foo 12'. Note that this only works in terms of sequences of digits, and the behavior for decimal fractions or pretty-formatted numbers may be unexpected. This is only expected to work mostly correctly for English-language text. Consider it a proof of concept. You probably want to use an UCA collation with '-u-kn' suffix rather than this. Bug: T8948 Change-Id: Ie268f2d92c5c75d0aaecf54ede2bdda1af3b309d --- diff --git a/RELEASE-NOTES-1.28 b/RELEASE-NOTES-1.28 index 865e300e90..92ac869535 100644 --- a/RELEASE-NOTES-1.28 +++ b/RELEASE-NOTES-1.28 @@ -39,7 +39,8 @@ production. * (T141604) Extensions can now provide a better error message when their maintenance scripts are run without the extension being installed. * (T8948) Numeric sorting in categories is now supported by setting $wgCategoryCollation - to uca-default-u-kn or uca--u-kn. If migrating from another + to 'uca-default-u-kn' or 'uca--u-kn'. If you can't use UCA collations, + a 'numeric' collation is also available. If migrating from another collation, you will need to run the updateCollation.php maintenance script. === External library changes in 1.28 === diff --git a/autoload.php b/autoload.php index 0d190566f4..39102fd358 100644 --- a/autoload.php +++ b/autoload.php @@ -975,6 +975,7 @@ $wgAutoloadLocalClasses = [ 'NullLockManager' => __DIR__ . '/includes/filebackend/lockmanager/LockManager.php', 'NullRepo' => __DIR__ . '/includes/filerepo/NullRepo.php', 'NullStatsdDataFactory' => __DIR__ . '/includes/libs/stats/NullStatsdDataFactory.php', + 'NumericUppercaseCollation' => __DIR__ . '/includes/collation/NumericUppercaseCollation.php', 'OOUIHTMLForm' => __DIR__ . '/includes/htmlform/OOUIHTMLForm.php', 'ORAField' => __DIR__ . '/includes/db/DatabaseOracle.php', 'ORAResult' => __DIR__ . '/includes/db/DatabaseOracle.php', diff --git a/includes/collation/Collation.php b/includes/collation/Collation.php index fe254afdc5..881c8c23fe 100644 --- a/includes/collation/Collation.php +++ b/includes/collation/Collation.php @@ -49,6 +49,8 @@ abstract class Collation { switch ( $collationName ) { case 'uppercase': return new UppercaseCollation; + case 'numeric': + return new NumericUppercaseCollation; case 'identity': return new IdentityCollation; case 'uca-default': diff --git a/includes/collation/NumericUppercaseCollation.php b/includes/collation/NumericUppercaseCollation.php new file mode 100644 index 0000000000..4bf2f737fb --- /dev/null +++ b/includes/collation/NumericUppercaseCollation.php @@ -0,0 +1,58 @@ +params( 0, 9 )->text(); + } else { + return parent::getFirstLetter( $string ); + } + } +}