From: Stephane Bisson Date: Tue, 2 May 2017 23:39:21 +0000 (-0700) Subject: RCFilters: Only register watchlist filter group when user is logged in X-Git-Tag: 1.31.0-rc.0~3343^2~1 X-Git-Url: https://git.heureux-cyclage.org/index.php?a=commitdiff_plain;h=02957353a59cef93c1a5631ce6c2ad28751e37c5;p=lhc%2Fweb%2Fwiklou.git RCFilters: Only register watchlist filter group when user is logged in Follow-up to 9a97cb6. Bug: T164314 Change-Id: If1af0816b5b37857060b87db8e4e798b4824b5a5 --- diff --git a/includes/specialpage/ChangesListSpecialPage.php b/includes/specialpage/ChangesListSpecialPage.php index 93cc18fa42..3f6d86516f 100644 --- a/includes/specialpage/ChangesListSpecialPage.php +++ b/includes/specialpage/ChangesListSpecialPage.php @@ -338,6 +338,7 @@ abstract class ChangesListSpecialPage extends SpecialPage { 'name' => 'changeType', 'title' => 'rcfilters-filtergroup-changetype', 'class' => ChangesListBooleanFilterGroup::class, + 'priority' => -8, 'filters' => [ [ 'name' => 'hidepageedits', @@ -393,96 +394,6 @@ abstract class ChangesListSpecialPage extends SpecialPage { ], ], - [ - 'name' => 'watchlist', - 'title' => 'rcfilters-filtergroup-watchlist', - 'class' => ChangesListStringOptionsFilterGroup::class, - 'isFullCoverage' => true, - 'filters' => [ - [ - 'name' => 'watched', - 'label' => 'rcfilters-filter-watchlist-watched-label', - 'description' => 'rcfilters-filter-watchlist-watched-description', - 'cssClassSuffix' => 'watched', - 'isRowApplicableCallable' => function ( $ctx, $rc ) { - return $rc->getAttribute( 'wl_user' ); - } - ], - [ - 'name' => 'watchednew', - 'label' => 'rcfilters-filter-watchlist-watchednew-label', - 'description' => 'rcfilters-filter-watchlist-watchednew-description', - 'cssClassSuffix' => 'watchednew', - 'isRowApplicableCallable' => function ( $ctx, $rc ) { - return $rc->getAttribute( 'wl_user' ) && - $rc->getAttribute( 'rc_timestamp' ) && - $rc->getAttribute( 'wl_notificationtimestamp' ) && - $rc->getAttribute( 'rc_timestamp' ) >= $rc->getAttribute( 'wl_notificationtimestamp' ); - }, - ], - [ - 'name' => 'notwatched', - 'label' => 'rcfilters-filter-watchlist-notwatched-label', - 'description' => 'rcfilters-filter-watchlist-notwatched-description', - 'cssClassSuffix' => 'notwatched', - 'isRowApplicableCallable' => function ( $ctx, $rc ) { - return $rc->getAttribute( 'wl_user' ) === null; - }, - ] - ], - 'default' => ChangesListStringOptionsFilterGroup::NONE, - 'queryCallable' => function ( $specialPageClassName, $context, $dbr, - &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedValues ) { - sort( $selectedValues ); - $notwatchedCond = 'wl_user IS NULL'; - $watchedCond = 'wl_user IS NOT NULL'; - $newCond = 'rc_timestamp >= wl_notificationtimestamp'; - - if ( $selectedValues === [ 'notwatched' ] ) { - $conds[] = $notwatchedCond; - return; - } - - if ( $selectedValues === [ 'watched' ] ) { - $conds[] = $watchedCond; - return; - } - - if ( $selectedValues === [ 'watchednew' ] ) { - $conds[] = $dbr->makeList( [ - $watchedCond, - $newCond - ], LIST_AND ); - return; - } - - if ( $selectedValues === [ 'notwatched', 'watched' ] ) { - // no filters - return; - } - - if ( $selectedValues === [ 'notwatched', 'watchednew' ] ) { - $conds[] = $dbr->makeList( [ - $notwatchedCond, - $dbr->makeList( [ - $watchedCond, - $newCond - ], LIST_AND ) - ], LIST_OR ); - return; - } - - if ( $selectedValues === [ 'watched', 'watchednew' ] ) { - $conds[] = $watchedCond; - return; - } - - if ( $selectedValues === [ 'notwatched', 'watched', 'watchednew' ] ) { - // no filters - return; - } - }, - ], ]; $this->reviewStatusFilterGroupDefinition = [ @@ -700,7 +611,7 @@ abstract class ChangesListSpecialPage extends SpecialPage { // Make sure this is not being transcluded (we don't want to show this // information to all users just because the user that saves the edit can - // patrol) + // patrol or is logged in) if ( !$this->including() && $this->getUser()->useRCPatrol() ) { $this->registerFiltersFromDefinitions( $this->reviewStatusFilterGroupDefinition ); } @@ -770,11 +681,6 @@ abstract class ChangesListSpecialPage extends SpecialPage { 'rcfilters-hideminor-conflicts-typeofchange', 'rcfilters-typeofchange-conflicts-hideminor' ); - - $watchlistGroup = $this->getFilterGroup( 'watchlist' ); - $watchlistGroup->getFilter( 'watched' )->setAsSupersetOf( - $watchlistGroup->getFilter( 'watchednew' ) - ); } /** diff --git a/includes/specials/SpecialRecentchanges.php b/includes/specials/SpecialRecentchanges.php index aaa99b60f1..4c8e882fbe 100644 --- a/includes/specials/SpecialRecentchanges.php +++ b/includes/specials/SpecialRecentchanges.php @@ -31,9 +31,104 @@ use Wikimedia\Rdbms\FakeResultWrapper; * @ingroup SpecialPage */ class SpecialRecentChanges extends ChangesListSpecialPage { + + private $watchlistFilterGroupDefinition; + // @codingStandardsIgnoreStart Needed "useless" override to change parameters. public function __construct( $name = 'Recentchanges', $restriction = '' ) { parent::__construct( $name, $restriction ); + + $this->watchlistFilterGroupDefinition = [ + 'name' => 'watchlist', + 'title' => 'rcfilters-filtergroup-watchlist', + 'class' => ChangesListStringOptionsFilterGroup::class, + 'priority' => -9, + 'isFullCoverage' => true, + 'filters' => [ + [ + 'name' => 'watched', + 'label' => 'rcfilters-filter-watchlist-watched-label', + 'description' => 'rcfilters-filter-watchlist-watched-description', + 'cssClassSuffix' => 'watched', + 'isRowApplicableCallable' => function ( $ctx, $rc ) { + return $rc->getAttribute( 'wl_user' ); + } + ], + [ + 'name' => 'watchednew', + 'label' => 'rcfilters-filter-watchlist-watchednew-label', + 'description' => 'rcfilters-filter-watchlist-watchednew-description', + 'cssClassSuffix' => 'watchednew', + 'isRowApplicableCallable' => function ( $ctx, $rc ) { + return $rc->getAttribute( 'wl_user' ) && + $rc->getAttribute( 'rc_timestamp' ) && + $rc->getAttribute( 'wl_notificationtimestamp' ) && + $rc->getAttribute( 'rc_timestamp' ) >= $rc->getAttribute( 'wl_notificationtimestamp' ); + }, + ], + [ + 'name' => 'notwatched', + 'label' => 'rcfilters-filter-watchlist-notwatched-label', + 'description' => 'rcfilters-filter-watchlist-notwatched-description', + 'cssClassSuffix' => 'notwatched', + 'isRowApplicableCallable' => function ( $ctx, $rc ) { + return $rc->getAttribute( 'wl_user' ) === null; + }, + ] + ], + 'default' => ChangesListStringOptionsFilterGroup::NONE, + 'queryCallable' => function ( $specialPageClassName, $context, $dbr, + &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedValues ) { + sort( $selectedValues ); + $notwatchedCond = 'wl_user IS NULL'; + $watchedCond = 'wl_user IS NOT NULL'; + $newCond = 'rc_timestamp >= wl_notificationtimestamp'; + + if ( $selectedValues === [ 'notwatched' ] ) { + $conds[] = $notwatchedCond; + return; + } + + if ( $selectedValues === [ 'watched' ] ) { + $conds[] = $watchedCond; + return; + } + + if ( $selectedValues === [ 'watchednew' ] ) { + $conds[] = $dbr->makeList( [ + $watchedCond, + $newCond + ], LIST_AND ); + return; + } + + if ( $selectedValues === [ 'notwatched', 'watched' ] ) { + // no filters + return; + } + + if ( $selectedValues === [ 'notwatched', 'watchednew' ] ) { + $conds[] = $dbr->makeList( [ + $notwatchedCond, + $dbr->makeList( [ + $watchedCond, + $newCond + ], LIST_AND ) + ], LIST_OR ); + return; + } + + if ( $selectedValues === [ 'watched', 'watchednew' ] ) { + $conds[] = $watchedCond; + return; + } + + if ( $selectedValues === [ 'notwatched', 'watched', 'watchednew' ] ) { + // no filters + return; + } + } + ]; } // @codingStandardsIgnoreEnd @@ -103,6 +198,18 @@ class SpecialRecentChanges extends ChangesListSpecialPage { protected function registerFilters() { parent::registerFilters(); + if ( + !$this->including() && + $this->getUser()->isLoggedIn() && + $this->getUser()->isAllowed( 'viewmywatchlist' ) + ) { + $this->registerFiltersFromDefinitions( [ $this->watchlistFilterGroupDefinition ] ); + $watchlistGroup = $this->getFilterGroup( 'watchlist' ); + $watchlistGroup->getFilter( 'watched' )->setAsSupersetOf( + $watchlistGroup->getFilter( 'watchednew' ) + ); + } + $user = $this->getUser(); $significance = $this->getFilterGroup( 'significance' ); @@ -236,7 +343,7 @@ class SpecialRecentChanges extends ChangesListSpecialPage { $fields = array_merge( RecentChange::selectFields(), $fields ); // JOIN on watchlist for users - if ( $user->getId() && $user->isAllowed( 'viewmywatchlist' ) ) { + if ( $user->isLoggedIn() && $user->isAllowed( 'viewmywatchlist' ) ) { $tables[] = 'watchlist'; $fields[] = 'wl_user'; $fields[] = 'wl_notificationtimestamp';