Add CASCADINGSOURCES parser function
[lhc/web/wiklou.git] / includes / WebRequest.php
1 <?php
2 /**
3 * Deal with importing all those nasty globals and things
4 *
5 * Copyright © 2003 Brion Vibber <brion@pobox.com>
6 * http://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 * The WebRequest class encapsulates getting at data passed in the
28 * URL or via a POSTed form, handling remove of "magic quotes" slashes,
29 * stripping illegal input characters and normalizing Unicode sequences.
30 *
31 * Usually this is used via a global singleton, $wgRequest. You should
32 * not create a second WebRequest object; make a FauxRequest object if
33 * you want to pass arbitrary data to some function in place of the web
34 * input.
35 *
36 * @ingroup HTTP
37 */
38 class WebRequest {
39 protected $data, $headers = array();
40
41 /**
42 * Lazy-init response object
43 * @var WebResponse
44 */
45 private $response;
46
47 /**
48 * Cached client IP address
49 * @var String
50 */
51 private $ip;
52
53 /**
54 * Cached URL protocol
55 * @var string
56 */
57 protected $protocol;
58
59 public function __construct() {
60 /// @todo FIXME: This preemptive de-quoting can interfere with other web libraries
61 /// and increases our memory footprint. It would be cleaner to do on
62 /// demand; but currently we have no wrapper for $_SERVER etc.
63 $this->checkMagicQuotes();
64
65 // POST overrides GET data
66 // We don't use $_REQUEST here to avoid interference from cookies...
67 $this->data = $_POST + $_GET;
68 }
69
70 /**
71 * Extract relevant query arguments from the http request uri's path
72 * to be merged with the normal php provided query arguments.
73 * Tries to use the REQUEST_URI data if available and parses it
74 * according to the wiki's configuration looking for any known pattern.
75 *
76 * If the REQUEST_URI is not provided we'll fall back on the PATH_INFO
77 * provided by the server if any and use that to set a 'title' parameter.
78 *
79 * @param string $want If this is not 'all', then the function
80 * will return an empty array if it determines that the URL is
81 * inside a rewrite path.
82 *
83 * @return Array: Any query arguments found in path matches.
84 */
85 public static function getPathInfo( $want = 'all' ) {
86 global $wgUsePathInfo;
87 // PATH_INFO is mangled due to http://bugs.php.net/bug.php?id=31892
88 // And also by Apache 2.x, double slashes are converted to single slashes.
89 // So we will use REQUEST_URI if possible.
90 $matches = array();
91 if ( !empty( $_SERVER['REQUEST_URI'] ) ) {
92 // Slurp out the path portion to examine...
93 $url = $_SERVER['REQUEST_URI'];
94 if ( !preg_match( '!^https?://!', $url ) ) {
95 $url = 'http://unused' . $url;
96 }
97 wfSuppressWarnings();
98 $a = parse_url( $url );
99 wfRestoreWarnings();
100 if ( $a ) {
101 $path = isset( $a['path'] ) ? $a['path'] : '';
102
103 global $wgScript;
104 if ( $path == $wgScript && $want !== 'all' ) {
105 // Script inside a rewrite path?
106 // Abort to keep from breaking...
107 return $matches;
108 }
109
110 $router = new PathRouter;
111
112 // Raw PATH_INFO style
113 $router->add( "$wgScript/$1" );
114
115 if ( isset( $_SERVER['SCRIPT_NAME'] )
116 && preg_match( '/\.php5?/', $_SERVER['SCRIPT_NAME'] )
117 ) {
118 # Check for SCRIPT_NAME, we handle index.php explicitly
119 # But we do have some other .php files such as img_auth.php
120 # Don't let root article paths clober the parsing for them
121 $router->add( $_SERVER['SCRIPT_NAME'] . "/$1" );
122 }
123
124 global $wgArticlePath;
125 if ( $wgArticlePath ) {
126 $router->add( $wgArticlePath );
127 }
128
129 global $wgActionPaths;
130 if ( $wgActionPaths ) {
131 $router->add( $wgActionPaths, array( 'action' => '$key' ) );
132 }
133
134 global $wgVariantArticlePath, $wgContLang;
135 if ( $wgVariantArticlePath ) {
136 $router->add( $wgVariantArticlePath,
137 array( 'variant' => '$2' ),
138 array( '$2' => $wgContLang->getVariants() )
139 );
140 }
141
142 wfRunHooks( 'WebRequestPathInfoRouter', array( $router ) );
143
144 $matches = $router->parse( $path );
145 }
146 } elseif ( $wgUsePathInfo ) {
147 if ( isset( $_SERVER['ORIG_PATH_INFO'] ) && $_SERVER['ORIG_PATH_INFO'] != '' ) {
148 // Mangled PATH_INFO
149 // http://bugs.php.net/bug.php?id=31892
150 // Also reported when ini_get('cgi.fix_pathinfo')==false
151 $matches['title'] = substr( $_SERVER['ORIG_PATH_INFO'], 1 );
152
153 } elseif ( isset( $_SERVER['PATH_INFO'] ) && $_SERVER['PATH_INFO'] != '' ) {
154 // Regular old PATH_INFO yay
155 $matches['title'] = substr( $_SERVER['PATH_INFO'], 1 );
156 }
157 }
158
159 return $matches;
160 }
161
162 /**
163 * Work out an appropriate URL prefix containing scheme and host, based on
164 * information detected from $_SERVER
165 *
166 * @return string
167 */
168 public static function detectServer() {
169 $proto = self::detectProtocol();
170 $stdPort = $proto === 'https' ? 443 : 80;
171
172 $varNames = array( 'HTTP_HOST', 'SERVER_NAME', 'HOSTNAME', 'SERVER_ADDR' );
173 $host = 'localhost';
174 $port = $stdPort;
175 foreach ( $varNames as $varName ) {
176 if ( !isset( $_SERVER[$varName] ) ) {
177 continue;
178 }
179 $parts = IP::splitHostAndPort( $_SERVER[$varName] );
180 if ( !$parts ) {
181 // Invalid, do not use
182 continue;
183 }
184 $host = $parts[0];
185 if ( $parts[1] === false ) {
186 if ( isset( $_SERVER['SERVER_PORT'] ) ) {
187 $port = $_SERVER['SERVER_PORT'];
188 } // else leave it as $stdPort
189 } else {
190 $port = $parts[1];
191 }
192 break;
193 }
194
195 return $proto . '://' . IP::combineHostAndPort( $host, $port, $stdPort );
196 }
197
198 /**
199 * Detect the protocol from $_SERVER.
200 * This is for use prior to Setup.php, when no WebRequest object is available.
201 * At other times, use the non-static function getProtocol().
202 *
203 * @return array
204 */
205 public static function detectProtocol() {
206 if ( ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == 'on' ) ||
207 ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) &&
208 $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' ) ) {
209 return 'https';
210 } else {
211 return 'http';
212 }
213 }
214
215 /**
216 * Get the current URL protocol (http or https)
217 * @return string
218 */
219 public function getProtocol() {
220 if ( $this->protocol === null ) {
221 $this->protocol = self::detectProtocol();
222 }
223 return $this->protocol;
224 }
225
226 /**
227 * Check for title, action, and/or variant data in the URL
228 * and interpolate it into the GET variables.
229 * This should only be run after $wgContLang is available,
230 * as we may need the list of language variants to determine
231 * available variant URLs.
232 */
233 public function interpolateTitle() {
234 // bug 16019: title interpolation on API queries is useless and sometimes harmful
235 if ( defined( 'MW_API' ) ) {
236 return;
237 }
238
239 $matches = self::getPathInfo( 'title' );
240 foreach ( $matches as $key => $val ) {
241 $this->data[$key] = $_GET[$key] = $_REQUEST[$key] = $val;
242 }
243 }
244
245 /**
246 * URL rewriting function; tries to extract page title and,
247 * optionally, one other fixed parameter value from a URL path.
248 *
249 * @param string $path the URL path given from the client
250 * @param array $bases one or more URLs, optionally with $1 at the end
251 * @param string $key if provided, the matching key in $bases will be
252 * passed on as the value of this URL parameter
253 * @return array of URL variables to interpolate; empty if no match
254 */
255 static function extractTitle( $path, $bases, $key = false ) {
256 foreach ( (array)$bases as $keyValue => $base ) {
257 // Find the part after $wgArticlePath
258 $base = str_replace( '$1', '', $base );
259 $baseLen = strlen( $base );
260 if ( substr( $path, 0, $baseLen ) == $base ) {
261 $raw = substr( $path, $baseLen );
262 if ( $raw !== '' ) {
263 $matches = array( 'title' => rawurldecode( $raw ) );
264 if ( $key ) {
265 $matches[$key] = $keyValue;
266 }
267 return $matches;
268 }
269 }
270 }
271 return array();
272 }
273
274 /**
275 * Recursively strips slashes from the given array;
276 * used for undoing the evil that is magic_quotes_gpc.
277 *
278 * @param array $arr will be modified
279 * @param bool $topLevel Specifies if the array passed is from the top
280 * level of the source. In PHP5 magic_quotes only escapes the first level
281 * of keys that belong to an array.
282 * @return array the original array
283 * @see http://www.php.net/manual/en/function.get-magic-quotes-gpc.php#49612
284 */
285 private function &fix_magic_quotes( &$arr, $topLevel = true ) {
286 $clean = array();
287 foreach ( $arr as $key => $val ) {
288 if ( is_array( $val ) ) {
289 $cleanKey = $topLevel ? stripslashes( $key ) : $key;
290 $clean[$cleanKey] = $this->fix_magic_quotes( $arr[$key], false );
291 } else {
292 $cleanKey = stripslashes( $key );
293 $clean[$cleanKey] = stripslashes( $val );
294 }
295 }
296 $arr = $clean;
297 return $arr;
298 }
299
300 /**
301 * If magic_quotes_gpc option is on, run the global arrays
302 * through fix_magic_quotes to strip out the stupid slashes.
303 * WARNING: This should only be done once! Running a second
304 * time could damage the values.
305 */
306 private function checkMagicQuotes() {
307 $mustFixQuotes = function_exists( 'get_magic_quotes_gpc' )
308 && get_magic_quotes_gpc();
309 if ( $mustFixQuotes ) {
310 $this->fix_magic_quotes( $_COOKIE );
311 $this->fix_magic_quotes( $_ENV );
312 $this->fix_magic_quotes( $_GET );
313 $this->fix_magic_quotes( $_POST );
314 $this->fix_magic_quotes( $_REQUEST );
315 $this->fix_magic_quotes( $_SERVER );
316 }
317 }
318
319 /**
320 * Recursively normalizes UTF-8 strings in the given array.
321 *
322 * @param $data string|array
323 * @return array|string cleaned-up version of the given
324 * @private
325 */
326 function normalizeUnicode( $data ) {
327 if ( is_array( $data ) ) {
328 foreach ( $data as $key => $val ) {
329 $data[$key] = $this->normalizeUnicode( $val );
330 }
331 } else {
332 global $wgContLang;
333 $data = isset( $wgContLang ) ? $wgContLang->normalize( $data ) : UtfNormal::cleanUp( $data );
334 }
335 return $data;
336 }
337
338 /**
339 * Fetch a value from the given array or return $default if it's not set.
340 *
341 * @param $arr Array
342 * @param $name String
343 * @param $default Mixed
344 * @return mixed
345 */
346 private function getGPCVal( $arr, $name, $default ) {
347 # PHP is so nice to not touch input data, except sometimes:
348 # http://us2.php.net/variables.external#language.variables.external.dot-in-names
349 # Work around PHP *feature* to avoid *bugs* elsewhere.
350 $name = strtr( $name, '.', '_' );
351 if ( isset( $arr[$name] ) ) {
352 global $wgContLang;
353 $data = $arr[$name];
354 if ( isset( $_GET[$name] ) && !is_array( $data ) ) {
355 # Check for alternate/legacy character encoding.
356 if ( isset( $wgContLang ) ) {
357 $data = $wgContLang->checkTitleEncoding( $data );
358 }
359 }
360 $data = $this->normalizeUnicode( $data );
361 return $data;
362 } else {
363 return $default;
364 }
365 }
366
367 /**
368 * Fetch a scalar from the input or return $default if it's not set.
369 * Returns a string. Arrays are discarded. Useful for
370 * non-freeform text inputs (e.g. predefined internal text keys
371 * selected by a drop-down menu). For freeform input, see getText().
372 *
373 * @param $name String
374 * @param string $default optional default (or NULL)
375 * @return String
376 */
377 public function getVal( $name, $default = null ) {
378 $val = $this->getGPCVal( $this->data, $name, $default );
379 if ( is_array( $val ) ) {
380 $val = $default;
381 }
382 if ( is_null( $val ) ) {
383 return $val;
384 } else {
385 return (string)$val;
386 }
387 }
388
389 /**
390 * Set an arbitrary value into our get/post data.
391 *
392 * @param string $key key name to use
393 * @param $value Mixed: value to set
394 * @return Mixed: old value if one was present, null otherwise
395 */
396 public function setVal( $key, $value ) {
397 $ret = isset( $this->data[$key] ) ? $this->data[$key] : null;
398 $this->data[$key] = $value;
399 return $ret;
400 }
401
402 /**
403 * Unset an arbitrary value from our get/post data.
404 *
405 * @param string $key key name to use
406 * @return Mixed: old value if one was present, null otherwise
407 */
408 public function unsetVal( $key ) {
409 if ( !isset( $this->data[$key] ) ) {
410 $ret = null;
411 } else {
412 $ret = $this->data[$key];
413 unset( $this->data[$key] );
414 }
415 return $ret;
416 }
417
418 /**
419 * Fetch an array from the input or return $default if it's not set.
420 * If source was scalar, will return an array with a single element.
421 * If no source and no default, returns NULL.
422 *
423 * @param $name String
424 * @param array $default optional default (or NULL)
425 * @return Array
426 */
427 public function getArray( $name, $default = null ) {
428 $val = $this->getGPCVal( $this->data, $name, $default );
429 if ( is_null( $val ) ) {
430 return null;
431 } else {
432 return (array)$val;
433 }
434 }
435
436 /**
437 * Fetch an array of integers, or return $default if it's not set.
438 * If source was scalar, will return an array with a single element.
439 * If no source and no default, returns NULL.
440 * If an array is returned, contents are guaranteed to be integers.
441 *
442 * @param $name String
443 * @param array $default option default (or NULL)
444 * @return Array of ints
445 */
446 public function getIntArray( $name, $default = null ) {
447 $val = $this->getArray( $name, $default );
448 if ( is_array( $val ) ) {
449 $val = array_map( 'intval', $val );
450 }
451 return $val;
452 }
453
454 /**
455 * Fetch an integer value from the input or return $default if not set.
456 * Guaranteed to return an integer; non-numeric input will typically
457 * return 0.
458 *
459 * @param $name String
460 * @param $default Integer
461 * @return Integer
462 */
463 public function getInt( $name, $default = 0 ) {
464 return intval( $this->getVal( $name, $default ) );
465 }
466
467 /**
468 * Fetch an integer value from the input or return null if empty.
469 * Guaranteed to return an integer or null; non-numeric input will
470 * typically return null.
471 *
472 * @param $name String
473 * @return Integer
474 */
475 public function getIntOrNull( $name ) {
476 $val = $this->getVal( $name );
477 return is_numeric( $val )
478 ? intval( $val )
479 : null;
480 }
481
482 /**
483 * Fetch a floating point value from the input or return $default if not set.
484 * Guaranteed to return a float; non-numeric input will typically
485 * return 0.
486 *
487 * @since 1.23
488 * @param $name String
489 * @param $default Float
490 * @return Float
491 */
492 public function getFloat( $name, $default = 0 ) {
493 return floatval( $this->getVal( $name, $default ) );
494 }
495
496 /**
497 * Fetch a boolean value from the input or return $default if not set.
498 * Guaranteed to return true or false, with normal PHP semantics for
499 * boolean interpretation of strings.
500 *
501 * @param $name String
502 * @param $default Boolean
503 * @return Boolean
504 */
505 public function getBool( $name, $default = false ) {
506 return (bool)$this->getVal( $name, $default );
507 }
508
509 /**
510 * Fetch a boolean value from the input or return $default if not set.
511 * Unlike getBool, the string "false" will result in boolean false, which is
512 * useful when interpreting information sent from JavaScript.
513 *
514 * @param $name String
515 * @param $default Boolean
516 * @return Boolean
517 */
518 public function getFuzzyBool( $name, $default = false ) {
519 return $this->getBool( $name, $default ) && strcasecmp( $this->getVal( $name ), 'false' ) !== 0;
520 }
521
522 /**
523 * Return true if the named value is set in the input, whatever that
524 * value is (even "0"). Return false if the named value is not set.
525 * Example use is checking for the presence of check boxes in forms.
526 *
527 * @param $name String
528 * @return Boolean
529 */
530 public function getCheck( $name ) {
531 # Checkboxes and buttons are only present when clicked
532 # Presence connotes truth, absence false
533 return $this->getVal( $name, null ) !== null;
534 }
535
536 /**
537 * Fetch a text string from the given array or return $default if it's not
538 * set. Carriage returns are stripped from the text, and with some language
539 * modules there is an input transliteration applied. This should generally
540 * be used for form "<textarea>" and "<input>" fields. Used for
541 * user-supplied freeform text input (for which input transformations may
542 * be required - e.g. Esperanto x-coding).
543 *
544 * @param $name String
545 * @param string $default optional
546 * @return String
547 */
548 public function getText( $name, $default = '' ) {
549 global $wgContLang;
550 $val = $this->getVal( $name, $default );
551 return str_replace( "\r\n", "\n",
552 $wgContLang->recodeInput( $val ) );
553 }
554
555 /**
556 * Extracts the given named values into an array.
557 * If no arguments are given, returns all input values.
558 * No transformation is performed on the values.
559 *
560 * @return array
561 */
562 public function getValues() {
563 $names = func_get_args();
564 if ( count( $names ) == 0 ) {
565 $names = array_keys( $this->data );
566 }
567
568 $retVal = array();
569 foreach ( $names as $name ) {
570 $value = $this->getGPCVal( $this->data, $name, null );
571 if ( !is_null( $value ) ) {
572 $retVal[$name] = $value;
573 }
574 }
575 return $retVal;
576 }
577
578 /**
579 * Returns the names of all input values excluding those in $exclude.
580 *
581 * @param $exclude Array
582 * @return array
583 */
584 public function getValueNames( $exclude = array() ) {
585 return array_diff( array_keys( $this->getValues() ), $exclude );
586 }
587
588 /**
589 * Get the values passed in the query string.
590 * No transformation is performed on the values.
591 *
592 * @return Array
593 */
594 public function getQueryValues() {
595 return $_GET;
596 }
597
598 /**
599 * Return the contents of the Query with no decoding. Use when you need to
600 * know exactly what was sent, e.g. for an OAuth signature over the elements.
601 *
602 * @return String
603 */
604 public function getRawQueryString() {
605 return $_SERVER['QUERY_STRING'];
606 }
607
608 /**
609 * Return the contents of the POST with no decoding. Use when you need to
610 * know exactly what was sent, e.g. for an OAuth signature over the elements.
611 *
612 * @return String
613 */
614 public function getRawPostString() {
615 if ( !$this->wasPosted() ) {
616 return '';
617 }
618 return $this->getRawInput();
619 }
620
621 /**
622 * Return the raw request body, with no processing. Cached since some methods
623 * disallow reading the stream more than once. As stated in the php docs, this
624 * does not work with enctype="multipart/form-data".
625 *
626 * @return String
627 */
628 public function getRawInput() {
629 static $input = false;
630 if ( $input === false ) {
631 $input = file_get_contents( 'php://input' );
632 }
633 return $input;
634 }
635
636 /**
637 * Get the HTTP method used for this request.
638 *
639 * @return String
640 */
641 public function getMethod() {
642 return isset( $_SERVER['REQUEST_METHOD'] ) ? $_SERVER['REQUEST_METHOD'] : 'GET';
643 }
644
645 /**
646 * Returns true if the present request was reached by a POST operation,
647 * false otherwise (GET, HEAD, or command-line).
648 *
649 * Note that values retrieved by the object may come from the
650 * GET URL etc even on a POST request.
651 *
652 * @return Boolean
653 */
654 public function wasPosted() {
655 return $this->getMethod() == 'POST';
656 }
657
658 /**
659 * Returns true if there is a session cookie set.
660 * This does not necessarily mean that the user is logged in!
661 *
662 * If you want to check for an open session, use session_id()
663 * instead; that will also tell you if the session was opened
664 * during the current request (in which case the cookie will
665 * be sent back to the client at the end of the script run).
666 *
667 * @return Boolean
668 */
669 public function checkSessionCookie() {
670 return isset( $_COOKIE[session_name()] );
671 }
672
673 /**
674 * Get a cookie from the $_COOKIE jar
675 *
676 * @param string $key the name of the cookie
677 * @param string $prefix a prefix to use for the cookie name, if not $wgCookiePrefix
678 * @param $default Mixed: what to return if the value isn't found
679 * @return Mixed: cookie value or $default if the cookie not set
680 */
681 public function getCookie( $key, $prefix = null, $default = null ) {
682 if ( $prefix === null ) {
683 global $wgCookiePrefix;
684 $prefix = $wgCookiePrefix;
685 }
686 return $this->getGPCVal( $_COOKIE, $prefix . $key, $default );
687 }
688
689 /**
690 * Return the path and query string portion of the request URI.
691 * This will be suitable for use as a relative link in HTML output.
692 *
693 * @throws MWException
694 * @return String
695 */
696 public function getRequestURL() {
697 if ( isset( $_SERVER['REQUEST_URI'] ) && strlen( $_SERVER['REQUEST_URI'] ) ) {
698 $base = $_SERVER['REQUEST_URI'];
699 } elseif ( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] ) && strlen( $_SERVER['HTTP_X_ORIGINAL_URL'] ) ) {
700 // Probably IIS; doesn't set REQUEST_URI
701 $base = $_SERVER['HTTP_X_ORIGINAL_URL'];
702 } elseif ( isset( $_SERVER['SCRIPT_NAME'] ) ) {
703 $base = $_SERVER['SCRIPT_NAME'];
704 if ( isset( $_SERVER['QUERY_STRING'] ) && $_SERVER['QUERY_STRING'] != '' ) {
705 $base .= '?' . $_SERVER['QUERY_STRING'];
706 }
707 } else {
708 // This shouldn't happen!
709 throw new MWException( "Web server doesn't provide either " .
710 "REQUEST_URI, HTTP_X_ORIGINAL_URL or SCRIPT_NAME. Report details " .
711 "of your web server configuration to http://bugzilla.wikimedia.org/" );
712 }
713 // User-agents should not send a fragment with the URI, but
714 // if they do, and the web server passes it on to us, we
715 // need to strip it or we get false-positive redirect loops
716 // or weird output URLs
717 $hash = strpos( $base, '#' );
718 if ( $hash !== false ) {
719 $base = substr( $base, 0, $hash );
720 }
721
722 if ( $base[0] == '/' ) {
723 // More than one slash will look like it is protocol relative
724 return preg_replace( '!^/+!', '/', $base );
725 } else {
726 // We may get paths with a host prepended; strip it.
727 return preg_replace( '!^[^:]+://[^/]+/+!', '/', $base );
728 }
729 }
730
731 /**
732 * Return the request URI with the canonical service and hostname, path,
733 * and query string. This will be suitable for use as an absolute link
734 * in HTML or other output.
735 *
736 * If $wgServer is protocol-relative, this will return a fully
737 * qualified URL with the protocol that was used for this request.
738 *
739 * @return String
740 */
741 public function getFullRequestURL() {
742 return wfExpandUrl( $this->getRequestURL(), PROTO_CURRENT );
743 }
744
745 /**
746 * Take an arbitrary query and rewrite the present URL to include it
747 * @param string $query query string fragment; do not include initial '?'
748 *
749 * @return String
750 */
751 public function appendQuery( $query ) {
752 return $this->appendQueryArray( wfCgiToArray( $query ) );
753 }
754
755 /**
756 * HTML-safe version of appendQuery().
757 * @deprecated: Deprecated in 1.20, warnings in 1.21, remove in 1.22.
758 *
759 * @param string $query query string fragment; do not include initial '?'
760 * @return String
761 */
762 public function escapeAppendQuery( $query ) {
763 return htmlspecialchars( $this->appendQuery( $query ) );
764 }
765
766 /**
767 * @param $key
768 * @param $value
769 * @param $onlyquery bool
770 * @return String
771 */
772 public function appendQueryValue( $key, $value, $onlyquery = false ) {
773 return $this->appendQueryArray( array( $key => $value ), $onlyquery );
774 }
775
776 /**
777 * Appends or replaces value of query variables.
778 *
779 * @param array $array of values to replace/add to query
780 * @param bool $onlyquery whether to only return the query string and not
781 * the complete URL
782 * @return String
783 */
784 public function appendQueryArray( $array, $onlyquery = false ) {
785 global $wgTitle;
786 $newquery = $this->getQueryValues();
787 unset( $newquery['title'] );
788 $newquery = array_merge( $newquery, $array );
789 $query = wfArrayToCgi( $newquery );
790 return $onlyquery ? $query : $wgTitle->getLocalURL( $query );
791 }
792
793 /**
794 * Check for limit and offset parameters on the input, and return sensible
795 * defaults if not given. The limit must be positive and is capped at 5000.
796 * Offset must be positive but is not capped.
797 *
798 * @param $deflimit Integer: limit to use if no input and the user hasn't set the option.
799 * @param string $optionname to specify an option other than rclimit to pull from.
800 * @return array first element is limit, second is offset
801 */
802 public function getLimitOffset( $deflimit = 50, $optionname = 'rclimit' ) {
803 global $wgUser;
804
805 $limit = $this->getInt( 'limit', 0 );
806 if ( $limit < 0 ) {
807 $limit = 0;
808 }
809 if ( ( $limit == 0 ) && ( $optionname != '' ) ) {
810 $limit = $wgUser->getIntOption( $optionname );
811 }
812 if ( $limit <= 0 ) {
813 $limit = $deflimit;
814 }
815 if ( $limit > 5000 ) {
816 $limit = 5000; # We have *some* limits...
817 }
818
819 $offset = $this->getInt( 'offset', 0 );
820 if ( $offset < 0 ) {
821 $offset = 0;
822 }
823
824 return array( $limit, $offset );
825 }
826
827 /**
828 * Return the path to the temporary file where PHP has stored the upload.
829 *
830 * @param $key String:
831 * @return string or NULL if no such file.
832 */
833 public function getFileTempname( $key ) {
834 $file = new WebRequestUpload( $this, $key );
835 return $file->getTempName();
836 }
837
838 /**
839 * Return the size of the upload, or 0.
840 *
841 * @deprecated since 1.17
842 * @param $key String:
843 * @return integer
844 */
845 public function getFileSize( $key ) {
846 wfDeprecated( __METHOD__, '1.17' );
847 $file = new WebRequestUpload( $this, $key );
848 return $file->getSize();
849 }
850
851 /**
852 * Return the upload error or 0
853 *
854 * @param $key String:
855 * @return integer
856 */
857 public function getUploadError( $key ) {
858 $file = new WebRequestUpload( $this, $key );
859 return $file->getError();
860 }
861
862 /**
863 * Return the original filename of the uploaded file, as reported by
864 * the submitting user agent. HTML-style character entities are
865 * interpreted and normalized to Unicode normalization form C, in part
866 * to deal with weird input from Safari with non-ASCII filenames.
867 *
868 * Other than this the name is not verified for being a safe filename.
869 *
870 * @param $key String:
871 * @return string or NULL if no such file.
872 */
873 public function getFileName( $key ) {
874 $file = new WebRequestUpload( $this, $key );
875 return $file->getName();
876 }
877
878 /**
879 * Return a WebRequestUpload object corresponding to the key
880 *
881 * @param $key string
882 * @return WebRequestUpload
883 */
884 public function getUpload( $key ) {
885 return new WebRequestUpload( $this, $key );
886 }
887
888 /**
889 * Return a handle to WebResponse style object, for setting cookies,
890 * headers and other stuff, for Request being worked on.
891 *
892 * @return WebResponse
893 */
894 public function response() {
895 /* Lazy initialization of response object for this request */
896 if ( !is_object( $this->response ) ) {
897 $class = ( $this instanceof FauxRequest ) ? 'FauxResponse' : 'WebResponse';
898 $this->response = new $class();
899 }
900 return $this->response;
901 }
902
903 /**
904 * Initialise the header list
905 */
906 private function initHeaders() {
907 if ( count( $this->headers ) ) {
908 return;
909 }
910
911 $apacheHeaders = function_exists( 'apache_request_headers' ) ? apache_request_headers() : false;
912 if ( $apacheHeaders ) {
913 foreach ( $apacheHeaders as $tempName => $tempValue ) {
914 $this->headers[strtoupper( $tempName )] = $tempValue;
915 }
916 } else {
917 foreach ( $_SERVER as $name => $value ) {
918 if ( substr( $name, 0, 5 ) === 'HTTP_' ) {
919 $name = str_replace( '_', '-', substr( $name, 5 ) );
920 $this->headers[$name] = $value;
921 } elseif ( $name === 'CONTENT_LENGTH' ) {
922 $this->headers['CONTENT-LENGTH'] = $value;
923 }
924 }
925 }
926 }
927
928 /**
929 * Get an array containing all request headers
930 *
931 * @return Array mapping header name to its value
932 */
933 public function getAllHeaders() {
934 $this->initHeaders();
935 return $this->headers;
936 }
937
938 /**
939 * Get a request header, or false if it isn't set
940 * @param string $name case-insensitive header name
941 *
942 * @return string|bool False on failure
943 */
944 public function getHeader( $name ) {
945 $this->initHeaders();
946 $name = strtoupper( $name );
947 if ( isset( $this->headers[$name] ) ) {
948 return $this->headers[$name];
949 } else {
950 return false;
951 }
952 }
953
954 /**
955 * Get data from $_SESSION
956 *
957 * @param string $key name of key in $_SESSION
958 * @return Mixed
959 */
960 public function getSessionData( $key ) {
961 if ( !isset( $_SESSION[$key] ) ) {
962 return null;
963 }
964 return $_SESSION[$key];
965 }
966
967 /**
968 * Set session data
969 *
970 * @param string $key name of key in $_SESSION
971 * @param $data Mixed
972 */
973 public function setSessionData( $key, $data ) {
974 $_SESSION[$key] = $data;
975 }
976
977 /**
978 * Check if Internet Explorer will detect an incorrect cache extension in
979 * PATH_INFO or QUERY_STRING. If the request can't be allowed, show an error
980 * message or redirect to a safer URL. Returns true if the URL is OK, and
981 * false if an error message has been shown and the request should be aborted.
982 *
983 * @param $extWhitelist array
984 * @throws HttpError
985 * @return bool
986 */
987 public function checkUrlExtension( $extWhitelist = array() ) {
988 global $wgScriptExtension;
989 $extWhitelist[] = ltrim( $wgScriptExtension, '.' );
990 if ( IEUrlExtension::areServerVarsBad( $_SERVER, $extWhitelist ) ) {
991 if ( !$this->wasPosted() ) {
992 $newUrl = IEUrlExtension::fixUrlForIE6(
993 $this->getFullRequestURL(), $extWhitelist );
994 if ( $newUrl !== false ) {
995 $this->doSecurityRedirect( $newUrl );
996 return false;
997 }
998 }
999 throw new HttpError( 403,
1000 'Invalid file extension found in the path info or query string.' );
1001 }
1002 return true;
1003 }
1004
1005 /**
1006 * Attempt to redirect to a URL with a QUERY_STRING that's not dangerous in
1007 * IE 6. Returns true if it was successful, false otherwise.
1008 *
1009 * @param $url string
1010 * @return bool
1011 */
1012 protected function doSecurityRedirect( $url ) {
1013 header( 'Location: ' . $url );
1014 header( 'Content-Type: text/html' );
1015 $encUrl = htmlspecialchars( $url );
1016 echo <<<HTML
1017 <html>
1018 <head>
1019 <title>Security redirect</title>
1020 </head>
1021 <body>
1022 <h1>Security redirect</h1>
1023 <p>
1024 We can't serve non-HTML content from the URL you have requested, because
1025 Internet Explorer would interpret it as an incorrect and potentially dangerous
1026 content type.</p>
1027 <p>Instead, please use <a href="$encUrl">this URL</a>, which is the same as the URL you have requested, except that
1028 "&amp;*" is appended. This prevents Internet Explorer from seeing a bogus file
1029 extension.
1030 </p>
1031 </body>
1032 </html>
1033 HTML;
1034 echo "\n";
1035 return true;
1036 }
1037
1038 /**
1039 * Returns true if the PATH_INFO ends with an extension other than a script
1040 * extension. This could confuse IE for scripts that send arbitrary data which
1041 * is not HTML but may be detected as such.
1042 *
1043 * Various past attempts to use the URL to make this check have generally
1044 * run up against the fact that CGI does not provide a standard method to
1045 * determine the URL. PATH_INFO may be mangled (e.g. if cgi.fix_pathinfo=0),
1046 * but only by prefixing it with the script name and maybe some other stuff,
1047 * the extension is not mangled. So this should be a reasonably portable
1048 * way to perform this security check.
1049 *
1050 * Also checks for anything that looks like a file extension at the end of
1051 * QUERY_STRING, since IE 6 and earlier will use this to get the file type
1052 * if there was no dot before the question mark (bug 28235).
1053 *
1054 * @deprecated Use checkUrlExtension().
1055 *
1056 * @param $extWhitelist array
1057 *
1058 * @return bool
1059 */
1060 public function isPathInfoBad( $extWhitelist = array() ) {
1061 wfDeprecated( __METHOD__, '1.17' );
1062 global $wgScriptExtension;
1063 $extWhitelist[] = ltrim( $wgScriptExtension, '.' );
1064 return IEUrlExtension::areServerVarsBad( $_SERVER, $extWhitelist );
1065 }
1066
1067 /**
1068 * Parse the Accept-Language header sent by the client into an array
1069 * @return array array( languageCode => q-value ) sorted by q-value in descending order then
1070 * appearing time in the header in ascending order.
1071 * May contain the "language" '*', which applies to languages other than those explicitly listed.
1072 * This is aligned with rfc2616 section 14.4
1073 * Preference for earlier languages appears in rfc3282 as an extension to HTTP/1.1.
1074 */
1075 public function getAcceptLang() {
1076 // Modified version of code found at http://www.thefutureoftheweb.com/blog/use-accept-language-header
1077 $acceptLang = $this->getHeader( 'Accept-Language' );
1078 if ( !$acceptLang ) {
1079 return array();
1080 }
1081
1082 // Return the language codes in lower case
1083 $acceptLang = strtolower( $acceptLang );
1084
1085 // Break up string into pieces (languages and q factors)
1086 $lang_parse = null;
1087 preg_match_all( '/([a-z]{1,8}(-[a-z]{1,8})*|\*)\s*(;\s*q\s*=\s*(1(\.0{0,3})?|0(\.[0-9]{0,3})?)?)?/',
1088 $acceptLang, $lang_parse );
1089
1090 if ( !count( $lang_parse[1] ) ) {
1091 return array();
1092 }
1093
1094 $langcodes = $lang_parse[1];
1095 $qvalues = $lang_parse[4];
1096 $indices = range( 0, count( $lang_parse[1] ) - 1 );
1097
1098 // Set default q factor to 1
1099 foreach ( $indices as $index ) {
1100 if ( $qvalues[$index] === '' ) {
1101 $qvalues[$index] = 1;
1102 } elseif ( $qvalues[$index] == 0 ) {
1103 unset( $langcodes[$index], $qvalues[$index], $indices[$index] );
1104 }
1105 }
1106
1107 // Sort list. First by $qvalues, then by order. Reorder $langcodes the same way
1108 array_multisort( $qvalues, SORT_DESC, SORT_NUMERIC, $indices, $langcodes );
1109
1110 // Create a list like "en" => 0.8
1111 $langs = array_combine( $langcodes, $qvalues );
1112
1113 return $langs;
1114 }
1115
1116 /**
1117 * Fetch the raw IP from the request
1118 *
1119 * @since 1.19
1120 *
1121 * @throws MWException
1122 * @return String
1123 */
1124 protected function getRawIP() {
1125 if ( !isset( $_SERVER['REMOTE_ADDR'] ) ) {
1126 return null;
1127 }
1128
1129 if ( is_array( $_SERVER['REMOTE_ADDR'] ) || strpos( $_SERVER['REMOTE_ADDR'], ',' ) !== false ) {
1130 throw new MWException( __METHOD__ . " : Could not determine the remote IP address due to multiple values." );
1131 } else {
1132 $ipchain = $_SERVER['REMOTE_ADDR'];
1133 }
1134
1135 return IP::canonicalize( $ipchain );
1136 }
1137
1138 /**
1139 * Work out the IP address based on various globals
1140 * For trusted proxies, use the XFF client IP (first of the chain)
1141 *
1142 * @since 1.19
1143 *
1144 * @throws MWException
1145 * @return string
1146 */
1147 public function getIP() {
1148 global $wgUsePrivateIPs;
1149
1150 # Return cached result
1151 if ( $this->ip !== null ) {
1152 return $this->ip;
1153 }
1154
1155 # collect the originating ips
1156 $ip = $this->getRawIP();
1157
1158 # Append XFF
1159 $forwardedFor = $this->getHeader( 'X-Forwarded-For' );
1160 if ( $forwardedFor !== false ) {
1161 $ipchain = array_map( 'trim', explode( ',', $forwardedFor ) );
1162 $ipchain = array_reverse( $ipchain );
1163 if ( $ip ) {
1164 array_unshift( $ipchain, $ip );
1165 }
1166
1167 # Step through XFF list and find the last address in the list which is a
1168 # trusted server. Set $ip to the IP address given by that trusted server,
1169 # unless the address is not sensible (e.g. private). However, prefer private
1170 # IP addresses over proxy servers controlled by this site (more sensible).
1171 foreach ( $ipchain as $i => $curIP ) {
1172 $curIP = IP::sanitizeIP( IP::canonicalize( $curIP ) );
1173 if ( wfIsTrustedProxy( $curIP ) && isset( $ipchain[$i + 1] ) ) {
1174 if ( wfIsConfiguredProxy( $curIP ) || // bug 48919; treat IP as sane
1175 IP::isPublic( $ipchain[$i + 1] ) ||
1176 $wgUsePrivateIPs
1177 ) {
1178 $nextIP = IP::canonicalize( $ipchain[$i + 1] );
1179 if ( !$nextIP && wfIsConfiguredProxy( $ip ) ) {
1180 // We have not yet made it past CDN/proxy servers of this site,
1181 // so either they are misconfigured or there is some IP spoofing.
1182 throw new MWException( "Invalid IP given in XFF '$forwardedFor'." );
1183 }
1184 $ip = $nextIP;
1185 continue;
1186 }
1187 }
1188 break;
1189 }
1190 }
1191
1192 # Allow extensions to improve our guess
1193 wfRunHooks( 'GetIP', array( &$ip ) );
1194
1195 if ( !$ip ) {
1196 throw new MWException( "Unable to determine IP." );
1197 }
1198
1199 wfDebug( "IP: $ip\n" );
1200 $this->ip = $ip;
1201 return $ip;
1202 }
1203
1204 /**
1205 * @param string $ip
1206 * @return void
1207 * @since 1.21
1208 */
1209 public function setIP( $ip ) {
1210 $this->ip = $ip;
1211 }
1212 }
1213
1214 /**
1215 * Object to access the $_FILES array
1216 */
1217 class WebRequestUpload {
1218 protected $request;
1219 protected $doesExist;
1220 protected $fileInfo;
1221
1222 /**
1223 * Constructor. Should only be called by WebRequest
1224 *
1225 * @param $request WebRequest The associated request
1226 * @param string $key Key in $_FILES array (name of form field)
1227 */
1228 public function __construct( $request, $key ) {
1229 $this->request = $request;
1230 $this->doesExist = isset( $_FILES[$key] );
1231 if ( $this->doesExist ) {
1232 $this->fileInfo = $_FILES[$key];
1233 }
1234 }
1235
1236 /**
1237 * Return whether a file with this name was uploaded.
1238 *
1239 * @return bool
1240 */
1241 public function exists() {
1242 return $this->doesExist;
1243 }
1244
1245 /**
1246 * Return the original filename of the uploaded file
1247 *
1248 * @return mixed Filename or null if non-existent
1249 */
1250 public function getName() {
1251 if ( !$this->exists() ) {
1252 return null;
1253 }
1254
1255 global $wgContLang;
1256 $name = $this->fileInfo['name'];
1257
1258 # Safari sends filenames in HTML-encoded Unicode form D...
1259 # Horrid and evil! Let's try to make some kind of sense of it.
1260 $name = Sanitizer::decodeCharReferences( $name );
1261 $name = $wgContLang->normalize( $name );
1262 wfDebug( __METHOD__ . ": {$this->fileInfo['name']} normalized to '$name'\n" );
1263 return $name;
1264 }
1265
1266 /**
1267 * Return the file size of the uploaded file
1268 *
1269 * @return int File size or zero if non-existent
1270 */
1271 public function getSize() {
1272 if ( !$this->exists() ) {
1273 return 0;
1274 }
1275
1276 return $this->fileInfo['size'];
1277 }
1278
1279 /**
1280 * Return the path to the temporary file
1281 *
1282 * @return mixed Path or null if non-existent
1283 */
1284 public function getTempName() {
1285 if ( !$this->exists() ) {
1286 return null;
1287 }
1288
1289 return $this->fileInfo['tmp_name'];
1290 }
1291
1292 /**
1293 * Return the upload error. See link for explanation
1294 * http://www.php.net/manual/en/features.file-upload.errors.php
1295 *
1296 * @return int One of the UPLOAD_ constants, 0 if non-existent
1297 */
1298 public function getError() {
1299 if ( !$this->exists() ) {
1300 return 0; # UPLOAD_ERR_OK
1301 }
1302
1303 return $this->fileInfo['error'];
1304 }
1305
1306 /**
1307 * Returns whether this upload failed because of overflow of a maximum set
1308 * in php.ini
1309 *
1310 * @return bool
1311 */
1312 public function isIniSizeOverflow() {
1313 if ( $this->getError() == UPLOAD_ERR_INI_SIZE ) {
1314 # PHP indicated that upload_max_filesize is exceeded
1315 return true;
1316 }
1317
1318 $contentLength = $this->request->getHeader( 'CONTENT_LENGTH' );
1319 if ( $contentLength > wfShorthandToInteger( ini_get( 'post_max_size' ) ) ) {
1320 # post_max_size is exceeded
1321 return true;
1322 }
1323
1324 return false;
1325 }
1326 }
1327
1328 /**
1329 * WebRequest clone which takes values from a provided array.
1330 *
1331 * @ingroup HTTP
1332 */
1333 class FauxRequest extends WebRequest {
1334 private $wasPosted = false;
1335 private $session = array();
1336
1337 /**
1338 * @param array $data of *non*-urlencoded key => value pairs, the
1339 * fake GET/POST values
1340 * @param bool $wasPosted whether to treat the data as POST
1341 * @param $session Mixed: session array or null
1342 * @param string $protocol 'http' or 'https'
1343 * @throws MWException
1344 */
1345 public function __construct( $data = array(), $wasPosted = false, $session = null, $protocol = 'http' ) {
1346 if ( is_array( $data ) ) {
1347 $this->data = $data;
1348 } else {
1349 throw new MWException( "FauxRequest() got bogus data" );
1350 }
1351 $this->wasPosted = $wasPosted;
1352 if ( $session ) {
1353 $this->session = $session;
1354 }
1355 $this->protocol = $protocol;
1356 }
1357
1358 /**
1359 * @param $method string
1360 * @throws MWException
1361 */
1362 private function notImplemented( $method ) {
1363 throw new MWException( "{$method}() not implemented" );
1364 }
1365
1366 /**
1367 * @param $name string
1368 * @param $default string
1369 * @return string
1370 */
1371 public function getText( $name, $default = '' ) {
1372 # Override; don't recode since we're using internal data
1373 return (string)$this->getVal( $name, $default );
1374 }
1375
1376 /**
1377 * @return Array
1378 */
1379 public function getValues() {
1380 return $this->data;
1381 }
1382
1383 /**
1384 * @return array
1385 */
1386 public function getQueryValues() {
1387 if ( $this->wasPosted ) {
1388 return array();
1389 } else {
1390 return $this->data;
1391 }
1392 }
1393
1394 public function getMethod() {
1395 return $this->wasPosted ? 'POST' : 'GET';
1396 }
1397
1398 /**
1399 * @return bool
1400 */
1401 public function wasPosted() {
1402 return $this->wasPosted;
1403 }
1404
1405 public function getCookie( $key, $prefix = null, $default = null ) {
1406 return $default;
1407 }
1408
1409 public function checkSessionCookie() {
1410 return false;
1411 }
1412
1413 public function getRequestURL() {
1414 $this->notImplemented( __METHOD__ );
1415 }
1416
1417 public function getProtocol() {
1418 return $this->protocol;
1419 }
1420
1421 /**
1422 * @param string $name The name of the header to get (case insensitive).
1423 * @return bool|string
1424 */
1425 public function getHeader( $name ) {
1426 $name = strtoupper( $name );
1427 return isset( $this->headers[$name] ) ? $this->headers[$name] : false;
1428 }
1429
1430 /**
1431 * @param $name string
1432 * @param $val string
1433 */
1434 public function setHeader( $name, $val ) {
1435 $name = strtoupper( $name );
1436 $this->headers[$name] = $val;
1437 }
1438
1439 /**
1440 * @param $key
1441 * @return mixed
1442 */
1443 public function getSessionData( $key ) {
1444 if ( isset( $this->session[$key] ) ) {
1445 return $this->session[$key];
1446 }
1447 return null;
1448 }
1449
1450 /**
1451 * @param $key
1452 * @param $data
1453 */
1454 public function setSessionData( $key, $data ) {
1455 $this->session[$key] = $data;
1456 }
1457
1458 /**
1459 * @return array|Mixed|null
1460 */
1461 public function getSessionArray() {
1462 return $this->session;
1463 }
1464
1465 /**
1466 * @param array $extWhitelist
1467 * @return bool
1468 */
1469 public function isPathInfoBad( $extWhitelist = array() ) {
1470 return false;
1471 }
1472
1473 /**
1474 * FauxRequests shouldn't depend on raw request data (but that could be implemented here)
1475 * @return String
1476 */
1477 public function getRawQueryString() {
1478 return '';
1479 }
1480
1481 /**
1482 * FauxRequests shouldn't depend on raw request data (but that could be implemented here)
1483 * @return String
1484 */
1485 public function getRawPostString() {
1486 return '';
1487 }
1488
1489 /**
1490 * FauxRequests shouldn't depend on raw request data (but that could be implemented here)
1491 * @return String
1492 */
1493 public function getRawInput() {
1494 return '';
1495 }
1496
1497 /**
1498 * @param array $extWhitelist
1499 * @return bool
1500 */
1501 public function checkUrlExtension( $extWhitelist = array() ) {
1502 return true;
1503 }
1504
1505 /**
1506 * @return string
1507 */
1508 protected function getRawIP() {
1509 return '127.0.0.1';
1510 }
1511 }
1512
1513 /**
1514 * Similar to FauxRequest, but only fakes URL parameters and method
1515 * (POST or GET) and use the base request for the remaining stuff
1516 * (cookies, session and headers).
1517 *
1518 * @ingroup HTTP
1519 * @since 1.19
1520 */
1521 class DerivativeRequest extends FauxRequest {
1522 private $base;
1523
1524 /**
1525 * @param WebRequest $base
1526 * @param array $data Array of *non*-urlencoded key => value pairs, the
1527 * fake GET/POST values
1528 * @param bool $wasPosted Whether to treat the data as POST
1529 */
1530 public function __construct( WebRequest $base, $data, $wasPosted = false ) {
1531 $this->base = $base;
1532 parent::__construct( $data, $wasPosted );
1533 }
1534
1535 public function getCookie( $key, $prefix = null, $default = null ) {
1536 return $this->base->getCookie( $key, $prefix, $default );
1537 }
1538
1539 public function checkSessionCookie() {
1540 return $this->base->checkSessionCookie();
1541 }
1542
1543 public function getHeader( $name ) {
1544 return $this->base->getHeader( $name );
1545 }
1546
1547 public function getAllHeaders() {
1548 return $this->base->getAllHeaders();
1549 }
1550
1551 public function getSessionData( $key ) {
1552 return $this->base->getSessionData( $key );
1553 }
1554
1555 public function setSessionData( $key, $data ) {
1556 $this->base->setSessionData( $key, $data );
1557 }
1558
1559 public function getAcceptLang() {
1560 return $this->base->getAcceptLang();
1561 }
1562
1563 public function getIP() {
1564 return $this->base->getIP();
1565 }
1566
1567 public function getProtocol() {
1568 return $this->base->getProtocol();
1569 }
1570 }