From: Gergő Tisza Date: Sun, 21 May 2017 08:29:41 +0000 (+0200) Subject: Remove $wgExceptionHooks X-Git-Tag: 1.31.0-rc.0~3189^2 X-Git-Url: http://git.cyclocoop.org/%22%2C%20generer_url_ecrire%28?a=commitdiff_plain;h=fcd495ffef437c3e48c062d6e067166af23dec1f;p=lhc%2Fweb%2Fwiklou.git Remove $wgExceptionHooks Skip deprecation period because it is very unlikely that anyone used this: it does not appear anywhere on gerrit/git, no nontrivial google hits, the documentation has been flat out wrong for 9 years and no one noticed it, and the whole feature is fairly useless as you need to declare it separately for every single exception class you expect. Change-Id: I85844a238d3135d05eeba10331149624b04bafe2 --- diff --git a/RELEASE-NOTES-1.30 b/RELEASE-NOTES-1.30 index 03ae7c2062..4e25532dc0 100644 --- a/RELEASE-NOTES-1.30 +++ b/RELEASE-NOTES-1.30 @@ -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 diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 0d82d35c98..19c585d14c 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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 diff --git a/includes/exception/MWException.php b/includes/exception/MWException.php index 4ff8636e2e..8c1f8dc968 100644 --- a/includes/exception/MWException.php +++ b/includes/exception/MWException.php @@ -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 { '' . "\n"; - $hookResult = $this->runHooks( static::class . 'Raw' ); - if ( $hookResult ) { - echo $hookResult; - } else { - echo $this->getHTML(); - } + echo $this->getHTML(); echo "\n"; } diff --git a/includes/exception/MWExceptionRenderer.php b/includes/exception/MWExceptionRenderer.php index 435fde3427..bd4393445b 100644 --- a/includes/exception/MWExceptionRenderer.php +++ b/includes/exception/MWExceptionRenderer.php @@ -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 { '' . "\n"; - $hookResult = self::runHooks( $e, get_class( $e ) . 'Raw' ); - if ( $hookResult ) { - echo $hookResult; - } else { - echo self::getHTML( $e ); - } + echo self::getHTML( $e ); echo "\n"; } diff --git a/tests/phpunit/includes/exception/MWExceptionTest.php b/tests/phpunit/includes/exception/MWExceptionTest.php index 7c36f7d13d..614a1c981d 100644 --- a/tests/phpunit/includes/exception/MWExceptionTest.php +++ b/tests/phpunit/includes/exception/MWExceptionTest.php @@ -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