Merge "RC filter: hidebyothers"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 24 Nov 2016 00:26:04 +0000 (00:26 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 24 Nov 2016 00:26:04 +0000 (00:26 +0000)
includes/specialpage/ChangesListSpecialPage.php
tests/phpunit/includes/specials/SpecialRecentchangesTest.php

index 01782f3..cb13840 100644 (file)
@@ -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
                ) {
index cc16e5f..c51217c 100644 (file)
@@ -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
+               );
+       }
 }