jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/372877 )
Change subject: WLFilters: set default values ...................................................................... WLFilters: set default values * Respect different default values for 'limit' and 'day' in RC and WL. * Make 'latestrevision' respect 'watchlistextended' Introducing 2 properties to ChangesListBooleanFilter * activeValue: The value that defines when a filter is active. Most filters are active when they are set to 'true' but 'extended' has no effect when it is 'true' and applies filtering when it is set to false. * isVisible: Whether this filter is visible anywhere. 'extended' is not visible in the legacy form but it is activated from preference or URL. When understanding form submission, it should not be assume to be 'false' when not present in the request. Bug: T171134 Change-Id: I3e48a9f2d9b70f0b9f6d7c6329db9c8e8001ee49 --- M includes/changes/ChangesListBooleanFilter.php M includes/specialpage/ChangesListSpecialPage.php M includes/specials/SpecialRecentchanges.php M includes/specials/SpecialWatchlist.php M resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js 5 files changed, 116 insertions(+), 28 deletions(-) Approvals: jenkins-bot: Verified Mooeypoo: Looks good to me, approved diff --git a/includes/changes/ChangesListBooleanFilter.php b/includes/changes/ChangesListBooleanFilter.php index 01e67f5..961cb48 100644 --- a/includes/changes/ChangesListBooleanFilter.php +++ b/includes/changes/ChangesListBooleanFilter.php @@ -67,6 +67,20 @@ protected $queryCallable; /** + * Value that defined when this filter is considered active + * + * @var bool $activeValue + */ + protected $activeValue; + + /** + * Whether this filter is visible somewhere (legacy form or structured UI). + * + * @var bool $isVisible + */ + protected $isVisible; + + /** * Create a new filter with the specified configuration. * * It infers which UI (it can be either or both) to display the filter on based on @@ -90,6 +104,10 @@ * to true. It does not need to be set if the exact same filter is simply visible * on both. * * $filterDefinition['default'] bool Default + * * $filterDefinition['activeValue'] bool This filter is considered active when + * its value is equal to its activeValue. Default is true. + * * $filterDefinition['isVisible'] bool This filter is visible in the legacy form or + * structured UI. Default is true. * * $filterDefinition['priority'] int Priority integer. Higher value means higher * up in the group's filter list. * * $filterDefinition['queryCallable'] callable Callable accepting parameters, used @@ -126,6 +144,18 @@ if ( isset( $filterDefinition['queryCallable'] ) ) { $this->queryCallable = $filterDefinition['queryCallable']; } + + if ( isset( $filterDefinition['activeValue'] ) ) { + $this->activeValue = $filterDefinition['activeValue']; + } else { + $this->activeValue = true; + } + + if ( isset( $filterDefinition['isVisible'] ) ) { + $this->isVisible = $filterDefinition['isVisible']; + } else { + $this->isVisible = true; + } } /** @@ -136,7 +166,7 @@ */ public function getDefault( $structuredUI = false ) { return $this->isReplacedInStructuredUi && $structuredUI ? - false : + !$this->activeValue : $this->defaultValue; } @@ -225,4 +255,24 @@ return $opts[ $sibling->getName() ]; } ); } + + /** + * @param FormOptions $opts Query parameters merged with defaults + * @param bool $isStructuredUI Whether the structured UI is currently enabled + * @return bool Whether this filter should be considered active + */ + public function isActive( FormOptions $opts, $isStructuredUI ) { + if ( $this->isReplacedInStructuredUi && $isStructuredUI ) { + return false; + } + + return $opts[ $this->getName() ] === $this->activeValue; + } + + /** + * @return bool Whether this filter is visible anywhere + */ + public function isVisible() { + return $this->isVisible; + } } diff --git a/includes/specialpage/ChangesListSpecialPage.php b/includes/specialpage/ChangesListSpecialPage.php index 52db51a..4d27d35 100644 --- a/includes/specialpage/ChangesListSpecialPage.php +++ b/includes/specialpage/ChangesListSpecialPage.php @@ -598,7 +598,9 @@ [ 'maxDays' => (int)$this->getConfig()->get( 'RCMaxAge' ) / ( 24 * 3600 ), // Translate to days 'limitArray' => $this->getConfig()->get( 'RCLinkLimits' ), + 'limitDefault' => $this->getDefaultLimit(), 'daysArray' => $this->getConfig()->get( 'RCLinkDays' ), + 'daysDefault' => $this->getDefaultDays(), ] ); } @@ -1153,6 +1155,7 @@ &$join_conds, FormOptions $opts ) { $dbr = $this->getDB(); + $isStructuredUI = $this->isStructuredFilterUiEnabled(); foreach ( $this->filterGroups as $filterGroup ) { // URL parameters can be per-group, like 'userExpLevel', @@ -1162,7 +1165,7 @@ $query_options, $join_conds, $opts[$filterGroup->getName()] ); } else { foreach ( $filterGroup->getFilters() as $filter ) { - if ( $opts[$filter->getName()] ) { + if ( $filter->isActive( $opts, $isStructuredUI ) ) { $filter->modifyQuery( $dbr, $this, $tables, $fields, $conds, $query_options, $join_conds ); } @@ -1535,4 +1538,8 @@ protected function isStructuredFilterUiEnabled() { return $this->getUser()->getOption( 'rcenhancedfilters' ); } + + abstract function getDefaultLimit(); + + abstract function getDefaultDays(); } diff --git a/includes/specials/SpecialRecentchanges.php b/includes/specials/SpecialRecentchanges.php index 4659b9d..d6eac32 100644 --- a/includes/specials/SpecialRecentchanges.php +++ b/includes/specials/SpecialRecentchanges.php @@ -991,4 +991,12 @@ protected function getCacheTTL() { return 60 * 5; } + + function getDefaultLimit() { + return $this->getUser()->getIntOption( 'rclimit' ); + } + + function getDefaultDays() { + return $this->getUser()->getIntOption( 'rcdays' ); + } } diff --git a/includes/specials/SpecialWatchlist.php b/includes/specials/SpecialWatchlist.php index cecc182..83d2afa 100644 --- a/includes/specials/SpecialWatchlist.php +++ b/includes/specials/SpecialWatchlist.php @@ -142,6 +142,41 @@ protected function registerFilters() { parent::registerFilters(); + // legacy 'extended' filter + $this->registerFilterGroup( new ChangesListBooleanFilterGroup( [ + 'name' => 'extended-group', + 'filters' => [ + [ + 'name' => 'extended', + 'isReplacedInStructuredUi' => true, + 'isVisible' => false, + 'activeValue' => false, + 'default' => $this->getUser()->getBoolOption( 'extendwatchlist' ), + 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, + &$fields, &$conds, &$query_options, &$join_conds ) { + $nonRevisionTypes = [ RC_LOG ]; + Hooks::run( 'SpecialWatchlistGetNonRevisionTypes', [ &$nonRevisionTypes ] ); + if ( $nonRevisionTypes ) { + $conds[] = $dbr->makeList( + [ + 'rc_this_oldid=page_latest', + 'rc_type' => $nonRevisionTypes, + ], + LIST_OR + ); + } + }, + ] + ], + + ] ) ); + + if ( $this->isStructuredFilterUiEnabled() ) { + $this->getFilterGroup( 'lastRevision' ) + ->getFilter( 'hidepreviousrevisions' ) + ->setDefault( !$this->getUser()->getBoolOption( 'extendwatchlist' ) ); + } + $this->registerFilterGroup( new ChangesListStringOptionsFilterGroup( [ 'name' => 'watchlistactivity', 'title' => 'rcfilters-filtergroup-watchlistactivity', @@ -234,7 +269,6 @@ $user = $this->getUser(); $opts->add( 'days', $user->getOption( 'watchlistdays' ), FormOptions::FLOAT ); - $opts->add( 'extended', $user->getBoolOption( 'extendwatchlist' ) ); $opts->add( 'limit', $user->getIntOption( 'wllimit' ), FormOptions::INT ); return $opts; @@ -299,7 +333,9 @@ foreach ( $this->filterGroups as $filterGroup ) { if ( $filterGroup instanceof ChangesListBooleanFilterGroup ) { foreach ( $filterGroup->getFilters() as $filter ) { - $allBooleansFalse[$filter->getName()] = false; + if ( $filter->isVisible() ) { + $allBooleansFalse[$filter->getName()] = false; + } } } } @@ -340,22 +376,6 @@ ) { $dbr = $this->getDB(); $user = $this->getUser(); - - # Toggle watchlist content (all recent edits or just the latest) - if ( !$opts['extended'] ) { - # Top log Ids for a page are not stored - $nonRevisionTypes = [ RC_LOG ]; - Hooks::run( 'SpecialWatchlistGetNonRevisionTypes', [ &$nonRevisionTypes ] ); - if ( $nonRevisionTypes ) { - $conds[] = $dbr->makeList( - [ - 'rc_this_oldid=page_latest', - 'rc_type' => $nonRevisionTypes, - ], - LIST_OR - ); - } - } $tables = array_merge( [ 'recentchanges', 'watchlist' ], $tables ); $fields = array_merge( RecentChange::selectFields(), $fields ); @@ -858,4 +878,12 @@ $count = $store->countWatchedItems( $this->getUser() ); return floor( $count / 2 ); } + + function getDefaultLimit() { + return $this->getUser()->getIntOption( 'wllimit' ); + } + + function getDefaultDays() { + return $this->getUser()->getIntOption( 'watchlistdays' ); + } } diff --git a/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js b/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js index a0e60d5..a520bdb 100644 --- a/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js +++ b/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js @@ -40,7 +40,7 @@ * @param {Object} [tagList] Tag definition */ mw.rcfilters.Controller.prototype.initialize = function ( filterStructure, namespaceStructure, tagList ) { - var parsedSavedQueries, limitDefault, + var parsedSavedQueries, displayConfig = mw.config.get( 'StructuredChangeFiltersDisplayConfig' ), controller = this, views = {}, @@ -97,11 +97,6 @@ }; } - // Convert the default from the old preference - // since the limit preference actually affects more - // than just the RecentChanges page - limitDefault = Number( mw.user.options.get( 'rclimit', '50' ) ); - // Add parameter range operations views.range = { groups: [ @@ -117,7 +112,7 @@ max: 1000 }, sortFunc: function ( a, b ) { return Number( a.name ) - Number( b.name ); }, - 'default': String( limitDefault ), + 'default': displayConfig.limitDefault, // Temporarily making this not sticky until we resolve the problem // with the misleading preference. Note that if this is to be permanent // we should remove all sticky behavior methods completely @@ -145,7 +140,7 @@ ( Number( i ) * 24 ).toFixed( 2 ) : Number( i ); }, - 'default': mw.user.options.get( 'rcdays', '30' ), + 'default': displayConfig.daysDefault, // Temporarily making this not sticky while limit is not sticky, see above // isSticky: true, excludedFromSavedQueries: true, -- To view, visit https://gerrit.wikimedia.org/r/372877 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I3e48a9f2d9b70f0b9f6d7c6329db9c8e8001ee49 Gerrit-PatchSet: 8 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Sbisson <sbis...@wikimedia.org> Gerrit-Reviewer: Florianschmidtwelzow <florian.schmidt.stargatewis...@gmail.com> Gerrit-Reviewer: Jack Phoenix <j...@countervandalism.net> Gerrit-Reviewer: Mattflaschen <mflasc...@wikimedia.org> Gerrit-Reviewer: Mooeypoo <mor...@gmail.com> Gerrit-Reviewer: Sbisson <sbis...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits