Add a way to exclude categories from Special:UnusedCategories

Added __EXPECT_UNUSED_CATEGORY__ as a behavioral switch. Adding
this switch to category pages prevents them from appearing in
Special:UnusedCategories.

Bug: T96041
Change-Id: I055e59f5311347155e0f801dd5ec9a6d4a68c9cc
This commit is contained in:
Agabi10 2018-09-07 21:32:26 +00:00
parent 68ce51d68f
commit 4985ce5134
6 changed files with 71 additions and 4 deletions

View file

@ -30,6 +30,8 @@ production.
=== New features in 1.33 ===
* The 'GetPreferences' hook now receives an additional $context parameter.
* (T96041) __EXPECT_UNUSED_CATEGORY__ on a category page causes the category
to be hidden on Special:UnusedCategories.
* …
=== External library changes in 1.33 ===

View file

@ -173,6 +173,7 @@ class MagicWordFactory {
'newsectionlink',
'nonewsectionlink',
'hiddencat',
'expectunusedcategory',
'index',
'noindex',
'staticredirect',

View file

@ -59,6 +59,20 @@ class WikiCategoryPage extends WikiPage {
$pageId = $this->getTitle()->getArticleID();
$pageProps = PageProps::getInstance()->getProperties( $this->getTitle(), 'hiddencat' );
return isset( $pageProps[$pageId] ) ? true : false;
return isset( $pageProps[$pageId] );
}
/**
* Checks if a category is expected to be an unused category.
*
* @since 1.33
*
* @return bool
*/
public function isExpectedUnusedCategory() {
$pageId = $this->getTitle()->getArticleID();
$pageProps = PageProps::getInstance()->getProperties( $this->getTitle(), 'expectunusedcategory' );
return isset( $pageProps[$pageId] );
}
}

View file

@ -39,7 +39,7 @@ class UnusedCategoriesPage extends QueryPage {
public function getQueryInfo() {
return [
'tables' => [ 'page', 'categorylinks' ],
'tables' => [ 'page', 'categorylinks', 'page_props' ],
'fields' => [
'namespace' => 'page_namespace',
'title' => 'page_title',
@ -48,9 +48,16 @@ class UnusedCategoriesPage extends QueryPage {
'conds' => [
'cl_from IS NULL',
'page_namespace' => NS_CATEGORY,
'page_is_redirect' => 0
'page_is_redirect' => 0,
'pp_page IS NULL'
],
'join_conds' => [ 'categorylinks' => [ 'LEFT JOIN', 'cl_to = page_title' ] ]
'join_conds' => [
'categorylinks' => [ 'LEFT JOIN', 'cl_to = page_title' ],
'page_props' => [ 'LEFT JOIN', [
'page_id = pp_page',
'pp_propname' => 'expectunusedcategory'
] ]
]
];
}

View file

@ -359,6 +359,7 @@ $magicWords = [
'filepath' => [ 0, 'FILEPATH:' ],
'tag' => [ 0, 'tag' ],
'hiddencat' => [ 1, '__HIDDENCAT__' ],
'expectunusedcategory' => [ 1, '__EXPECT_UNUSED_CATEGORY__', '__EXPECT_UNUSED_CAT__', '__EXPECTUNUSEDCATEGORY__', '__EXPECTUNUSEDCAT__' ],
'pagesincategory' => [ 1, 'PAGESINCATEGORY', 'PAGESINCAT' ],
'pagesize' => [ 1, 'PAGESIZE' ],
'index' => [ 1, '__INDEX__' ],

View file

@ -60,4 +60,46 @@ class WikiCategoryPageTest extends MediaWikiLangTestCase {
ScopedCallback::consume( $scopedOverride );
}
/**
* @covers WikiCategoryPage::isExpectedUnusedCategory
*/
public function testExpectUnusedCategory_PropertyNotSet() {
$title = Title::makeTitle( NS_CATEGORY, 'CategoryPage' );
$categoryPage = WikiCategoryPage::factory( $title );
$pageProps = $this->getMockPageProps();
$pageProps->expects( $this->once() )
->method( 'getProperties' )
->with( $title, 'expectunusedcategory' )
->will( $this->returnValue( [] ) );
$scopedOverride = PageProps::overrideInstance( $pageProps );
$this->assertFalse( $categoryPage->isExpectedUnusedCategory() );
ScopedCallback::consume( $scopedOverride );
}
/**
* @dataProvider provideCategoryContent
* @covers WikiCategoryPage::isExpectedUnusedCategory
*/
public function testExpectUnusedCategory_PropertyIsSet( $isExpectedUnusedCategory ) {
$categoryTitle = Title::makeTitle( NS_CATEGORY, 'CategoryPage' );
$categoryPage = WikiCategoryPage::factory( $categoryTitle );
$returnValue = $isExpectedUnusedCategory ? [ $categoryTitle->getArticleID() => '' ] : [];
$pageProps = $this->getMockPageProps();
$pageProps->expects( $this->once() )
->method( 'getProperties' )
->with( $categoryTitle, 'expectunusedcategory' )
->will( $this->returnValue( $returnValue ) );
$scopedOverride = PageProps::overrideInstance( $pageProps );
$this->assertEquals( $isExpectedUnusedCategory, $categoryPage->isExpectedUnusedCategory() );
ScopedCallback::consume( $scopedOverride );
}
}