Allow SpecialPage::beforeExecute to prevent execution
authorGergő Tisza <tgr.huwiki@gmail.com>
Fri, 1 Apr 2016 12:51:04 +0000 (15:51 +0300)
committerGergő Tisza <tgr.huwiki@gmail.com>
Fri, 1 Apr 2016 12:51:04 +0000 (15:51 +0300)
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
includes/specialpage/SpecialPage.php

index 9478f48..01fae5b 100644 (file)
@@ -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
 
index 6a04c6a..90ace7b 100644 (file)
@@ -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