1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
<?php
/**
* Deal with importing all those nasty globals and things
*
* Copyright © 2003 Brooke Vibber <bvibber@wikimedia.org>
* https://www.mediawiki.org/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
*/
namespace MediaWiki\Request;
use MediaWiki\Session\Session;
/**
* Similar to MediaWiki\Request\FauxRequest, but only fakes URL parameters and method
* (POST or GET) and use the base request for the remaining stuff
* (cookies, session and headers).
*
* @newable
*
* @ingroup HTTP
* @since 1.19
*/
class DerivativeRequest extends FauxRequest {
private WebRequest $base;
/** @var string|null */
private $ip;
/**
* @stable to call
*
* @param WebRequest $base
* @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
*/
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 getHeader( $name, $flags = 0 ) {
return $this->base->getHeader( $name, $flags );
}
public function getAllHeaders() {
return $this->base->getAllHeaders();
}
public function getSession(): Session {
return $this->base->getSession();
}
public function getSessionData( $key ) {
return $this->base->getSessionData( $key );
}
public function setSessionData( $key, $data ) {
$this->base->setSessionData( $key, $data );
}
public function getAcceptLang() {
return $this->base->getAcceptLang();
}
public function getIP(): string {
return $this->ip ?: $this->base->getIP();
}
public function setIP( $ip ) {
$this->ip = $ip;
}
public function getProtocol() {
return $this->base->getProtocol();
}
public function getUpload( $key ) {
// @phan-suppress-next-line PhanTypeMismatchReturnSuperType
return $this->base->getUpload( $key );
}
public function getElapsedTime() {
return $this->base->getElapsedTime();
}
}
/** @deprecated class alias since 1.40 */
class_alias( DerivativeRequest::class, 'DerivativeRequest' );
|