From 5f1d4591d95cea154b0a5f8d40a856cac97aa27e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gerg=C5=91=20Tisza?= Date: Fri, 1 Apr 2016 15:51:04 +0300 Subject: [PATCH] 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 --- docs/hooks.txt | 1 + includes/specialpage/SpecialPage.php | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) 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 -- 2.20.1