Move all Parser handling to Hooks::parserHook

Change-Id: I5d35c6d87b610ffb566588a3d0c75067c1d06962
This commit is contained in:
Fomafix 2024-08-30 16:17:38 +00:00
parent a918bdea16
commit 921e6fe3f9
2 changed files with 9 additions and 14 deletions

View file

@ -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 ) {

View file

@ -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 );
}
/**