From 5963aa7ed7a2c097acae3c3673336c71294bc333 Mon Sep 17 00:00:00 2001 From: aude Date: Wed, 8 Jan 2014 22:32:21 +0100 Subject: [PATCH] Add ability to mark hooks as deprecated Change-Id: I8fd29e97a2b5d02746b572a9c315fbe54faf36f2 --- RELEASE-NOTES-1.23 | 1 + includes/GlobalFunctions.php | 6 ++++-- includes/Hooks.php | 9 ++++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/RELEASE-NOTES-1.23 b/RELEASE-NOTES-1.23 index e017a629ea..a05d7a2cc1 100644 --- a/RELEASE-NOTES-1.23 +++ b/RELEASE-NOTES-1.23 @@ -163,6 +163,7 @@ changes to languages because of Bugzilla reports. ** Several array keys have been renamed: hideMinor → hideminor, hideBots → hidebots, hideAnons → hideanons, hideLiu → hideliu, hidePatrolled → hidepatrolled, hideOwn → hidemyself. +* Option to mark hooks as deprecated has been added. ==== Removed classes ==== * TitleDependency (unused) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 3250ec835c..a638287966 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -4026,10 +4026,12 @@ function wfGetLangConverterCacheStorage() { * * @param string $event event name * @param array $args parameters passed to hook functions + * @param string|null $deprecatedVersion optionally mark hook as deprecated with version number + * * @return Boolean True if no handler aborted the hook */ -function wfRunHooks( $event, array $args = array() ) { - return Hooks::run( $event, $args ); +function wfRunHooks( $event, array $args = array(), $deprecatedVersion = null ) { + return Hooks::run( $event, $args, $deprecatedVersion ); } /** diff --git a/includes/Hooks.php b/includes/Hooks.php index db47d3194e..785e71707c 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -124,6 +124,7 @@ 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 @@ -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,6 +196,12 @@ 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 ) { -- 2.20.1