From f97da7df26fc99a8d7eb14f65b378b7560511ebf Mon Sep 17 00:00:00 2001 From: daniel Date: Fri, 4 Nov 2022 12:22:09 +0100 Subject: [PATCH] Use HookContainer to register hooks on the fly. Manipulating $wgHooks is deprecated and unreliable. Use HookContainer instead. Needed-By: Iddcb760cf8961316d6527e81b9aa968657d8354c Change-Id: I413cd2ae43fe4b13917d61a50e190b536fce7279 --- includes/ParserFunctions.php | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/includes/ParserFunctions.php b/includes/ParserFunctions.php index b8f0a93c..cb7d5771 100644 --- a/includes/ParserFunctions.php +++ b/includes/ParserFunctions.php @@ -30,22 +30,6 @@ class ParserFunctions { /** ~10 seconds */ private const MAX_TIME_CHARS = 6000; - /** - * Register ParserClearState hook. - * We defer this until needed to avoid the loading of the code of this file - * when no parser function is actually called. - */ - private static function registerClearHook() { - static $done = false; - if ( !$done ) { - global $wgHooks; - $wgHooks['ParserClearState'][] = static function () { - self::$mTimeChars = 0; - }; - $done = true; - } - } - /** * @return ExprParser */ @@ -431,7 +415,14 @@ class ParserFunctions { Parser $parser, PPFrame $frame, $format, $date, $language, $local ) { global $wgLocaltimezone; - self::registerClearHook(); + + MediaWikiServices::getInstance()->getHookContainer()->register( + 'ParserClearState', + static function () { + self::$mTimeChars = 0; + } + ); + if ( $date === '' ) { $cacheKey = $parser->getOptions()->getTimestamp(); $timestamp = new MWTimestamp( $cacheKey );