r90759 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90758‎ | r90759 | r90760 >
Date:07:21, 25 June 2011
Author:bawolff
Status:resolved (Comments)
Tags:
Comment:
Let $wgCategoryCollation take a class name as a value so that extensions
can define new Collation classes.

(I plan to commit such an extension shortly)

Wasn't sure if it would be better to make an array mapping collation names => class names
instead. However, that seemed to be unneededly complicated so I went with
letting that variable take class names.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES-1.19 (modified) (history)
  • /trunk/phase3/includes/Collation.php (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)

Diff [purge]

Index: trunk/phase3/RELEASE-NOTES-1.19
@@ -27,6 +27,8 @@
2828 was removed in about 1.5.
2929 * LogPageValidTypes, LogPageLogName, LogPageLogHeader and LogPageActionText
3030 hooks have been removed.
 31+* $wgCategoryCollation can now use a class name as its value, in order for
 32+ extensions to be able to define new collations
3133
3234 === New features in 1.19 ===
3335 * BREAKING CHANGE: action=watch / action=unwatch now requires a token.
Index: trunk/phase3/includes/Collation.php
@@ -26,7 +26,18 @@
2727 case 'uca-default':
2828 return new IcuCollation( 'root' );
2929 default:
30 - throw new MWException( __METHOD__.": unknown collation type \"$collationName\"" );
 30+ # Provide a mechanism for extensions to hook in.
 31+ if ( class_exists( $collationName ) ) {
 32+ $collationObject = new $collationName;
 33+ if ( $collationObject instanceof Collation ) {
 34+ return $collationObject;
 35+ } else {
 36+ throw new MWException( __METHOD__.": collation type \"$collationName\""
 37+ . " is not a subclass of Collation." );
 38+ }
 39+ } else {
 40+ throw new MWException( __METHOD__.": unknown collation type \"$collationName\"" );
 41+ }
3142 }
3243 }
3344
Index: trunk/phase3/includes/DefaultSettings.php
@@ -4731,6 +4731,9 @@
47324732 *
47334733 * After you change this, you must run maintenance/updateCollation.php to fix
47344734 * the sort keys in the database.
 4735+ *
 4736+ * Extensions can define there own collations by subclassing Collation
 4737+ * and using the class name as the value of this variable.
47354738 */
47364739 $wgCategoryCollation = 'uppercase';
47374740

Follow-up revisions

RevisionCommit summaryAuthorDate
r90760New extension: CategorySortHeaders, to make custom headers instead of just th...bawolff07:27, 25 June 2011
r91436(Follow-up r90759 per CR) Use a hook to register new Collations instead of ju...bawolff05:30, 5 July 2011

Comments

#Comment by Brion VIBBER (talk | contribs)   23:25, 28 June 2011

Could also do this by adding a wfRunHooks call in Collation::factory to handle unknown names. This would let extensions add arbitrarily-named collations, including accepting parameters (maybe 'myfunkycollation:uppercase' to make something that piggybacks on top of another collation, or to accept a language-specific parameter). The extension can then pass whatever values it needs to the object constructor and simply return the object.

Status & tagging log