X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FFauxRequest.php;h=c2108f207a52bdfe291949d20dcd13b810922e9c;hb=460ea2524c4643e7f8ddf2fd6c95f77aaeb91891;hp=888f853a4d1df29d3ced9ed31435d85180d3c510;hpb=114e30955c803d13f37dbb23c8d0cf500fc43d06;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/FauxRequest.php b/includes/FauxRequest.php index 888f853a4d..c2108f207a 100644 --- a/includes/FauxRequest.php +++ b/includes/FauxRequest.php @@ -23,6 +23,8 @@ * @file */ +use MediaWiki\Session\SessionManager; + /** * WebRequest clone which takes values from a provided array. * @@ -30,19 +32,19 @@ */ class FauxRequest extends WebRequest { private $wasPosted = false; - private $session = array(); private $requestUrl; - protected $cookies = array(); + protected $cookies = []; /** * @param array $data Array of *non*-urlencoded key => value pairs, the * fake GET/POST values * @param bool $wasPosted Whether to treat the data as POST - * @param array|null $session Session array or null + * @param MediaWiki\\Session\\Session|array|null $session Session, session + * data array, or null * @param string $protocol 'http' or 'https' * @throws MWException */ - public function __construct( $data = array(), $wasPosted = false, + public function __construct( $data = [], $wasPosted = false, $session = null, $protocol = 'http' ) { $this->requestTime = microtime( true ); @@ -53,8 +55,16 @@ class FauxRequest extends WebRequest { throw new MWException( "FauxRequest() got bogus data" ); } $this->wasPosted = $wasPosted; - if ( $session ) { - $this->session = $session; + if ( $session instanceof MediaWiki\Session\Session ) { + $this->sessionId = $session->getSessionId(); + } elseif ( is_array( $session ) ) { + $mwsession = SessionManager::singleton()->getEmptySession( $this ); + $this->sessionId = $mwsession->getSessionId(); + foreach ( $session as $key => $value ) { + $mwsession->set( $key, $value ); + } + } elseif ( $session !== null ) { + throw new MWException( "FauxRequest() got bogus session" ); } $this->protocol = $protocol; } @@ -88,7 +98,7 @@ class FauxRequest extends WebRequest { */ public function getQueryValues() { if ( $this->wasPosted ) { - return array(); + return []; } else { return $this->data; } @@ -121,7 +131,7 @@ class FauxRequest extends WebRequest { * @param string|null $prefix Cookie prefix. Defaults to $wgCookiePrefix */ public function setCookie( $key, $value, $prefix = null ) { - $this->setCookies( array( $key => $value ), $prefix ); + $this->setCookies( [ $key => $value ], $prefix ); } /** @@ -140,10 +150,6 @@ class FauxRequest extends WebRequest { } } - public function checkSessionCookie() { - return false; - } - /** * @since 1.25 */ @@ -171,7 +177,7 @@ class FauxRequest extends WebRequest { * @param string $val */ public function setHeader( $name, $val ) { - $this->setHeaders( array( $name => $val ) ); + $this->setHeaders( [ $name => $val ] ); } /** @@ -186,31 +192,15 @@ class FauxRequest extends WebRequest { } /** - * @param string $key * @return array|null */ - public function getSessionData( $key ) { - if ( isset( $this->session[$key] ) ) { - return $this->session[$key]; + public function getSessionArray() { + if ( $this->sessionId !== null ) { + return iterator_to_array( $this->getSession() ); } return null; } - /** - * @param string $key - * @param array $data - */ - public function setSessionData( $key, $data ) { - $this->session[$key] = $data; - } - - /** - * @return array|mixed|null - */ - public function getSessionArray() { - return $this->session; - } - /** * FauxRequests shouldn't depend on raw request data (but that could be implemented here) * @return string @@ -239,7 +229,7 @@ class FauxRequest extends WebRequest { * @param array $extWhitelist * @return bool */ - public function checkUrlExtension( $extWhitelist = array() ) { + public function checkUrlExtension( $extWhitelist = [] ) { return true; }