* $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
'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
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
*
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 {
'<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";
}
}
}
- /**
- * 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?
$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 {
'<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";
}
$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