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