aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAgabi10 <gabilondo.ander@gmail.com>2018-09-07 21:32:26 +0000
committerAgabi10 <gabilondo.ander@gmail.com>2018-11-16 13:32:27 +0000
commit4985ce513469fa82a132139a41c2854504475e4a (patch)
treee924891948fee5475cac8940b0548fa269dbe160
parent68ce51d68f34d590a9dac6142bbb8a507da9657e (diff)
downloadmediawikicore-4985ce513469fa82a132139a41c2854504475e4a.tar.gz
mediawikicore-4985ce513469fa82a132139a41c2854504475e4a.zip
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
-rw-r--r--RELEASE-NOTES-1.332
-rw-r--r--includes/MagicWordFactory.php1
-rw-r--r--includes/page/WikiCategoryPage.php16
-rw-r--r--includes/specials/SpecialUnusedcategories.php13
-rw-r--r--languages/messages/MessagesEn.php1
-rw-r--r--tests/phpunit/includes/page/WikiCategoryPageTest.php42
6 files changed, 71 insertions, 4 deletions
diff --git a/RELEASE-NOTES-1.33 b/RELEASE-NOTES-1.33
index c573a5951cff..df6b5f821479 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 e62716d67e32..4e9bfaf1f7e7 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 6c932029ae2c..283757399861 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 1469742a4b8b..2577a100cf9f 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 587f6ea4adb4..b5e2c5eaa7da 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 5f1bf0ca794a..9f696c08b834 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 );
+ }
}