From: Gergő Tisza Date: Fri, 1 Apr 2016 12:51:04 +0000 (+0300) Subject: Allow SpecialPage::beforeExecute to prevent execution X-Git-Tag: 1.31.0-rc.0~7450^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_aide%28?a=commitdiff_plain;h=5f1d4591d95cea154b0a5f8d40a856cac97aa27e;p=lhc%2Fweb%2Fwiklou.git Allow SpecialPage::beforeExecute to prevent execution Allos SpecialPage::beforeExecute() (and the equivalent SpecialPageBeforeExecute hook) to prevent execution of the page by returning false. Needed by I8b52ec8ddf494f23941807638f149f15b5e46b0c. Change-Id: I71423b920d596ee9ae6da60d95b14255eddfbcd6 --- diff --git a/docs/hooks.txt b/docs/hooks.txt index 9478f485f6..01fae5bb6e 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -2855,6 +2855,7 @@ $special: the SpecialPage object $subPage: the subpage string or null if no subpage was specified 'SpecialPageBeforeExecute': Called before SpecialPage::execute. +Return false to prevent execution. $special: the SpecialPage object $subPage: the subpage string or null if no subpage was specified diff --git a/includes/specialpage/SpecialPage.php b/includes/specialpage/SpecialPage.php index 6a04c6a754..90ace7b2dc 100644 --- a/includes/specialpage/SpecialPage.php +++ b/includes/specialpage/SpecialPage.php @@ -395,15 +395,20 @@ class SpecialPage { final public function run( $subPage ) { /** * Gets called before @see SpecialPage::execute. + * Return false to prevent calling execute() (since 1.27+). * * @since 1.20 * * @param SpecialPage $this * @param string|null $subPage */ - Hooks::run( 'SpecialPageBeforeExecute', [ $this, $subPage ] ); + if ( !Hooks::run( 'SpecialPageBeforeExecute', [ $this, $subPage ] ) ) { + return; + } - $this->beforeExecute( $subPage ); + if ( $this->beforeExecute( $subPage ) === false ) { + return; + } $this->execute( $subPage ); $this->afterExecute( $subPage ); @@ -420,10 +425,12 @@ class SpecialPage { /** * Gets called before @see SpecialPage::execute. + * Return false to prevent calling execute() (since 1.27+). * * @since 1.20 * * @param string|null $subPage + * @return bool|void */ protected function beforeExecute( $subPage ) { // No-op