From: Agabi10 Date: Fri, 7 Sep 2018 21:32:26 +0000 (+0000) Subject: Add a way to exclude categories from Special:UnusedCategories X-Git-Tag: 1.34.0-rc.0~3500^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/ajouter.php?a=commitdiff_plain;h=4985ce513469fa82a132139a41c2854504475e4a;p=lhc%2Fweb%2Fwiklou.git 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 --- diff --git a/RELEASE-NOTES-1.33 b/RELEASE-NOTES-1.33 index c573a5951c..df6b5f8214 100644 --- a/RELEASE-NOTES-1.33 +++ b/RELEASE-NOTES-1.33 @@ -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 === diff --git a/includes/MagicWordFactory.php b/includes/MagicWordFactory.php index e62716d67e..4e9bfaf1f7 100644 --- a/includes/MagicWordFactory.php +++ b/includes/MagicWordFactory.php @@ -173,6 +173,7 @@ class MagicWordFactory { 'newsectionlink', 'nonewsectionlink', 'hiddencat', + 'expectunusedcategory', 'index', 'noindex', 'staticredirect', diff --git a/includes/page/WikiCategoryPage.php b/includes/page/WikiCategoryPage.php index 6c932029ae..2837573998 100644 --- a/includes/page/WikiCategoryPage.php +++ b/includes/page/WikiCategoryPage.php @@ -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] ); } } diff --git a/includes/specials/SpecialUnusedcategories.php b/includes/specials/SpecialUnusedcategories.php index 1469742a4b..2577a100cf 100644 --- a/includes/specials/SpecialUnusedcategories.php +++ b/includes/specials/SpecialUnusedcategories.php @@ -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' + ] ] + ] ]; } diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 587f6ea4ad..b5e2c5eaa7 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -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__' ], diff --git a/tests/phpunit/includes/page/WikiCategoryPageTest.php b/tests/phpunit/includes/page/WikiCategoryPageTest.php index 5f1bf0ca79..9f696c08b8 100644 --- a/tests/phpunit/includes/page/WikiCategoryPageTest.php +++ b/tests/phpunit/includes/page/WikiCategoryPageTest.php @@ -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 ); + } }