[MediaWiki-commits] [Gerrit] mediawiki/core[master]: WLFilters: set default values
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 +++
[MediaWiki-commits] [Gerrit] mediawiki/core[master]: WLFilters: set default values
Sbisson has uploaded a new change for review. ( 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' active by default on WL Bug: T171134 Change-Id: I3e48a9f2d9b70f0b9f6d7c6329db9c8e8001ee49 --- M includes/specialpage/ChangesListSpecialPage.php M includes/specials/SpecialRecentchanges.php M includes/specials/SpecialWatchlist.php M resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js 4 files changed, 28 insertions(+), 7 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/77/372877/1 diff --git a/includes/specialpage/ChangesListSpecialPage.php b/includes/specialpage/ChangesListSpecialPage.php index 52db51a..c9f7695 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(), ] ); } @@ -1535,4 +1537,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 b20b331..224649a 100644 --- a/includes/specials/SpecialWatchlist.php +++ b/includes/specials/SpecialWatchlist.php @@ -142,6 +142,10 @@ protected function registerFilters() { parent::registerFilters(); + $this->getFilterGroup( 'lastRevision' ) + ->getFilter( 'hidepreviousrevisions' ) + ->setDefault( true ); + $this->registerFilterGroup( new ChangesListStringOptionsFilterGroup( [ 'name' => 'watchlistactivity', 'title' => 'rcfilters-filtergroup-watchlistactivity', @@ -858,4 +862,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 c24e6c6..7dd1a28 100644 --- a/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js +++ b/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js @@ -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