Remove $allowMissing and make the check directly on the hook

This change avoids a super category expand button on not existing
categories.

This change even avoids loading the modules if there are no valid
categories.

Change-Id: I38a2b49aaef7cf46d9f89e1cc9fd65e2382155f5
This commit is contained in:
Fomafix 2024-08-29 10:57:07 +00:00
parent b1e3b5f06d
commit a918bdea16
2 changed files with 9 additions and 8 deletions

View file

@ -78,11 +78,10 @@ class CategoryTree {
* @param bool $hideroot
* @param array $attr
* @param int $depth
* @param bool $allowMissing
* @return bool|string
*/
public function getTag( ?Parser $parser, string $category, bool $hideroot = false, array $attr = [],
int $depth = 1, bool $allowMissing = false
int $depth = 1
) {
$disableCache = $this->config->get( 'CategoryTreeDisableCache' );
@ -114,7 +113,7 @@ class CategoryTree {
$attr['data-ct-mode'] = $this->optionManager->getOption( 'mode' );
$attr['data-ct-options'] = $this->optionManager->getOptionsAsJsStructure();
if ( !$allowMissing && !$title->getArticleID() ) {
if ( !$title->getArticleID() ) {
$html = Html::rawElement( 'span', [ 'class' => 'CategoryTreeNotice' ],
wfMessage( 'categorytree-not-found' )
->plaintextParams( $category )

View file

@ -185,15 +185,13 @@ class Hooks implements
* @param array $argv
* @param Parser|null $parser
* @param PPFrame|null $frame
* @param bool $allowMissing
* @return bool|string
*/
public function parserHook(
$cat,
array $argv,
Parser $parser = null,
PPFrame $frame = null,
$allowMissing = false
PPFrame $frame = null
) {
if ( $parser ) {
$parserOutput = $parser->getOutput();
@ -226,7 +224,7 @@ class Hooks implements
}
return $message .
$ct->getTag( $parser, $cat, $hideroot, $attr, $depth, $allowMissing );
$ct->getTag( $parser, $cat, $hideroot, $attr, $depth );
}
/**
@ -247,13 +245,17 @@ class Hooks implements
// Not enabled, don't do anything
return;
}
if ( !$categoryTitle->exists() ) {
// Category doesn't exist. Let the normal LinkRenderer generate the link.
return;
}
CategoryTree::setHeaders( $out );
$options = $this->config->get( 'CategoryTreePageCategoryOptions' );
$link = $this->parserHook(
$this->titleFormatter->getPrefixedText( $categoryTitle ),
$options, null, null, true
$options
);
}