summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>2013-09-05 10:11:02 +0000
committerGerrit Code Review <gerrit@wikimedia.org>2013-09-05 10:11:02 +0000
commit15bbdb5e3a065046a33217fcc53182984c86bc17 (patch)
tree0b7961ac02a0cf0cc4ed25ac492d50d7e74ce105
parent1b8155403c6b7e3cd499314120cde0ab6d52b990 (diff)
parentf303047f680d465694cad69ce0f30d7a2e675d54 (diff)
Merge "Allow registration of Actions using a callback that returns an Action instance"origin/master
-rw-r--r--RELEASE-NOTES-1.223
-rw-r--r--includes/Action.php24
2 files changed, 19 insertions, 8 deletions
diff --git a/RELEASE-NOTES-1.22 b/RELEASE-NOTES-1.22
index e743b48b60e9..44b0faedca37 100644
--- a/RELEASE-NOTES-1.22
+++ b/RELEASE-NOTES-1.22
@@ -151,6 +151,9 @@ production.
** editmyoptions controls whether a user may change their preferences.
* Add new hook AbortTalkPageEmailNotification, this will be used to determine
whether to send the regular talk page email notification
+* Action classes registered in $wgActions are now also supported in the form of
+ a callback (which returns an instance of Action) instead of providing the name
+ of a subclass of Action.
* (bug 46513) Vector: Add the collapsibleTabs script from the Vector extension.
* Added $wgRecentChangesFlags for defining new flags for RecentChanges and
watchlists.
diff --git a/includes/Action.php b/includes/Action.php
index e9961042a171..23b648f421df 100644
--- a/includes/Action.php
+++ b/includes/Action.php
@@ -59,7 +59,7 @@ abstract class Action {
* the action is disabled, or null if it's not recognised
* @param $action String
* @param $overrides Array
- * @return bool|null|string
+ * @return bool|null|string|callable
*/
final private static function getClass( $action, array $overrides ) {
global $wgActions;
@@ -89,12 +89,18 @@ abstract class Action {
* if it is not recognised
*/
final public static function factory( $action, Page $page, IContextSource $context = null ) {
- $class = self::getClass( $action, $page->getActionOverrides() );
- if ( $class ) {
- $obj = new $class( $page, $context );
+ $classOrCallable = self::getClass( $action, $page->getActionOverrides() );
+
+ if ( is_string( $classOrCallable ) ) {
+ $obj = new $classOrCallable( $page, $context );
return $obj;
}
- return $class;
+
+ if ( is_callable( $classOrCallable ) ) {
+ return call_user_func_array( $classOrCallable, array( $page, $context ) );
+ }
+
+ return $classOrCallable;
}
/**
@@ -241,12 +247,14 @@ abstract class Action {
}
/**
- * Protected constructor: use Action::factory( $action, $page ) to actually build
- * these things in the real world
+ * Constructor.
+ *
+ * Only public since 1.21
+ *
* @param $page Page
* @param $context IContextSource
*/
- protected function __construct( Page $page, IContextSource $context = null ) {
+ public function __construct( Page $page, IContextSource $context = null ) {
$this->page = $page;
$this->context = $context;
}