From 76b899b21b8b3d20333a5fa57eab4c29c0da82e0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Fri, 8 Nov 2013 00:42:47 +0100 Subject: [PATCH] SpecialWatchlist: Don't overwrite context now that we don't have to Abstracted away backwards-compatibility URL parameter handling to a separate method called before the options are fetched. Change-Id: I54fd5f35262d86c936deac4d8cec0d2aebad10cd --- includes/specials/SpecialRecentchanges.php | 16 ++++- includes/specials/SpecialWatchlist.php | 68 +++++++++++----------- 2 files changed, 48 insertions(+), 36 deletions(-) diff --git a/includes/specials/SpecialRecentchanges.php b/includes/specials/SpecialRecentchanges.php index 8a119f50ac..a4e0b85c9c 100644 --- a/includes/specials/SpecialRecentchanges.php +++ b/includes/specials/SpecialRecentchanges.php @@ -87,12 +87,11 @@ class SpecialRecentChanges extends SpecialPage { global $wgFeedLimit; $opts = $this->getDefaultOptions(); - foreach ( $this->getCustomFilters() as $key => $params ) { $opts->add( $key, $params['default'] ); } - $opts->fetchValuesFromRequest( $this->getRequest() ); + $opts = $this->fetchOptionsFromRequest( $opts ); // Give precedence to subpage syntax if ( $parameters !== null ) { @@ -104,6 +103,19 @@ class SpecialRecentChanges extends SpecialPage { return $opts; } + /** + * Fetch values for a FormOptions object from the WebRequest associated with this instance. + * + * Intended for subclassing, e.g. to add a backwards-compatibility layer. + * + * @param FormOptions $parameters + * @return FormOptions + */ + protected function fetchOptionsFromRequest( $opts ) { + $opts->fetchValuesFromRequest( $this->getRequest() ); + return $opts; + } + /** * Get custom show/hide filters * diff --git a/includes/specials/SpecialWatchlist.php b/includes/specials/SpecialWatchlist.php index 49a149423c..afdf9810d9 100644 --- a/includes/specials/SpecialWatchlist.php +++ b/includes/specials/SpecialWatchlist.php @@ -34,38 +34,6 @@ class SpecialWatchlist extends SpecialRecentChanges { return false; } - /** - * Map old pre-1.23 request parameters Watchlist used to use (different from Recentchanges' ones) - * to the current ones. - * - * This creates derivative context and request, pokes with request's parameters, and sets them as - * the context for this class instance, mapping old keys to new ones completely transparently (as - * long as nothing tries to access the globals instead of current context). - */ - private function mapCompatibilityRequestParameters() { - static $map = array( - 'hideMinor' => 'hideminor', - 'hideBots' => 'hidebots', - 'hideAnons' => 'hideanons', - 'hideLiu' => 'hideliu', - 'hidePatrolled' => 'hidepatrolled', - 'hideOwn' => 'hidemyself', - ); - - $params = $this->getRequest()->getValues(); - foreach ( $map as $from => $to ) { - if ( isset( $params[$from] ) ) { - $params[$to] = $params[$from]; - unset( $params[$from] ); - } - } - - $context = new DerivativeContext( $this->getContext() ); - $request = new DerivativeRequest( $context->getRequest(), $params ); - $context->setRequest( $request ); - $this->setContext( $context ); - } - /** * Get a FormOptions object containing the default options * @@ -91,6 +59,40 @@ class SpecialWatchlist extends SpecialRecentChanges { return $opts; } + /** + * Fetch values for a FormOptions object from the WebRequest associated with this instance. + * + * Maps old pre-1.23 request parameters Watchlist used to use (different from Recentchanges' ones) + * to the current ones. + * + * @param FormOptions $parameters + * @return FormOptions + */ + protected function fetchOptionsFromRequest( $opts ) { + static $compatibilityMap = array( + 'hideMinor' => 'hideminor', + 'hideBots' => 'hidebots', + 'hideAnons' => 'hideanons', + 'hideLiu' => 'hideliu', + 'hidePatrolled' => 'hidepatrolled', + 'hideOwn' => 'hidemyself', + ); + + $params = $this->getRequest()->getValues(); + foreach ( $compatibilityMap as $from => $to ) { + if ( isset( $params[$from] ) ) { + $params[$to] = $params[$from]; + unset( $params[$from] ); + } + } + + // Not the prettiest way to achieve this… FormOptions internally depends on data sanitization + // methods defined on WebRequest and removing this dependency would cause some code duplication. + $request = new DerivativeRequest( $this->getRequest(), $params ); + $opts->fetchValuesFromRequest( $request ); + return $opts; + } + /** * Get custom show/hide filters * @@ -132,8 +134,6 @@ class SpecialWatchlist extends SpecialRecentChanges { function execute( $par ) { global $wgRCShowWatchingUsers, $wgEnotifWatchlist, $wgShowUpdatedMarker; - $this->mapCompatibilityRequestParameters(); - $user = $this->getUser(); $output = $this->getOutput(); $output->addModuleStyles( 'mediawiki.special.changeslist' ); -- 2.20.1