From: Kunal Mehta Date: Wed, 17 Aug 2016 05:53:16 +0000 (-0700) Subject: Allow marking legacy ContentHandler hooks as deprecated X-Git-Tag: 1.31.0-rc.0~6007 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/ajouter.php?a=commitdiff_plain;h=4b5c1745ec7405f24de4aea88cbdeb7c9dd29ea7;p=lhc%2Fweb%2Fwiklou.git Allow marking legacy ContentHandler hooks as deprecated Instead of having a single development flag that controls whether all the hooks emit warnings, use the standard hook deprecation method to mark individual hooks as deprecated once we have determined that their usage is minimal. Change-Id: I9a00ae131cb7f609c1d44926d1f6547089f70c34 --- diff --git a/includes/content/ContentHandler.php b/includes/content/ContentHandler.php index 7184980ede..5a5c0d8eec 100644 --- a/includes/content/ContentHandler.php +++ b/includes/content/ContentHandler.php @@ -1156,62 +1156,19 @@ abstract class ContentHandler { * * @param string $event Event name * @param array $args Parameters passed to hook functions - * @param bool $warn Whether to log a warning. - * Default to self::$enableDeprecationWarnings. - * May be set to false for testing. + * @param string|null $deprecatedVersion Emit a deprecation notice + * when the hook is run for the provided version * * @return bool True if no handler aborted the hook - * - * @see ContentHandler::$enableDeprecationWarnings */ public static function runLegacyHooks( $event, $args = [], - $warn = null + $deprecatedVersion = null ) { - if ( $warn === null ) { - $warn = self::$enableDeprecationWarnings; - } - if ( !Hooks::isRegistered( $event ) ) { return true; // nothing to do here } - if ( $warn ) { - // Log information about which handlers are registered for the legacy hook, - // so we can find and fix them. - - $handlers = Hooks::getHandlers( $event ); - $handlerInfo = []; - - MediaWiki\suppressWarnings(); - - foreach ( $handlers as $handler ) { - if ( is_array( $handler ) ) { - if ( is_object( $handler[0] ) ) { - $info = get_class( $handler[0] ); - } else { - $info = $handler[0]; - } - - if ( isset( $handler[1] ) ) { - $info .= '::' . $handler[1]; - } - } elseif ( is_object( $handler ) ) { - $info = get_class( $handler[0] ); - $info .= '::on' . $event; - } else { - $info = $handler; - } - - $handlerInfo[] = $info; - } - - MediaWiki\restoreWarnings(); - - wfWarn( "Using obsolete hook $event via ContentHandler::runLegacyHooks()! Handlers: " . - implode( ', ', $handlerInfo ), 2 ); - } - // convert Content objects to text $contentObjects = []; $contentTexts = []; @@ -1229,7 +1186,7 @@ abstract class ContentHandler { } // call the hook functions - $ok = Hooks::run( $event, $args ); + $ok = Hooks::run( $event, $args, $deprecatedVersion ); // see if the hook changed the text foreach ( $contentTexts as $k => $orig ) { diff --git a/tests/phpunit/includes/content/ContentHandlerTest.php b/tests/phpunit/includes/content/ContentHandlerTest.php index bb9050fbd3..6168182c14 100644 --- a/tests/phpunit/includes/content/ContentHandlerTest.php +++ b/tests/phpunit/includes/content/ContentHandlerTest.php @@ -376,8 +376,7 @@ class ContentHandlerTest extends MediaWikiTestCase { $content = new WikitextContent( 'test text' ); $ok = ContentHandler::runLegacyHooks( 'testRunLegacyHooks', - [ 'foo', &$content, 'bar' ], - false + [ 'foo', &$content, 'bar' ] ); $this->assertTrue( $ok, "runLegacyHooks should have returned true" );