Merge "Remove $allowMissing and make the check directly on the hook"

This commit is contained in:
jenkins-bot 2024-10-10 16:01:18 +00:00 committed by Gerrit Code Review
commit ee0a3f1aab
2 changed files with 9 additions and 8 deletions

View file

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

View file

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