Use HookContainer to register hooks on the fly.

Manipulating $wgHooks is deprecated and unreliable.
Use HookContainer instead.

Needed-By: Iddcb760cf8961316d6527e81b9aa968657d8354c
Change-Id: I413cd2ae43fe4b13917d61a50e190b536fce7279
This commit is contained in:
daniel 2022-11-04 12:22:09 +01:00 committed by Daniel Kinzler
parent ee66f0bfff
commit f97da7df26

View file

@ -30,22 +30,6 @@ class ParserFunctions {
/** ~10 seconds */ /** ~10 seconds */
private const MAX_TIME_CHARS = 6000; 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 * @return ExprParser
*/ */
@ -431,7 +415,14 @@ class ParserFunctions {
Parser $parser, PPFrame $frame, $format, $date, $language, $local Parser $parser, PPFrame $frame, $format, $date, $language, $local
) { ) {
global $wgLocaltimezone; global $wgLocaltimezone;
self::registerClearHook();
MediaWikiServices::getInstance()->getHookContainer()->register(
'ParserClearState',
static function () {
self::$mTimeChars = 0;
}
);
if ( $date === '' ) { if ( $date === '' ) {
$cacheKey = $parser->getOptions()->getTimestamp(); $cacheKey = $parser->getOptions()->getTimestamp();
$timestamp = new MWTimestamp( $cacheKey ); $timestamp = new MWTimestamp( $cacheKey );