X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FHooks.php;h=785e71707c1a8625594e01a9cdd2d6b562047354;hb=b5993f884a3c4b0012fca120d3625452408c159d;hp=5d8a4a7c5737e372d0e2c5c728565ce73b232ff5;hpb=5d3dbc64aada672802b5316f293b36095555d1c7;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Hooks.php b/includes/Hooks.php index 5d8a4a7c57..785e71707c 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -53,7 +53,7 @@ class Hooks { * @since 1.18 */ public static function register( $name, $callback ) { - if( !isset( self::$handlers[$name] ) ) { + if ( !isset( self::$handlers[$name] ) ) { self::$handlers[$name] = array(); } @@ -124,12 +124,16 @@ class Hooks { * * @param string $event Event name * @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 + * processing to continue. Not returning a value (or explicitly + * returning null) is equivalent to returning true. * @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.) @@ -174,7 +178,7 @@ class Hooks { // Run autoloader (workaround for call_user_func_array bug) // and throw error if not callable. - if( !is_callable( $callback ) ) { + if ( !is_callable( $callback ) ) { throw new MWException( 'Invalid callback in hooks for ' . $event . "\n" ); } @@ -192,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 ); @@ -210,14 +223,7 @@ class Hooks { 'Detected bug in an extension! ' . "Hook $func has invalid call signature; " . $badhookmsg ); - } elseif ( $retval === null ) { - // Null was returned. Error. - throw new MWException( - 'Detected bug in an extension! ' . - "Hook $func failed to return a value; " . - 'should return true to continue hook processing or false to abort.' - ); - } elseif ( !$retval ) { + } elseif ( $retval === false ) { wfProfileOut( 'hook: ' . $event ); // False was returned. Stop processing, but no error. return false;