CategoryTreePage: Refactor category tree to own method

Use an early return path for not found category.

Change-Id: I49275941ca45b678c5b325966c52c28cb0630d49
This commit is contained in:
Fomafix 2021-09-01 06:58:51 +00:00 committed by Krinkle
parent 509745aaaa
commit 031e5bf358

View file

@ -103,43 +103,12 @@ class CategoryTreePage extends SpecialPage {
$this->tree = new CategoryTree( $options );
$output = $this->getOutput();
$output->addWikiMsg( 'categorytree-header' );
$this->getOutput()->addWikiMsg( 'categorytree-header' );
$this->executeInputForm();
if ( $this->target !== '' ) {
CategoryTree::setHeaders( $output );
$title = CategoryTree::makeTitle( $this->target );
if ( $title && $title->getArticleID() ) {
$parents = $this->tree->renderParents( $title );
if ( $parents == '' ) {
$parents = $this->msg( 'categorytree-no-parent-categories' )->parse();
}
$output->addHTML( Html::rawElement( 'div', [ 'class' => 'CategoryTreeParents' ],
$this->msg( 'categorytree-parents' )->parse() .
$this->msg( 'colon-separator' )->escaped() .
$parents
) );
$output->addHTML( Html::rawElement( 'div',
[
'class' => 'CategoryTreeResult CategoryTreeTag',
'data-ct-mode' => $this->tree->getOption( 'mode' ),
'data-ct-options' => $this->tree->getOptionsAsJsStructure(),
],
$this->tree->renderNode( $title, 1 )
) );
} else {
$output->addHTML( Html::rawElement( 'div', [ 'class' => 'CategoryTreeNotice' ],
$this->msg( 'categorytree-not-found' )
->plaintextParams( $this->target )
->parse()
) );
}
$this->executeCategoryTree();
}
}
@ -196,6 +165,44 @@ class CategoryTreePage extends SpecialPage {
->displayForm( false );
}
/**
* Show the category tree
*/
private function executeCategoryTree() {
$output = $this->getOutput();
CategoryTree::setHeaders( $output );
$title = CategoryTree::makeTitle( $this->target );
if ( !$title || !$title->getArticleID() ) {
$output->addHTML( Html::rawElement( 'div', [ 'class' => 'CategoryTreeNotice' ],
$this->msg( 'categorytree-not-found' )
->plaintextParams( $this->target )
->parse()
) );
return;
}
$parents = $this->tree->renderParents( $title );
if ( $parents == '' ) {
$parents = $this->msg( 'categorytree-no-parent-categories' )->parse();
}
$output->addHTML( Html::rawElement( 'div', [ 'class' => 'CategoryTreeParents' ],
$this->msg( 'categorytree-parents' )->parse() .
$this->msg( 'colon-separator' )->escaped() .
$parents
) );
$output->addHTML( Html::rawElement( 'div',
[
'class' => 'CategoryTreeResult CategoryTreeTag',
'data-ct-mode' => $this->tree->getOption( 'mode' ),
'data-ct-options' => $this->tree->getOptionsAsJsStructure(),
],
$this->tree->renderNode( $title, 1 )
) );
}
/**
* Return an array of subpages beginning with $search that this special page will accept.
*