Merge "1.24 -> 1.25"
[lhc/web/wiklou.git] / includes / Hooks.php
index db47d31..668c3d9 100644 (file)
@@ -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.)
@@ -178,7 +179,7 @@ class Hooks {
                        // Run autoloader (workaround for call_user_func_array bug)
                        // and throw error if not callable.
                        if ( !is_callable( $callback ) ) {
-                               throw new MWException( 'Invalid callback in hooks for ' . $event . "\n" );
+                               throw new MWException( 'Invalid callback ' . $func . ' in hooks for ' . $event . "\n" );
                        }
 
                        /*
@@ -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 ) {