From fabe7d12a35b86b05cca37ad4878709407414e52 Mon Sep 17 00:00:00 2001 From: Stephane Bisson Date: Mon, 14 Nov 2016 09:10:47 -0500 Subject: [PATCH] RC filter: hidebyothers Allows hiding edits by other users on Special:RecentChanges. It is not available in the current UI but will be used by the ERI project. Bug: T149859 Change-Id: I8c1e2238a41d6f5e5ac44cc12cb02a6b4271c237 --- .../specialpage/ChangesListSpecialPage.php | 10 +++ .../specials/SpecialRecentchangesTest.php | 88 ++++++++++++++++++- 2 files changed, 97 insertions(+), 1 deletion(-) diff --git a/includes/specialpage/ChangesListSpecialPage.php b/includes/specialpage/ChangesListSpecialPage.php index 01782f3b73..cb13840528 100644 --- a/includes/specialpage/ChangesListSpecialPage.php +++ b/includes/specialpage/ChangesListSpecialPage.php @@ -145,6 +145,7 @@ abstract class ChangesListSpecialPage extends SpecialPage { $opts->add( 'hideliu', false ); $opts->add( 'hidepatrolled', false ); $opts->add( 'hidemyself', false ); + $opts->add( 'hidebyothers', false ); if ( $config->get( 'RCWatchCategoryMembership' ) ) { $opts->add( 'hidecategorization', false ); @@ -247,6 +248,7 @@ abstract class ChangesListSpecialPage extends SpecialPage { $conds[] = 'rc_user != 0'; } } + if ( $opts['hidemyself'] ) { if ( $user->getId() ) { $conds[] = 'rc_user != ' . $dbr->addQuotes( $user->getId() ); @@ -254,6 +256,14 @@ abstract class ChangesListSpecialPage extends SpecialPage { $conds[] = 'rc_user_text != ' . $dbr->addQuotes( $user->getName() ); } } + if ( $opts['hidebyothers'] ) { + if ( $user->getId() ) { + $conds[] = 'rc_user = ' . $dbr->addQuotes( $user->getId() ); + } else { + $conds[] = 'rc_user_text = ' . $dbr->addQuotes( $user->getName() ); + } + } + if ( $this->getConfig()->get( 'RCWatchCategoryMembership' ) && $opts['hidecategorization'] === true ) { diff --git a/tests/phpunit/includes/specials/SpecialRecentchangesTest.php b/tests/phpunit/includes/specials/SpecialRecentchangesTest.php index cc16e5f7bd..c51217c5b9 100644 --- a/tests/phpunit/includes/specials/SpecialRecentchangesTest.php +++ b/tests/phpunit/includes/specials/SpecialRecentchangesTest.php @@ -22,9 +22,17 @@ class SpecialRecentchangesTest extends MediaWikiTestCase { protected $rc; /** helper to test SpecialRecentchanges::buildMainQueryConds() */ - private function assertConditions( $expected, $requestOptions = null, $message = '' ) { + private function assertConditions( + $expected, + $requestOptions = null, + $message = '', + $user = null + ) { $context = new RequestContext; $context->setRequest( new FauxRequest( $requestOptions ) ); + if ( $user ) { + $context->setUser( $user ); + } # setup the rc object $this->rc = new SpecialRecentChanges(); @@ -129,4 +137,82 @@ class SpecialRecentchangesTest extends MediaWikiTestCase { [ NS_TALK, NS_MAIN ], ]; } + + public function testRcHidemyselfFilter() { + $user = $this->getTestUser()->getUser(); + $this->assertConditions( + [ # expected + 'rc_bot' => 0, + 0 => "rc_user != '{$user->getId()}'", + 1 => "rc_type != '6'", + ], + [ + 'hidemyself' => 1, + ], + "rc conditions: hidemyself=1 (logged in)", + $user + ); + + $user = User::newFromName( '10.11.12.13', false ); + $this->assertConditions( + [ # expected + 'rc_bot' => 0, + 0 => "rc_user_text != '10.11.12.13'", + 1 => "rc_type != '6'", + ], + [ + 'hidemyself' => 1, + ], + "rc conditions: hidemyself=1 (anon)", + $user + ); + } + + public function testRcHidebyothersFilter() { + $user = $this->getTestUser()->getUser(); + $this->assertConditions( + [ # expected + 'rc_bot' => 0, + 0 => "rc_user = '{$user->getId()}'", + 1 => "rc_type != '6'", + ], + [ + 'hidebyothers' => 1, + ], + "rc conditions: hidebyothers=1 (logged in)", + $user + ); + + $user = User::newFromName( '10.11.12.13', false ); + $this->assertConditions( + [ # expected + 'rc_bot' => 0, + 0 => "rc_user_text = '10.11.12.13'", + 1 => "rc_type != '6'", + ], + [ + 'hidebyothers' => 1, + ], + "rc conditions: hidebyothers=1 (anon)", + $user + ); + } + + public function testRcHidemyselfHidebyothersFilter() { + $user = $this->getTestUser()->getUser(); + $this->assertConditions( + [ # expected + 'rc_bot' => 0, + 0 => "rc_user != '{$user->getId()}'", + 1 => "rc_user = '{$user->getId()}'", + 2 => "rc_type != '6'", + ], + [ + 'hidemyself' => 1, + 'hidebyothers' => 1, + ], + "rc conditions: hidemyself=1 hidebyothers=1 (logged in)", + $user + ); + } } -- 2.20.1