From 921e6fe3f947a3c034e358a471fa497e58c4ba04 Mon Sep 17 00:00:00 2001 From: Fomafix Date: Fri, 30 Aug 2024 16:17:38 +0000 Subject: [PATCH] Move all Parser handling to Hooks::parserHook Change-Id: I5d35c6d87b610ffb566588a3d0c75067c1d06962 --- includes/CategoryTree.php | 14 +------------- includes/Hooks.php | 9 ++++++++- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/includes/CategoryTree.php b/includes/CategoryTree.php index 07e9a09f..0c9188b6 100644 --- a/includes/CategoryTree.php +++ b/includes/CategoryTree.php @@ -33,7 +33,6 @@ use MediaWiki\Html\Html; use MediaWiki\Linker\LinkRenderer; use MediaWiki\MediaWikiServices; use MediaWiki\Output\OutputPage; -use MediaWiki\Parser\Parser; use MediaWiki\Registration\ExtensionRegistry; use MediaWiki\SpecialPage\SpecialPage; use MediaWiki\Title\Title; @@ -73,31 +72,20 @@ class CategoryTree { /** * Custom tag implementation. This is called by Hooks::parserHook, which is used to * load CategoryTreeFunctions.php on demand. - * @param ?Parser $parser * @param string $category * @param bool $hideroot * @param array $attr * @param int $depth * @return bool|string */ - public function getTag( ?Parser $parser, string $category, bool $hideroot = false, array $attr = [], + public function getTag( string $category, bool $hideroot = false, array $attr = [], int $depth = 1 ) { - $disableCache = $this->config->get( 'CategoryTreeDisableCache' ); - $category = trim( $category ); if ( $category === '' ) { return false; } - if ( $parser ) { - if ( $disableCache === true ) { - $parser->getOutput()->updateCacheExpiry( 0 ); - } elseif ( is_int( $disableCache ) ) { - $parser->getOutput()->updateCacheExpiry( $disableCache ); - } - } - $title = self::makeTitle( $category ); if ( $title === null ) { diff --git a/includes/Hooks.php b/includes/Hooks.php index b880109a..4f030d20 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -197,6 +197,13 @@ class Hooks implements $parserOutput = $parser->getOutput(); $parserOutput->addModuleStyles( [ 'ext.categoryTree.styles' ] ); $parserOutput->addModules( [ 'ext.categoryTree' ] ); + + $disableCache = $this->config->get( 'CategoryTreeDisableCache' ); + if ( $disableCache === true ) { + $parserOutput->updateCacheExpiry( 0 ); + } elseif ( is_int( $disableCache ) ) { + $parserOutput->updateCacheExpiry( $disableCache ); + } } $ct = new CategoryTree( $argv, $this->config, $this->dbProvider, $this->linkRenderer ); @@ -224,7 +231,7 @@ class Hooks implements } return $message . - $ct->getTag( $parser, $cat, $hideroot, $attr, $depth ); + $ct->getTag( $cat, $hideroot, $attr, $depth ); } /**