r91436 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91435‎ | r91436 | r91437 >
Date:05:30, 5 July 2011
Author:bawolff
Status:ok
Tags:
Comment:
(Follow-up r90759 per CR) Use a hook to register new Collations instead of just taking the collation name as a class name
Modified paths:
  • /trunk/phase3/RELEASE-NOTES-1.19 (modified) (history)
  • /trunk/phase3/includes/Collation.php (modified) (history)

Diff [purge]

Index: trunk/phase3/RELEASE-NOTES-1.19
@@ -27,8 +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
 31+* New hook "Collation::factory" to allow extensions to create custom
 32+ category collations.
3333
3434 === New features in 1.19 ===
3535 * BREAKING CHANGE: action=watch / action=unwatch now requires a token.
Index: trunk/phase3/includes/Collation.php
@@ -27,17 +27,16 @@
2828 return new IcuCollation( 'root' );
2929 default:
3030 # 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\"" );
 31+
 32+ $collationObject = null;
 33+ wfRunHooks( 'Collation::factory', array( $collationName, &$collationObject ) );
 34+
 35+ if ( $collationObject instanceof Collation ) {
 36+ return $collationObject;
4137 }
 38+
 39+ // If all else fails...
 40+ throw new MWException( __METHOD__.": unknown collation type \"$collationName\"" );
4241 }
4342 }
4443

Follow-up revisions

RevisionCommit summaryAuthorDate
r91437(follow-up r91436) Make this extension use the new hook i just made.bawolff05:30, 5 July 2011
r91438(follow-up r91436) add new hook to hooks.txt...bawolff05:33, 5 July 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r90759Let $wgCategoryCollation take a class name as a value so that extensions...bawolff07:21, 25 June 2011

Status & tagging log