X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2FAction.php;h=23b648f421df634d4879b4ee07cc9b7ce95a25b6;hb=50c30a7d57fa99855909ef698276ebb8010cda16;hp=2e0c88ba9aea9e8681e34641018248d3be9bb9b8;hpb=7f4e344b2404f3eb51d1facdcfaaa9f4499c4d6b;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Action.php b/includes/Action.php index 2e0c88ba9a..23b648f421 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; } /** @@ -213,7 +219,7 @@ abstract class Action { /** * Shortcut to get the user Language being used for this instance * - * @deprecated 1.19 Use getLanguage instead + * @deprecated since 1.19 Use getLanguage instead * @return Language */ final public function getLang() { @@ -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; } @@ -374,18 +382,23 @@ abstract class FormAction extends Action { * Add pre- or post-text to the form * @return String HTML which will be sent to $form->addPreText() */ - protected function preText() { return ''; } + protected function preText() { + return ''; + } /** * @return string */ - protected function postText() { return ''; } + protected function postText() { + return ''; + } /** * Play with the HTMLForm if you need to more substantially * @param $form HTMLForm */ - protected function alterForm( HTMLForm $form ) {} + protected function alterForm( HTMLForm $form ) { + } /** * Get the HTMLForm to control behavior