From df4b6e4c3a9cee325719c8201e978567d17a3dac Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Thu, 3 Nov 2011 19:14:46 +0000 Subject: [PATCH] Per Aaron, fix for r89405: introduced DerivativeRequest to allow to override the request parameters, but not headers, cookies and session. Updated ApiEditPage (for the bug) and ApiLogin (for future use) --- includes/WebRequest.php | 40 ++++++++++++++++++++++++++++++++++++ includes/api/ApiEditPage.php | 4 ++-- includes/api/ApiLogin.php | 21 +++++++++---------- 3 files changed, 52 insertions(+), 13 deletions(-) diff --git a/includes/WebRequest.php b/includes/WebRequest.php index 362051dbd4..3651f92d38 100644 --- a/includes/WebRequest.php +++ b/includes/WebRequest.php @@ -1306,3 +1306,43 @@ class FauxRequest extends WebRequest { return '127.0.0.1'; } } + +/** + * Similar to FauxRequest, but only fakes URL parameters and method + * (POST or GET) and use the base request for the remaining stuff + * (cookies, session and headers). + * + * @ingroup HTTP + */ +class DerivativeRequest extends FauxRequest { + private $base; + + public function __construct( WebRequest $base, $data, $wasPosted = false ) { + $this->base = $base; + parent::__construct( $data, $wasPosted ); + } + + public function getCookie( $key, $prefix = null, $default = null ) { + return $this->base->getCookie( $key, $prefix, $default ); + } + + public function checkSessionCookie() { + return $this->base->checkSessionCookie(); + } + + public function getHeader( $name ) { + return $this->base->getHeader( $name ); + } + + public function getAllHeaders() { + return $this->base->getAllHeaders(); + } + + public function getSessionData( $key ) { + return $this->base->getSessionData( $key ); + } + + public function setSessionData( $key, $data ) { + return $this->base->setSessionData( $key, $data ); + } +} diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php index 61dea37dcd..e3106461a8 100644 --- a/includes/api/ApiEditPage.php +++ b/includes/api/ApiEditPage.php @@ -239,12 +239,12 @@ class ApiEditPage extends ApiBase { $reqArr['wpWatchthis'] = ''; } - $req = new FauxRequest( $reqArr, true ); + global $wgRequest; + $req = new DerivativeRequest( $wgRequest, $reqArr, true ); $ep->importFormData( $req ); // Run hooks // Handle CAPTCHA parameters - global $wgRequest; if ( !is_null( $params['captchaid'] ) ) { $wgRequest->setVal( 'wpCaptchaId', $params['captchaid'] ); } diff --git a/includes/api/ApiLogin.php b/includes/api/ApiLogin.php index a45d51f095..ae660fd258 100644 --- a/includes/api/ApiLogin.php +++ b/includes/api/ApiLogin.php @@ -55,23 +55,22 @@ class ApiLogin extends ApiBase { $result = array(); - $req = new FauxRequest( array( - 'wpName' => $params['name'], - 'wpPassword' => $params['password'], - 'wpDomain' => $params['domain'], - 'wpLoginToken' => $params['token'], - 'wpRemember' => '' - ) ); - // Init session if necessary if ( session_id() == '' ) { wfSetupSession(); } $context = new DerivativeContext( $this->getContext() ); - $context->setRequest( $req ); - /*$context = $this->createContext(); - $context->setRequest( $req );*/ + $context->setRequest( new DerivativeRequest( + $this->getContext()->getRequest(), + array( + 'wpName' => $params['name'], + 'wpPassword' => $params['password'], + 'wpDomain' => $params['domain'], + 'wpLoginToken' => $params['token'], + 'wpRemember' => '' + ) + ) ); $loginForm = new LoginForm(); $loginForm->setContext( $context ); -- 2.20.1