Merge "Remove $wgExceptionHooks"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 22 May 2017 16:19:46 +0000 (16:19 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 22 May 2017 16:19:46 +0000 (16:19 +0000)
RELEASE-NOTES-1.30
includes/DefaultSettings.php
includes/exception/MWException.php
includes/exception/MWExceptionRenderer.php
tests/phpunit/includes/exception/MWExceptionTest.php

index 03ae7c2..4e25532 100644 (file)
@@ -20,6 +20,7 @@ production.
 * $wgResourceModules may now specify callback functions as an alternative
   to plain class names, using the 'factory' key in the module description
   array. This allows dependency injection to be used for ResourceLoader modules.
+* $wgExceptionHooks has been removed.
 
 === New features in 1.30 ===
 * (T37247) Output from Parser::parse() will now be wrapped in a div with
index 0d82d35..19c585d 100644 (file)
@@ -7431,15 +7431,6 @@ $wgSpecialPageCacheUpdates = [
        'Statistics' => [ 'SiteStatsUpdate', 'cacheUpdate' ]
 ];
 
-/**
- * Hooks that are used for outputting exceptions.  Format is:
- *   $wgExceptionHooks[] = $funcname
- * or:
- *   $wgExceptionHooks[] = [ $class, $funcname ]
- * Hooks should return strings or false
- */
-$wgExceptionHooks = [];
-
 /**
  * Page property link table invalidation lists. When a page property
  * changes, this may require other link tables to be updated (eg
index 4ff8636..8c1f8dc 100644 (file)
@@ -63,17 +63,6 @@ class MWException extends Exception {
                return $wgLang instanceof Language;
        }
 
-       /**
-        * Run hook to allow extensions to modify the text of the exception
-        *
-        * @param string $name Class name of the exception
-        * @param array $args Arguments to pass to the callback functions
-        * @return string|null String to output or null if any hook has been called
-        */
-       public function runHooks( $name, $args = [] ) {
-               return MWExceptionRenderer::runHooks( $this, $name, $args );
-       }
-
        /**
         * Get a message from i18n
         *
@@ -164,12 +153,7 @@ class MWException extends Exception {
                if ( $this->useOutputPage() ) {
                        $wgOut->prepareErrorPage( $this->getPageTitle() );
 
-                       $hookResult = $this->runHooks( static::class );
-                       if ( $hookResult ) {
-                               $wgOut->addHTML( $hookResult );
-                       } else {
-                               $wgOut->addHTML( $this->getHTML() );
-                       }
+                       $wgOut->addHTML( $this->getHTML() );
 
                        $wgOut->output();
                } else {
@@ -183,12 +167,7 @@ class MWException extends Exception {
                                '<style>body { font-family: sans-serif; margin: 0; padding: 0.5em 2em; }</style>' .
                                "</head><body>\n";
 
-                       $hookResult = $this->runHooks( static::class . 'Raw' );
-                       if ( $hookResult ) {
-                               echo $hookResult;
-                       } else {
-                               echo $this->getHTML();
-                       }
+                       echo $this->getHTML();
 
                        echo "</body></html>\n";
                }
index 435fde3..bd43934 100644 (file)
@@ -84,51 +84,6 @@ class MWExceptionRenderer {
                }
        }
 
-       /**
-        * Run hook to allow extensions to modify the text of the exception
-        *
-        * Called by MWException for b/c
-        *
-        * @param Exception|Throwable $e
-        * @param string $name Class name of the exception
-        * @param array $args Arguments to pass to the callback functions
-        * @return string|null String to output or null if any hook has been called
-        */
-       public static function runHooks( $e, $name, $args = [] ) {
-               global $wgExceptionHooks;
-
-               if ( !isset( $wgExceptionHooks ) || !is_array( $wgExceptionHooks ) ) {
-                       return null; // Just silently ignore
-               }
-
-               if ( !array_key_exists( $name, $wgExceptionHooks ) ||
-                       !is_array( $wgExceptionHooks[$name] )
-               ) {
-                       return null;
-               }
-
-               $hooks = $wgExceptionHooks[$name];
-               $callargs = array_merge( [ $e ], $args );
-
-               foreach ( $hooks as $hook ) {
-                       if (
-                               is_string( $hook ) ||
-                               ( is_array( $hook ) && count( $hook ) >= 2 && is_string( $hook[0] ) )
-                       ) {
-                               // 'function' or [ 'class', 'hook' ]
-                               $result = call_user_func_array( $hook, $callargs );
-                       } else {
-                               $result = null;
-                       }
-
-                       if ( is_string( $result ) ) {
-                               return $result;
-                       }
-               }
-
-               return null;
-       }
-
        /**
         * @param Exception|Throwable $e
         * @return bool Should the exception use $wgOut to output the error?
@@ -167,16 +122,11 @@ class MWExceptionRenderer {
                                $wgOut->prepareErrorPage( self::msg( 'internalerror', 'Internal error' ) );
                        }
 
-                       $hookResult = self::runHooks( $e, get_class( $e ) );
-                       if ( $hookResult ) {
-                               $wgOut->addHTML( $hookResult );
-                       } else {
-                               // Show any custom GUI message before the details
-                               if ( $e instanceof MessageSpecifier ) {
-                                       $wgOut->addHTML( Message::newFromSpecifier( $e )->escaped() );
-                               }
-                               $wgOut->addHTML( self::getHTML( $e ) );
+                       // Show any custom GUI message before the details
+                       if ( $e instanceof MessageSpecifier ) {
+                               $wgOut->addHTML( Message::newFromSpecifier( $e )->escaped() );
                        }
+                       $wgOut->addHTML( self::getHTML( $e ) );
 
                        $wgOut->output();
                } else {
@@ -191,12 +141,7 @@ class MWExceptionRenderer {
                                '<style>body { font-family: sans-serif; margin: 0; padding: 0.5em 2em; }</style>' .
                                "</head><body>\n";
 
-                       $hookResult = self::runHooks( $e, get_class( $e ) . 'Raw' );
-                       if ( $hookResult ) {
-                               echo $hookResult;
-                       } else {
-                               echo self::getHTML( $e );
-                       }
+                       echo self::getHTML( $e );
 
                        echo "</body></html>\n";
                }
index 7c36f7d..614a1c9 100644 (file)
@@ -75,53 +75,6 @@ class MWExceptionTest extends MediaWikiTestCase {
                $this->assertTrue( $e->isLoggable() );
        }
 
-       /**
-        * @dataProvider provideRunHooks
-        * @covers MWException::runHooks
-        */
-       public function testRunHooks( $wgExceptionHooks, $name, $args, $expectedReturn ) {
-               $this->setMwGlobals( [
-                       'wgExceptionHooks' => $wgExceptionHooks,
-               ] );
-               $e = new MWException();
-               $this->assertEquals( $expectedReturn, $e->runHooks( $name, $args ) );
-       }
-
-       public static function provideRunHooks() {
-               return [
-                       [ null, null, null, null ],
-                       [ [], 'name', [], null ],
-                       [ [ 'name' => false ], 'name', [], null ],
-                       [
-                               [ 'mockHook' => [ 'MWExceptionTest::mockHook' ] ],
-                               'mockHook', [], 'YAY.[]'
-                       ],
-                       [
-                               [ 'mockHook' => [ 'MWExceptionTest::mockHook' ] ],
-                               'mockHook', [ 'a' ], 'YAY.{"1":"a"}'
-                       ],
-                       [
-                               [ 'mockHook' => [ 'MWExceptionTest::mockHook' ] ],
-                               'mockHook', [ null ], null
-                       ],
-               ];
-       }
-
-       /**
-        * Used in conjunction with provideRunHooks and testRunHooks as a mock callback for a hook
-        */
-       public static function mockHook() {
-               $args = func_get_args();
-               if ( !$args[0] instanceof MWException ) {
-                       return '$caller not instance of MWException';
-               }
-               unset( $args[0] );
-               if ( array_key_exists( 1, $args ) && $args[1] === null ) {
-                       return null;
-               }
-               return 'YAY.' . json_encode( $args );
-       }
-
        /**
         * @dataProvider provideIsCommandLine
         * @covers MWException::isCommandLine