From: Stephane Bisson Date: Mon, 21 Aug 2017 19:28:23 +0000 (-0400) Subject: WLFilters: set default values X-Git-Tag: 1.31.0-rc.0~2277^2 X-Git-Url: http://git.cyclocoop.org/?a=commitdiff_plain;h=6314a9026f9b404928e96a883c6ace7e491e891b;p=lhc%2Fweb%2Fwiklou.git 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 --- diff --git a/includes/changes/ChangesListBooleanFilter.php b/includes/changes/ChangesListBooleanFilter.php index 01e67f5079..961cb48ac0 100644 --- a/includes/changes/ChangesListBooleanFilter.php +++ b/includes/changes/ChangesListBooleanFilter.php @@ -66,6 +66,20 @@ class ChangesListBooleanFilter extends ChangesListFilter { */ 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. * @@ -90,6 +104,10 @@ class ChangesListBooleanFilter extends ChangesListFilter { * 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 @@ class ChangesListBooleanFilter extends ChangesListFilter { 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 @@ class ChangesListBooleanFilter extends ChangesListFilter { */ public function getDefault( $structuredUI = false ) { return $this->isReplacedInStructuredUi && $structuredUI ? - false : + !$this->activeValue : $this->defaultValue; } @@ -225,4 +255,24 @@ class ChangesListBooleanFilter extends ChangesListFilter { 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 52db51aa8e..4d27d35dd4 100644 --- a/includes/specialpage/ChangesListSpecialPage.php +++ b/includes/specialpage/ChangesListSpecialPage.php @@ -598,7 +598,9 @@ abstract class ChangesListSpecialPage extends SpecialPage { [ '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 @@ abstract class ChangesListSpecialPage extends SpecialPage { &$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 @@ abstract class ChangesListSpecialPage extends SpecialPage { $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 @@ abstract class ChangesListSpecialPage extends SpecialPage { 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 4659b9d739..d6eac32e66 100644 --- a/includes/specials/SpecialRecentchanges.php +++ b/includes/specials/SpecialRecentchanges.php @@ -991,4 +991,12 @@ class SpecialRecentChanges extends ChangesListSpecialPage { 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 cecc182f72..83d2afa3e0 100644 --- a/includes/specials/SpecialWatchlist.php +++ b/includes/specials/SpecialWatchlist.php @@ -142,6 +142,41 @@ class SpecialWatchlist extends ChangesListSpecialPage { 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 @@ class SpecialWatchlist extends ChangesListSpecialPage { $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 @@ class SpecialWatchlist extends ChangesListSpecialPage { 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; + } } } } @@ -341,22 +377,6 @@ class SpecialWatchlist extends ChangesListSpecialPage { $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 @@ class SpecialWatchlist extends ChangesListSpecialPage { $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 a0e60d583d..a520bdb7a2 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,