(bug 30722) Add an identity collation that sorts things based on what the unicode...
authorBrian Wolff <bawolff@users.mediawiki.org>
Sun, 11 Sep 2011 01:13:08 +0000 (01:13 +0000)
committerBrian Wolff <bawolff@users.mediawiki.org>
Sun, 11 Sep 2011 01:13:08 +0000 (01:13 +0000)
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
includes/AutoLoader.php
includes/Collation.php
includes/DefaultSettings.php

index 19daaa1..144da2e 100644 (file)
@@ -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)
index d407ca6..065a487 100644 (file)
@@ -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',
index a6f1cfe..0c510b7 100644 (file)
@@ -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;
index b7d9e00..a6c1d03 100644 (file)
@@ -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';