Merge "Move all Parser handling to Hooks::parserHook"

This commit is contained in:
jenkins-bot 2024-10-10 16:45:06 +00:00 committed by Gerrit Code Review
commit 4d2836760f
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 );
}
/**