Update RELEASE-NOTES-1.34 for various backports
[lhc/web/wiklou.git] / includes / DerivativeRequest.php
1 <?php
2 /**
3 * Deal with importing all those nasty globals and things
4 *
5 * Copyright © 2003 Brion Vibber <brion@pobox.com>
6 * https://www.mediawiki.org/
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * http://www.gnu.org/copyleft/gpl.html
22 *
23 * @file
24 */
25
26 /**
27 * Similar to FauxRequest, but only fakes URL parameters and method
28 * (POST or GET) and use the base request for the remaining stuff
29 * (cookies, session and headers).
30 *
31 * @ingroup HTTP
32 * @since 1.19
33 */
34 class DerivativeRequest extends FauxRequest {
35 private $base;
36 private $ip;
37
38 /**
39 * @param WebRequest $base
40 * @param array $data Array of *non*-urlencoded key => value pairs, the
41 * fake GET/POST values
42 * @param bool $wasPosted Whether to treat the data as POST
43 */
44 public function __construct( WebRequest $base, $data, $wasPosted = false ) {
45 $this->base = $base;
46 parent::__construct( $data, $wasPosted );
47 }
48
49 public function getCookie( $key, $prefix = null, $default = null ) {
50 return $this->base->getCookie( $key, $prefix, $default );
51 }
52
53 public function getHeader( $name, $flags = 0 ) {
54 return $this->base->getHeader( $name, $flags );
55 }
56
57 public function getAllHeaders() {
58 return $this->base->getAllHeaders();
59 }
60
61 public function getSession() {
62 return $this->base->getSession();
63 }
64
65 public function getSessionData( $key ) {
66 return $this->base->getSessionData( $key );
67 }
68
69 public function setSessionData( $key, $data ) {
70 $this->base->setSessionData( $key, $data );
71 }
72
73 public function getAcceptLang() {
74 return $this->base->getAcceptLang();
75 }
76
77 public function getIP() {
78 return $this->ip ?: $this->base->getIP();
79 }
80
81 public function setIP( $ip ) {
82 $this->ip = $ip;
83 }
84
85 public function getProtocol() {
86 return $this->base->getProtocol();
87 }
88
89 public function getElapsedTime() {
90 return $this->base->getElapsedTime();
91 }
92 }