From a658eee7fc65b19f6bb937131cdcdd5bb4e941b2 Mon Sep 17 00:00:00 2001 From: Brian Wolff Date: Sun, 11 Sep 2011 01:13:08 +0000 Subject: [PATCH] (bug 30722) Add an identity collation that sorts things based on what the unicode code point is (aka pre-1.17 behaviour). I'm tagging this 1.18 because the original bug was for iswiktionary wanting it, so it'd be nice to get it in 1.18. --- RELEASE-NOTES-1.18 | 1 + includes/AutoLoader.php | 1 + includes/Collation.php | 26 ++++++++++++++++++++++++++ includes/DefaultSettings.php | 4 +++- 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/RELEASE-NOTES-1.18 b/RELEASE-NOTES-1.18 index 19daaa1c12..144da2eb4f 100644 --- a/RELEASE-NOTES-1.18 +++ b/RELEASE-NOTES-1.18 @@ -209,6 +209,7 @@ production. * Introduced $wgVaryOnXFPForAPI which will cause the API to send Vary: X-Forwarded-Proto headers. * New maintenance script to refresh image metadata (maintenance/refreshImageMetadata.php) +* (bug 30722) Add a new collation that sorts categories in ascii sort order. === Bug fixes in 1.18 === * mw.util.getScript has been implemented (like wfScript in GlobalFunctions.php) diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index d407ca68fa..065a487207 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -118,6 +118,7 @@ $wgAutoloadLocalClasses = array( 'HttpRequest' => 'includes/HttpFunctions.old.php', 'IContextSource' => 'includes/RequestContext.php', 'IcuCollation' => 'includes/Collation.php', + 'IdentityCollation' => 'includes/Collation.php', 'ImageGallery' => 'includes/ImageGallery.php', 'ImageHistoryList' => 'includes/ImagePage.php', 'ImageHistoryPseudoPager' => 'includes/ImagePage.php', diff --git a/includes/Collation.php b/includes/Collation.php index a6f1cfe47a..0c510b7830 100644 --- a/includes/Collation.php +++ b/includes/Collation.php @@ -23,6 +23,8 @@ abstract class Collation { switch( $collationName ) { case 'uppercase': return new UppercaseCollation; + case 'identity': + return new IdentityCollation; case 'uca-default': return new IcuCollation( 'root' ); default: @@ -99,6 +101,30 @@ class UppercaseCollation extends Collation { } } +/** + * Collation class that's essentially a no-op. + * + * Does sorting based on binary value of the string. + * Like how things were pre 1.17. + */ +class IdentityCollation extends Collation { + + function getSortKey( $string ) { + return $string; + } + + function getFirstLetter( $string ) { + global $wgContLang; + // Copied from UppercaseCollation. + // I'm kind of unclear on when this could happen... + if ( $string[0] == "\0" ) { + $string = substr( $string, 1 ); + } + return $wgContLang->firstChar( $string ); + } +} + + class IcuCollation extends Collation { var $primaryCollator, $mainCollator, $locale; var $firstLetterData; diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index b7d9e0012e..a6c1d03ae6 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -4879,6 +4879,8 @@ $wgCategoryPagingLimit = 200; * * - uppercase: Converts the category name to upper case, and sorts by that. * + * - identity: Does no conversion. Sorts by binary value of the string. + * * - uca-default: Provides access to the Unicode Collation Algorithm with * the default element table. This is a compromise collation which sorts * all languages in a mediocre way. However, it is better than "uppercase". @@ -4892,7 +4894,7 @@ $wgCategoryPagingLimit = 200; * the sort keys in the database. * * Extensions can define there own collations by subclassing Collation - * and using the class name as the value of this variable. + * and using the Collation::factory hook. */ $wgCategoryCollation = 'uppercase'; -- 2.20.1