From a2dd90eb4a2bd6db02d5952419e99c864a77a02b Mon Sep 17 00:00:00 2001 From: Stephane Bisson Date: Wed, 23 Nov 2016 14:39:23 -0500 Subject: [PATCH] RC/Watchlist: Filter out parameters that cannot be displayed Some parameters added by the ORES extension work with the URL and the new ERI UI but not with the old toggle (hide*) filter UI. Specifying 'msg' => false when adding them from the hook registers them correctly but they won't be displayed. Bug: T149853 Change-Id: If47842f3d91c5999a7c5bf25666b967e9b30a6d7 --- .../specialpage/ChangesListSpecialPage.php | 19 +++++++++++++++++++ includes/specials/SpecialRecentchanges.php | 5 +++-- includes/specials/SpecialWatchlist.php | 5 +++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/includes/specialpage/ChangesListSpecialPage.php b/includes/specialpage/ChangesListSpecialPage.php index cb13840528..9e3e3df399 100644 --- a/includes/specialpage/ChangesListSpecialPage.php +++ b/includes/specialpage/ChangesListSpecialPage.php @@ -495,4 +495,23 @@ abstract class ChangesListSpecialPage extends SpecialPage { protected function getGroupName() { return 'changes'; } + + /** + * Get filters that can be rendered. + * + * Filters with 'msg' => false can be used to filter data but won't + * be presented as show/hide toggles in the UI. They are not returned + * by this function. + * + * @param array $allFilters Map of filter URL param names to properties (msg/default) + * @return array Map of filter URL param names to properties (msg/default) + */ + protected function getRenderableCustomFilters( $allFilters ) { + return array_filter( + $allFilters, + function( $filter ) { + return isset( $filter['msg'] ) && ( $filter['msg'] !== false ); + } + ); + } } diff --git a/includes/specials/SpecialRecentchanges.php b/includes/specials/SpecialRecentchanges.php index cd3299c210..4569dd2601 100644 --- a/includes/specials/SpecialRecentchanges.php +++ b/includes/specials/SpecialRecentchanges.php @@ -95,7 +95,7 @@ class SpecialRecentChanges extends ChangesListSpecialPage { } /** - * Get custom show/hide filters + * Get all custom filters * * @return array Map of filter URL param names to properties (msg/default) */ @@ -747,9 +747,10 @@ class SpecialRecentChanges extends ChangesListSpecialPage { $showhide = [ 'show', 'hide' ]; - foreach ( $this->getCustomFilters() as $key => $params ) { + foreach ( $this->getRenderableCustomFilters( $this->getCustomFilters() ) as $key => $params ) { $filters[$key] = $params['msg']; } + // Disable some if needed if ( !$user->useRCPatrol() ) { unset( $filters['hidepatrolled'] ); diff --git a/includes/specials/SpecialWatchlist.php b/includes/specials/SpecialWatchlist.php index 4824961c70..55400d3cc9 100644 --- a/includes/specials/SpecialWatchlist.php +++ b/includes/specials/SpecialWatchlist.php @@ -130,7 +130,7 @@ class SpecialWatchlist extends ChangesListSpecialPage { } /** - * Get custom show/hide filters + * Get all custom filters * * @return array Map of filter URL param names to properties (msg/default) */ @@ -465,9 +465,10 @@ class SpecialWatchlist extends ChangesListSpecialPage { $filters['hidecategorization'] = 'wlshowhidecategorization'; } - foreach ( $this->getCustomFilters() as $key => $params ) { + foreach ( $this->getRenderableCustomFilters( $this->getCustomFilters() ) as $key => $params ) { $filters[$key] = $params['msg']; } + // Disable some if needed if ( !$user->useRCPatrol() ) { unset( $filters['hidepatrolled'] ); -- 2.20.1