From f980458a9be7d4185c231565e3c5da24bf2226db Mon Sep 17 00:00:00 2001 From: Brian Wolff Date: Tue, 5 Jul 2011 05:30:04 +0000 Subject: [PATCH] (Follow-up r90759 per CR) Use a hook to register new Collations instead of just taking the collation name as a class name --- RELEASE-NOTES-1.19 | 4 ++-- includes/Collation.php | 19 +++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/RELEASE-NOTES-1.19 b/RELEASE-NOTES-1.19 index 2e095dfecd..5802892f2d 100644 --- a/RELEASE-NOTES-1.19 +++ b/RELEASE-NOTES-1.19 @@ -27,8 +27,8 @@ production. was removed in about 1.5. * LogPageValidTypes, LogPageLogName, LogPageLogHeader and LogPageActionText hooks have been removed. -* $wgCategoryCollation can now use a class name as its value, in order for - extensions to be able to define new collations +* New hook "Collation::factory" to allow extensions to create custom + category collations. === New features in 1.19 === * BREAKING CHANGE: action=watch / action=unwatch now requires a token. diff --git a/includes/Collation.php b/includes/Collation.php index e6c98f1f5c..a6f1cfe47a 100644 --- a/includes/Collation.php +++ b/includes/Collation.php @@ -27,17 +27,16 @@ abstract class Collation { return new IcuCollation( 'root' ); default: # Provide a mechanism for extensions to hook in. - if ( class_exists( $collationName ) ) { - $collationObject = new $collationName; - if ( $collationObject instanceof Collation ) { - return $collationObject; - } else { - throw new MWException( __METHOD__.": collation type \"$collationName\"" - . " is not a subclass of Collation." ); - } - } else { - throw new MWException( __METHOD__.": unknown collation type \"$collationName\"" ); + + $collationObject = null; + wfRunHooks( 'Collation::factory', array( $collationName, &$collationObject ) ); + + if ( $collationObject instanceof Collation ) { + return $collationObject; } + + // If all else fails... + throw new MWException( __METHOD__.": unknown collation type \"$collationName\"" ); } } -- 2.20.1