mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CategoryTree
synced 2024-11-27 09:43:06 +00:00
Optimize PHP code semantic
* Mark $mOptions as private. There is no external reference. * CategoryTree::makeTitle don't return false. A check for false is not needed. * A class attribute should not start with a space. * $title->isExternal() is equivalent to $title->getInterwiki() !== ''. * Use $title->inNamespace( NS_CATEGORY ) instead of $title->getNamespace() === NS_CATEGORY. Change-Id: Iddad84ff5a18080d1216346ec2a906c955a644a4
This commit is contained in:
parent
ba6e585427
commit
828566ef60
|
@ -45,7 +45,7 @@ use Title;
|
|||
*/
|
||||
class CategoryTree {
|
||||
/** @var array */
|
||||
public $mOptions = [];
|
||||
private $mOptions = [];
|
||||
|
||||
/** @var LinkRenderer */
|
||||
private $linkRenderer;
|
||||
|
@ -357,14 +357,14 @@ class CategoryTree {
|
|||
|
||||
$title = self::makeTitle( $category );
|
||||
|
||||
if ( $title === false || $title === null ) {
|
||||
if ( $title === null ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( isset( $attr['class'] ) ) {
|
||||
$attr['class'] .= ' CategoryTreeTag';
|
||||
} else {
|
||||
$attr['class'] = ' CategoryTreeTag';
|
||||
$attr['class'] = 'CategoryTreeTag';
|
||||
}
|
||||
|
||||
$attr['data-ct-mode'] = $this->mOptions['mode'];
|
||||
|
@ -397,7 +397,7 @@ class CategoryTree {
|
|||
public function renderChildren( Title $title, $depth = 1 ) {
|
||||
global $wgCategoryTreeMaxChildren, $wgCategoryTreeUseCategoryTable;
|
||||
|
||||
if ( $title->getNamespace() !== NS_CATEGORY ) {
|
||||
if ( !$title->inNamespace( NS_CATEGORY ) ) {
|
||||
// Non-categories can't have children. :)
|
||||
return '';
|
||||
}
|
||||
|
@ -565,7 +565,7 @@ class CategoryTree {
|
|||
public function renderNode( Title $title, $children = 0 ) {
|
||||
global $wgCategoryTreeUseCategoryTable;
|
||||
|
||||
if ( $wgCategoryTreeUseCategoryTable && $title->getNamespace() === NS_CATEGORY
|
||||
if ( $wgCategoryTreeUseCategoryTable && $title->inNamespace( NS_CATEGORY )
|
||||
&& !$this->isInverse()
|
||||
) {
|
||||
$cat = Category::newFromTitle( $title );
|
||||
|
@ -587,7 +587,7 @@ class CategoryTree {
|
|||
public function renderNodeInfo( Title $title, Category $cat = null, $children = 0 ) {
|
||||
$mode = $this->getOption( 'mode' );
|
||||
|
||||
$ns = $title->getNamespace();
|
||||
$isInCatNS = $title->inNamespace( NS_CATEGORY );
|
||||
$key = $title->getDBkey();
|
||||
|
||||
$hideprefix = $this->getOption( 'hideprefix' );
|
||||
|
@ -597,7 +597,7 @@ class CategoryTree {
|
|||
} elseif ( $hideprefix === CategoryTreeHidePrefix::AUTO ) {
|
||||
$hideprefix = ( $mode === CategoryTreeMode::CATEGORIES );
|
||||
} elseif ( $hideprefix === CategoryTreeHidePrefix::CATEGORIES ) {
|
||||
$hideprefix = ( $ns === NS_CATEGORY );
|
||||
$hideprefix = $isInCatNS;
|
||||
} else {
|
||||
$hideprefix = true;
|
||||
}
|
||||
|
@ -625,7 +625,7 @@ class CategoryTree {
|
|||
|
||||
$attr = [ 'class' => 'CategoryTreeBullet' ];
|
||||
|
||||
if ( $ns === NS_CATEGORY ) {
|
||||
if ( $isInCatNS ) {
|
||||
if ( $cat ) {
|
||||
if ( $mode === CategoryTreeMode::CATEGORIES ) {
|
||||
$count = $cat->getSubcatCount();
|
||||
|
@ -674,7 +674,7 @@ class CategoryTree {
|
|||
]
|
||||
);
|
||||
|
||||
if ( $ns === NS_CATEGORY && $children > 0 ) {
|
||||
if ( $isInCatNS && $children > 0 ) {
|
||||
$children = $this->renderChildren( $title, $children );
|
||||
if ( $children === '' ) {
|
||||
switch ( $mode ) {
|
||||
|
@ -773,7 +773,7 @@ class CategoryTree {
|
|||
# The title must be in the category namespace
|
||||
# Ignore a leading Category: if there is one
|
||||
$t = Title::newFromText( $title, NS_CATEGORY );
|
||||
if ( !$t || $t->getNamespace() !== NS_CATEGORY || $t->getInterwiki() !== '' ) {
|
||||
if ( !$t || !$t->inNamespace( NS_CATEGORY ) || $t->isExternal() ) {
|
||||
// If we were given something like "Wikipedia:Foo" or "Template:",
|
||||
// try it again but forced.
|
||||
$title = "Category:$title";
|
||||
|
|
|
@ -213,7 +213,7 @@ class CategoryTreePage extends SpecialPage {
|
|||
*/
|
||||
public function prefixSearchSubpages( $search, $limit, $offset ) {
|
||||
$title = Title::newFromText( $search, NS_CATEGORY );
|
||||
if ( $title && $title->getNamespace() !== NS_CATEGORY ) {
|
||||
if ( $title && !$title->inNamespace( NS_CATEGORY ) ) {
|
||||
// Someone searching for something like "Wikipedia:Foo"
|
||||
$title = Title::makeTitleSafe( NS_CATEGORY, $search );
|
||||
}
|
||||
|
|
|
@ -235,7 +235,7 @@ class Hooks implements
|
|||
* @return bool|void True or no return value to continue or false to abort
|
||||
*/
|
||||
public function onArticleFromTitle( $title, &$article, $context ) {
|
||||
if ( $title->getNamespace() === NS_CATEGORY ) {
|
||||
if ( $title->inNamespace( NS_CATEGORY ) ) {
|
||||
$article = new CategoryTreeCategoryPage( $title );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue