diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2014-12-27 15:41:37 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2014-12-31 11:43:28 +0100 |
commit | c1f9b1f7b1b77776192048005dcc66dcf3df2bfb (patch) | |
tree | 2b38796e738dd74cb42ecd9bfd151803108386bc /includes/Hooks.php | |
parent | b88ab0086858470dd1f644e64cb4e4f62bb2be9b (diff) |
Update to MediaWiki 1.24.1
Diffstat (limited to 'includes/Hooks.php')
-rw-r--r-- | includes/Hooks.php | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/includes/Hooks.php b/includes/Hooks.php index 396e360d..29287483 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -27,7 +27,8 @@ /** * @since 1.18 */ -class MWHookException extends MWException {} +class MWHookException extends MWException { +} /** * Hooks class. @@ -37,7 +38,6 @@ class MWHookException extends MWException {} * @since 1.18 */ class Hooks { - /** * Array of events mapped to an array of callbacks to be run * when that event is triggered. @@ -48,7 +48,7 @@ class Hooks { * Attach an event handler to a given hook. * * @param string $name Name of hook - * @param mixed $callback Callback function to attach + * @param callable $callback Callback function to attach * * @since 1.18 */ @@ -64,10 +64,10 @@ class Hooks { * Clears hooks registered via Hooks::register(). Does not touch $wgHooks. * This is intended for use while testing and will fail if MW_PHPUNIT_TEST is not defined. * - * @param string $name the name of the hook to clear. + * @param string $name The name of the hook to clear. * * @since 1.21 - * @throws MWException if not in testing mode. + * @throws MWException If not in testing mode. */ public static function clear( $name ) { if ( !defined( 'MW_PHPUNIT_TEST' ) ) { @@ -123,7 +123,8 @@ class Hooks { * Finally, process the return value and return/throw accordingly. * * @param string $event Event name - * @param array $args Array of parameters passed to hook functions + * @param array $args Array of parameters passed to hook functions + * @param string|null $deprecatedVersion Optionally, mark hook as deprecated with version number * @return bool True if no handler aborted the hook * * @since 1.22 A hook function is not required to return a value for @@ -132,7 +133,7 @@ class Hooks { * @throws MWException * @throws FatalError */ - public static function run( $event, array $args = array() ) { + public static function run( $event, array $args = array(), $deprecatedVersion = null ) { wfProfileIn( 'hook: ' . $event ); foreach ( self::getHandlers( $event ) as $hook ) { // Turn non-array values into an array. (Can't use casting because of objects.) @@ -195,10 +196,19 @@ class Hooks { // Profile first in case the Profiler causes errors. wfProfileIn( $func ); set_error_handler( 'Hooks::hookErrorHandler' ); + + // mark hook as deprecated, if deprecation version is specified + if ( $deprecatedVersion !== null ) { + wfDeprecated( "$event hook (used in $func)", $deprecatedVersion ); + } + try { $retval = call_user_func_array( $callback, $hook_args ); } catch ( MWHookException $e ) { $badhookmsg = $e->getMessage(); + } catch ( Exception $e ) { + restore_error_handler(); + throw $e; } restore_error_handler(); wfProfileOut( $func ); |