WMDE-Fisch has uploaded a new change for review.
https://gerrit.wikimedia.org/r/278263
Change subject: Hide hiddencat catwatch changes in special changelists
......................................................................
Hide hiddencat catwatch changes in special changelists
If a hidden category has a member added or removed
this will only be shown to users that have the user
preference "display hidden categories".
Also added static method to WikiCategoryPage to check
for hidden status.
Added unit tests for both.
Bug: T127944
Change-Id: Id051569533bd00bb24228b7ee0b718b7543d62df
---
M includes/changes/RecentChange.php
M includes/page/WikiCategoryPage.php
M includes/specials/SpecialRecentchanges.php
M tests/phpunit/includes/changes/RecentChangeTest.php
A tests/phpunit/includes/page/WikiCategoryPageTest.php
5 files changed, 82 insertions(+), 6 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/63/278263/1
diff --git a/includes/changes/RecentChange.php
b/includes/changes/RecentChange.php
index a7b587a..c614754 100644
--- a/includes/changes/RecentChange.php
+++ b/includes/changes/RecentChange.php
@@ -819,11 +819,7 @@
$ip = '',
$deleted = 0
) {
- $isHiddenCat = false;
- $categoryContent = WikiPage::factory( $categoryTitle
)->getContent();
- if ( $categoryContent ) {
- $isHiddenCat = $categoryContent->matchMagicWord(
MagicWord::get( 'hiddencat' ) );
- }
+ $isHiddenCat = WikiCategoryPage::isHidden( WikiPage::factory(
$categoryTitle ) );
$rc = new RecentChange;
$rc->mTitle = $categoryTitle;
@@ -866,6 +862,17 @@
}
/**
+ * Get a parameter value
+ *
+ * @param string $name parameter name
+ * @return mixed
+ */
+ public function getParam( $name ) {
+ $params = $this->parseParams();
+ return isset( $params[$name] ) ? $params[$name] : null;
+ }
+
+ /**
* Initialises the members of this object from a mysql row object
*
* @param mixed $row
diff --git a/includes/page/WikiCategoryPage.php
b/includes/page/WikiCategoryPage.php
index d382001..90fd1c7 100644
--- a/includes/page/WikiCategoryPage.php
+++ b/includes/page/WikiCategoryPage.php
@@ -47,4 +47,20 @@
}
return false;
}
+
+
+ /**
+ * Checks if a category is hidden.
+ * @param WikiCategoryPage $page
+ * @return bool
+ */
+ public static function isHidden( WikiPage $page ) {
+ $isHiddenCat = false;
+ $categoryContent = $page->getContent();
+ if ( $categoryContent ) {
+ $isHiddenCat = $categoryContent->matchMagicWord(
MagicWord::get( 'hiddencat' ) );
+ return $isHiddenCat;
+ }
+ return $isHiddenCat;
+ }
}
diff --git a/includes/specials/SpecialRecentchanges.php
b/includes/specials/SpecialRecentchanges.php
index 5dfe15e..f4837ef 100644
--- a/includes/specials/SpecialRecentchanges.php
+++ b/includes/specials/SpecialRecentchanges.php
@@ -337,7 +337,7 @@
if (
$rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE
&&
!$userShowHiddenCats &&
- $rc->parseParams()['hidden-cat']
+ $rc->getParam( 'hidden-cat' )
) {
continue;
}
diff --git a/tests/phpunit/includes/changes/RecentChangeTest.php
b/tests/phpunit/includes/changes/RecentChangeTest.php
index 4abe9ee..a3d5155 100644
--- a/tests/phpunit/includes/changes/RecentChangeTest.php
+++ b/tests/phpunit/includes/changes/RecentChangeTest.php
@@ -134,4 +134,29 @@
$this->assertEquals( $rcType, RecentChange::parseToRCType(
$type ) );
}
+ public function provideCategoryContent() {
+ return [
+ [ "Hidden. __HIDDENCAT__", true ],
+ [ "Not Hidden.", false ],
+ ];
+ }
+
+ /**
+ * @dataProvider provideCategoryContent
+ * @covers RecentChange::newForCategorization
+ */
+ public function testHiddenCategoryChange( $content, $isHidden ) {
+ $title = Title::newFromText( 'CategoryPager', NS_CATEGORY );
+ $categoryPage = WikiPage::factory( $title );
+ $content = ContentHandler::makeContent(
+ $content,
+ $title,
+ CONTENT_MODEL_WIKITEXT
+ );
+ $categoryPage->doEditContent( $content, '' );
+
+ $rc = RecentChange::newForCategorization(0, $title,
$this->user, $this->user_comment, $this->title );
+
+ $this->assertEquals( [ 'hidden-cat' => $isHidden ],
$rc->parseParams() );
+ }
}
diff --git a/tests/phpunit/includes/page/WikiCategoryPageTest.php
b/tests/phpunit/includes/page/WikiCategoryPageTest.php
new file mode 100644
index 0000000..1368182
--- /dev/null
+++ b/tests/phpunit/includes/page/WikiCategoryPageTest.php
@@ -0,0 +1,28 @@
+<?php
+
+class WikiCategoryPageTest extends MediaWikiLangTestCase {
+
+ public function provideCategoryContent() {
+ return [
+ [ "Hidden. __HIDDENCAT__", true ],
+ [ "Not Hidden.", false ],
+ ];
+ }
+
+ /**
+ * @dataProvider provideCategoryContent
+ * @covers RecentChange::newForCategorization
+ */
+ public function testHiddenCategoryChange( $content, $isHidden ) {
+ $title = Title::makeTitle( NS_CATEGORY, 'CategoryPage' );
+ $categoryPage = WikiPage::factory( $title );
+ $content = ContentHandler::makeContent(
+ $content,
+ $title,
+ CONTENT_MODEL_WIKITEXT
+ );
+ $categoryPage->doEditContent( $content, '' );
+
+ $this->assertEquals( $isHidden, WikiCategoryPage::isHidden(
$categoryPage ) );
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/278263
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id051569533bd00bb24228b7ee0b718b7543d62df
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: WMDE-Fisch <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits