Bartosz Dziewoński has uploaded a new change for review.
https://gerrit.wikimedia.org/r/94289
Change subject: SpecialWatchlist: Don't overwrite context now that we don't
have to
......................................................................
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
---
M includes/specials/SpecialRecentchanges.php
M includes/specials/SpecialWatchlist.php
2 files changed, 48 insertions(+), 36 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/89/94289/2
diff --git a/includes/specials/SpecialRecentchanges.php
b/includes/specials/SpecialRecentchanges.php
index 43139b8..aa83a4c 100644
--- a/includes/specials/SpecialRecentchanges.php
+++ b/includes/specials/SpecialRecentchanges.php
@@ -78,12 +78,11 @@
*/
public function setup( $parameters ) {
$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 ) {
@@ -96,6 +95,19 @@
}
/**
+ * 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
*
* @return array Map of filter URL param names to properties
(msg/default)
diff --git a/includes/specials/SpecialWatchlist.php
b/includes/specials/SpecialWatchlist.php
index 30fa0ec..802aeed 100644
--- a/includes/specials/SpecialWatchlist.php
+++ b/includes/specials/SpecialWatchlist.php
@@ -35,38 +35,6 @@
}
/**
- * 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
*
* @return FormOptions
@@ -88,6 +56,40 @@
// Add new ones
$opts->add( 'extended', $user->getBoolOption( 'extendwatchlist'
) );
+ 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;
}
@@ -131,8 +133,6 @@
*/
function execute( $par ) {
global $wgRCShowWatchingUsers, $wgEnotifWatchlist,
$wgShowUpdatedMarker;
-
- $this->mapCompatibilityRequestParameters();
$user = $this->getUser();
$output = $this->getOutput();
--
To view, visit https://gerrit.wikimedia.org/r/94289
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I54fd5f35262d86c936deac4d8cec0d2aebad10cd
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits