3 * Deal with importing all those nasssty globals and things
5 * Copyright © 2003 Brion Vibber <brion@pobox.com>
6 * http://www.mediawiki.org/
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.
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.
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
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.
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
39 protected $data, $headers = array();
42 * Lazy-init response object
47 public function __construct() {
48 /// @todo Fixme: this preemptive de-quoting can interfere with other web libraries
49 /// and increases our memory footprint. It would be cleaner to do on
50 /// demand; but currently we have no wrapper for $_SERVER etc.
51 $this->checkMagicQuotes();
53 // POST overrides GET data
54 // We don't use $_REQUEST here to avoid interference from cookies...
55 $this->data
= $_POST +
$_GET;
59 * Extract the PATH_INFO variable even when it isn't a reasonable
60 * value. On some large webhosts, PATH_INFO includes the script
61 * path as well as everything after it.
63 * @param $want string: If this is not 'all', then the function
64 * will return an empty array if it determines that the URL is
65 * inside a rewrite path.
67 * @return Array: 'title' key is the title of the article.
69 static public function getPathInfo( $want = 'all' ) {
70 // PATH_INFO is mangled due to http://bugs.php.net/bug.php?id=31892
71 // And also by Apache 2.x, double slashes are converted to single slashes.
72 // So we will use REQUEST_URI if possible.
74 if ( !empty( $_SERVER['REQUEST_URI'] ) ) {
75 // Slurp out the path portion to examine...
76 $url = $_SERVER['REQUEST_URI'];
77 if ( !preg_match( '!^https?://!', $url ) ) {
78 $url = 'http://unused' . $url;
80 $a = parse_url( $url );
82 $path = isset( $a['path'] ) ?
$a['path'] : '';
85 if( $path == $wgScript && $want !== 'all' ) {
86 // Script inside a rewrite path?
87 // Abort to keep from breaking...
90 // Raw PATH_INFO style
91 $matches = self
::extractTitle( $path, "$wgScript/$1" );
93 global $wgArticlePath;
94 if( !$matches && $wgArticlePath ) {
95 $matches = self
::extractTitle( $path, $wgArticlePath );
98 global $wgActionPaths;
99 if( !$matches && $wgActionPaths ) {
100 $matches = self
::extractTitle( $path, $wgActionPaths, 'action' );
103 global $wgVariantArticlePath, $wgContLang;
104 if( !$matches && $wgVariantArticlePath ) {
105 $variantPaths = array();
106 foreach( $wgContLang->getVariants() as $variant ) {
107 $variantPaths[$variant] =
108 str_replace( '$2', $variant, $wgVariantArticlePath );
110 $matches = self
::extractTitle( $path, $variantPaths, 'variant' );
113 } elseif ( isset( $_SERVER['ORIG_PATH_INFO'] ) && $_SERVER['ORIG_PATH_INFO'] != '' ) {
115 // http://bugs.php.net/bug.php?id=31892
116 // Also reported when ini_get('cgi.fix_pathinfo')==false
117 $matches['title'] = substr( $_SERVER['ORIG_PATH_INFO'], 1 );
119 } elseif ( isset( $_SERVER['PATH_INFO'] ) && ($_SERVER['PATH_INFO'] != '') ) {
120 // Regular old PATH_INFO yay
121 $matches['title'] = substr( $_SERVER['PATH_INFO'], 1 );
128 * Check for title, action, and/or variant data in the URL
129 * and interpolate it into the GET variables.
130 * This should only be run after $wgContLang is available,
131 * as we may need the list of language variants to determine
132 * available variant URLs.
134 public function interpolateTitle() {
135 global $wgUsePathInfo;
137 // bug 16019: title interpolation on API queries is useless and sometimes harmful
138 if ( defined( 'MW_API' ) ) {
142 if ( $wgUsePathInfo ) {
143 $matches = self
::getPathInfo( 'title' );
144 foreach( $matches as $key => $val) {
145 $this->data
[$key] = $_GET[$key] = $_REQUEST[$key] = $val;
151 * Internal URL rewriting function; tries to extract page title and,
152 * optionally, one other fixed parameter value from a URL path.
154 * @param $path string: the URL path given from the client
155 * @param $bases array: one or more URLs, optionally with $1 at the end
156 * @param $key string: if provided, the matching key in $bases will be
157 * passed on as the value of this URL parameter
158 * @return array of URL variables to interpolate; empty if no match
160 private static function extractTitle( $path, $bases, $key=false ) {
161 foreach( (array)$bases as $keyValue => $base ) {
162 // Find the part after $wgArticlePath
163 $base = str_replace( '$1', '', $base );
164 $baseLen = strlen( $base );
165 if( substr( $path, 0, $baseLen ) == $base ) {
166 $raw = substr( $path, $baseLen );
168 $matches = array( 'title' => rawurldecode( $raw ) );
170 $matches[$key] = $keyValue;
180 * Recursively strips slashes from the given array;
181 * used for undoing the evil that is magic_quotes_gpc.
183 * @param $arr array: will be modified
184 * @return array the original array
186 private function &fix_magic_quotes( &$arr ) {
187 foreach( $arr as $key => $val ) {
188 if( is_array( $val ) ) {
189 $this->fix_magic_quotes( $arr[$key] );
191 $arr[$key] = stripslashes( $val );
198 * If magic_quotes_gpc option is on, run the global arrays
199 * through fix_magic_quotes to strip out the stupid slashes.
200 * WARNING: This should only be done once! Running a second
201 * time could damage the values.
203 private function checkMagicQuotes() {
204 $mustFixQuotes = function_exists( 'get_magic_quotes_gpc' )
205 && get_magic_quotes_gpc();
206 if( $mustFixQuotes ) {
207 $this->fix_magic_quotes( $_COOKIE );
208 $this->fix_magic_quotes( $_ENV );
209 $this->fix_magic_quotes( $_GET );
210 $this->fix_magic_quotes( $_POST );
211 $this->fix_magic_quotes( $_REQUEST );
212 $this->fix_magic_quotes( $_SERVER );
217 * Recursively normalizes UTF-8 strings in the given array.
219 * @param $data string or array
220 * @return cleaned-up version of the given
223 function normalizeUnicode( $data ) {
224 if( is_array( $data ) ) {
225 foreach( $data as $key => $val ) {
226 $data[$key] = $this->normalizeUnicode( $val );
230 $data = $wgContLang->normalize( $data );
236 * Fetch a value from the given array or return $default if it's not set.
239 * @param $name String
240 * @param $default Mixed
243 private function getGPCVal( $arr, $name, $default ) {
244 # PHP is so nice to not touch input data, except sometimes:
245 # http://us2.php.net/variables.external#language.variables.external.dot-in-names
246 # Work around PHP *feature* to avoid *bugs* elsewhere.
247 $name = strtr( $name, '.', '_' );
248 if( isset( $arr[$name] ) ) {
251 if( isset( $_GET[$name] ) && !is_array( $data ) ) {
252 # Check for alternate/legacy character encoding.
253 if( isset( $wgContLang ) ) {
254 $data = $wgContLang->checkTitleEncoding( $data );
257 $data = $this->normalizeUnicode( $data );
266 * Fetch a scalar from the input or return $default if it's not set.
267 * Returns a string. Arrays are discarded. Useful for
268 * non-freeform text inputs (e.g. predefined internal text keys
269 * selected by a drop-down menu). For freeform input, see getText().
271 * @param $name String
272 * @param $default String: optional default (or NULL)
275 public function getVal( $name, $default = null ) {
276 $val = $this->getGPCVal( $this->data
, $name, $default );
277 if( is_array( $val ) ) {
280 if( is_null( $val ) ) {
288 * Set an aribtrary value into our get/post data.
290 * @param $key String: key name to use
291 * @param $value Mixed: value to set
292 * @return Mixed: old value if one was present, null otherwise
294 public function setVal( $key, $value ) {
295 $ret = isset( $this->data
[$key] ) ?
$this->data
[$key] : null;
296 $this->data
[$key] = $value;
301 * Fetch an array from the input or return $default if it's not set.
302 * If source was scalar, will return an array with a single element.
303 * If no source and no default, returns NULL.
305 * @param $name String
306 * @param $default Array: optional default (or NULL)
309 public function getArray( $name, $default = null ) {
310 $val = $this->getGPCVal( $this->data
, $name, $default );
311 if( is_null( $val ) ) {
319 * Fetch an array of integers, or return $default if it's not set.
320 * If source was scalar, will return an array with a single element.
321 * If no source and no default, returns NULL.
322 * If an array is returned, contents are guaranteed to be integers.
324 * @param $name String
325 * @param $default Array: option default (or NULL)
326 * @return Array of ints
328 public function getIntArray( $name, $default = null ) {
329 $val = $this->getArray( $name, $default );
330 if( is_array( $val ) ) {
331 $val = array_map( 'intval', $val );
337 * Fetch an integer value from the input or return $default if not set.
338 * Guaranteed to return an integer; non-numeric input will typically
341 * @param $name String
342 * @param $default Integer
345 public function getInt( $name, $default = 0 ) {
346 return intval( $this->getVal( $name, $default ) );
350 * Fetch an integer value from the input or return null if empty.
351 * Guaranteed to return an integer or null; non-numeric input will
352 * typically return null.
354 * @param $name String
357 public function getIntOrNull( $name ) {
358 $val = $this->getVal( $name );
359 return is_numeric( $val )
365 * Fetch a boolean value from the input or return $default if not set.
366 * Guaranteed to return true or false, with normal PHP semantics for
367 * boolean interpretation of strings.
369 * @param $name String
370 * @param $default Boolean
373 public function getBool( $name, $default = false ) {
374 return (bool)$this->getVal( $name, $default );
378 * Fetch a boolean value from the input or return $default if not set.
379 * Unlike getBool, the string "false" will result in boolean false, which is
380 * useful when interpreting information sent from JavaScript.
382 * @param $name String
383 * @param $default Boolean
386 public function getFuzzyBool( $name, $default = false ) {
387 return $this->getBool( $name, $default ) && strcasecmp( $this->getVal( $name ), 'false' ) !== 0;
391 * Return true if the named value is set in the input, whatever that
392 * value is (even "0"). Return false if the named value is not set.
393 * Example use is checking for the presence of check boxes in forms.
395 * @param $name String
398 public function getCheck( $name ) {
399 # Checkboxes and buttons are only present when clicked
400 # Presence connotes truth, abscense false
401 $val = $this->getVal( $name, null );
402 return isset( $val );
406 * Fetch a text string from the given array or return $default if it's not
407 * set. Carriage returns are stripped from the text, and with some language
408 * modules there is an input transliteration applied. This should generally
409 * be used for form <textarea> and <input> fields. Used for user-supplied
410 * freeform text input (for which input transformations may be required - e.g.
411 * Esperanto x-coding).
413 * @param $name String
414 * @param $default String: optional
417 public function getText( $name, $default = '' ) {
419 $val = $this->getVal( $name, $default );
420 return str_replace( "\r\n", "\n",
421 $wgContLang->recodeInput( $val ) );
425 * Extracts the given named values into an array.
426 * If no arguments are given, returns all input values.
427 * No transformation is performed on the values.
429 public function getValues() {
430 $names = func_get_args();
431 if ( count( $names ) == 0 ) {
432 $names = array_keys( $this->data
);
436 foreach ( $names as $name ) {
437 $value = $this->getVal( $name );
438 if ( !is_null( $value ) ) {
439 $retVal[$name] = $value;
446 * Returns true if the present request was reached by a POST operation,
447 * false otherwise (GET, HEAD, or command-line).
449 * Note that values retrieved by the object may come from the
450 * GET URL etc even on a POST request.
454 public function wasPosted() {
455 return $_SERVER['REQUEST_METHOD'] == 'POST';
459 * Returns true if there is a session cookie set.
460 * This does not necessarily mean that the user is logged in!
462 * If you want to check for an open session, use session_id()
463 * instead; that will also tell you if the session was opened
464 * during the current request (in which case the cookie will
465 * be sent back to the client at the end of the script run).
469 public function checkSessionCookie() {
470 return isset( $_COOKIE[ session_name() ] );
474 * Get a cookie from the $_COOKIE jar
476 * @param $key String: the name of the cookie
477 * @param $prefix String: a prefix to use for the cookie name, if not $wgCookiePrefix
478 * @param $default Mixed: what to return if the value isn't found
479 * @return Mixed: cookie value or $default if the cookie not set
481 public function getCookie( $key, $prefix = null, $default = null ) {
482 if( $prefix === null ) {
483 global $wgCookiePrefix;
484 $prefix = $wgCookiePrefix;
486 return $this->getGPCVal( $_COOKIE, $prefix . $key , $default );
490 * Return the path portion of the request URI.
494 public function getRequestURL() {
495 if( isset( $_SERVER['REQUEST_URI'] ) && strlen( $_SERVER['REQUEST_URI'] ) ) {
496 $base = $_SERVER['REQUEST_URI'];
497 } elseif ( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] ) && strlen( $_SERVER['HTTP_X_ORIGINAL_URL'] ) ) {
498 // Probably IIS; doesn't set REQUEST_URI
499 $base = $_SERVER['HTTP_X_ORIGINAL_URL'];
500 } elseif( isset( $_SERVER['SCRIPT_NAME'] ) ) {
501 $base = $_SERVER['SCRIPT_NAME'];
502 if( isset( $_SERVER['QUERY_STRING'] ) && $_SERVER['QUERY_STRING'] != '' ) {
503 $base .= '?' . $_SERVER['QUERY_STRING'];
506 // This shouldn't happen!
507 throw new MWException( "Web server doesn't provide either " .
508 "REQUEST_URI, HTTP_X_ORIGINAL_URL or SCRIPT_NAME. Report details " .
509 "of your web server configuration to http://bugzilla.wikimedia.org/" );
511 // User-agents should not send a fragment with the URI, but
512 // if they do, and the web server passes it on to us, we
513 // need to strip it or we get false-positive redirect loops
514 // or weird output URLs
515 $hash = strpos( $base, '#' );
516 if( $hash !== false ) {
517 $base = substr( $base, 0, $hash );
519 if( $base{0} == '/' ) {
522 // We may get paths with a host prepended; strip it.
523 return preg_replace( '!^[^:]+://[^/]+/!', '/', $base );
528 * Return the request URI with the canonical service and hostname.
532 public function getFullRequestURL() {
534 return $wgServer . $this->getRequestURL();
538 * Take an arbitrary query and rewrite the present URL to include it
539 * @param $query String: query string fragment; do not include initial '?'
543 public function appendQuery( $query ) {
546 foreach( $_GET as $var => $val ) {
547 if ( $var == 'title' ) {
550 if ( is_array( $val ) ) {
551 /* This will happen given a request like
552 * http://en.wikipedia.org/w/index.php?title[]=Special:Userlogin&returnto[]=Main_Page
556 $basequery .= '&' . urlencode( $var ) . '=' . urlencode( $val );
558 $basequery .= '&' . $query;
561 $basequery = substr( $basequery, 1 );
562 return $wgTitle->getLocalURL( $basequery );
566 * HTML-safe version of appendQuery().
568 * @param $query String: query string fragment; do not include initial '?'
571 public function escapeAppendQuery( $query ) {
572 return htmlspecialchars( $this->appendQuery( $query ) );
575 public function appendQueryValue( $key, $value, $onlyquery = false ) {
576 return $this->appendQueryArray( array( $key => $value ), $onlyquery );
580 * Appends or replaces value of query variables.
582 * @param $array Array of values to replace/add to query
583 * @param $onlyquery Bool: whether to only return the query string and not
587 public function appendQueryArray( $array, $onlyquery = false ) {
590 unset( $newquery['title'] );
591 $newquery = array_merge( $newquery, $array );
592 $query = wfArrayToCGI( $newquery );
593 return $onlyquery ?
$query : $wgTitle->getLocalURL( $query );
597 * Check for limit and offset parameters on the input, and return sensible
598 * defaults if not given. The limit must be positive and is capped at 5000.
599 * Offset must be positive but is not capped.
601 * @param $deflimit Integer: limit to use if no input and the user hasn't set the option.
602 * @param $optionname String: to specify an option other than rclimit to pull from.
603 * @return array first element is limit, second is offset
605 public function getLimitOffset( $deflimit = 50, $optionname = 'rclimit' ) {
608 $limit = $this->getInt( 'limit', 0 );
612 if( ( $limit == 0 ) && ( $optionname != '' ) ) {
613 $limit = (int)$wgUser->getOption( $optionname );
618 if( $limit > 5000 ) {
619 $limit = 5000; # We have *some* limits...
622 $offset = $this->getInt( 'offset', 0 );
627 return array( $limit, $offset );
631 * Return the path to the temporary file where PHP has stored the upload.
633 * @param $key String:
634 * @return string or NULL if no such file.
636 public function getFileTempname( $key ) {
637 $file = new WebRequestUpload( $this, $key );
638 return $file->getTempName();
642 * Return the size of the upload, or 0.
645 * @param $key String:
648 public function getFileSize( $key ) {
649 $file = new WebRequestUpload( $this, $key );
650 return $file->getSize();
654 * Return the upload error or 0
656 * @param $key String:
659 public function getUploadError( $key ) {
660 $file = new WebRequestUpload( $this, $key );
661 return $file->getError();
665 * Return the original filename of the uploaded file, as reported by
666 * the submitting user agent. HTML-style character entities are
667 * interpreted and normalized to Unicode normalization form C, in part
668 * to deal with weird input from Safari with non-ASCII filenames.
670 * Other than this the name is not verified for being a safe filename.
672 * @param $key String:
673 * @return string or NULL if no such file.
675 public function getFileName( $key ) {
676 $file = new WebRequestUpload( $this, $key );
677 return $file->getName();
681 * Return a WebRequestUpload object corresponding to the key
684 * @return WebRequestUpload
686 public function getUpload( $key ) {
687 return new WebRequestUpload( $this, $key );
691 * Return a handle to WebResponse style object, for setting cookies,
692 * headers and other stuff, for Request being worked on.
694 * @return WebResponse
696 public function response() {
697 /* Lazy initialization of response object for this request */
698 if ( !is_object( $this->response
) ) {
699 $class = ( $this instanceof FauxRequest
) ?
'FauxResponse' : 'WebResponse';
700 $this->response
= new $class();
702 return $this->response
;
706 * Initialise the header list
708 private function initHeaders() {
709 if ( count( $this->headers
) ) {
713 if ( function_exists( 'apache_request_headers' ) ) {
714 foreach ( apache_request_headers() as $tempName => $tempValue ) {
715 $this->headers
[ strtoupper( $tempName ) ] = $tempValue;
719 foreach ( $_SERVER as $name => $value ) {
720 if ( substr( $name, 0, 5 ) === 'HTTP_' ) {
721 $name = str_replace( '_', '-', substr( $name, 5 ) );
722 $this->headers
[$name] = $value;
723 } elseif ( $name === 'CONTENT_LENGTH' ) {
724 $this->headers
['CONTENT-LENGTH'] = $value;
731 * Get an array containing all request headers
733 * @return Array mapping header name to its value
735 public function getAllHeaders() {
736 $this->initHeaders();
737 return $this->headers
;
741 * Get a request header, or false if it isn't set
742 * @param $name String: case-insensitive header name
744 public function getHeader( $name ) {
745 $name = strtoupper( $name );
746 if ( isset( $this->headers
[$name] ) ) {
747 return $this->headers
[$name];
754 * Get data from $_SESSION
756 * @param $key String: name of key in $_SESSION
759 public function getSessionData( $key ) {
760 if( !isset( $_SESSION[$key] ) ) {
763 return $_SESSION[$key];
769 * @param $key String: name of key in $_SESSION
772 public function setSessionData( $key, $data ) {
773 $_SESSION[$key] = $data;
777 * Returns true if the PATH_INFO ends with an extension other than a script
778 * extension. This could confuse IE for scripts that send arbitrary data which
779 * is not HTML but may be detected as such.
781 * Various past attempts to use the URL to make this check have generally
782 * run up against the fact that CGI does not provide a standard method to
783 * determine the URL. PATH_INFO may be mangled (e.g. if cgi.fix_pathinfo=0),
784 * but only by prefixing it with the script name and maybe some other stuff,
785 * the extension is not mangled. So this should be a reasonably portable
786 * way to perform this security check.
788 public function isPathInfoBad() {
789 global $wgScriptExtension;
791 if ( !isset( $_SERVER['PATH_INFO'] ) ) {
794 $pi = $_SERVER['PATH_INFO'];
795 $dotPos = strrpos( $pi, '.' );
796 if ( $dotPos === false ) {
799 $ext = substr( $pi, $dotPos );
800 return !in_array( $ext, array( $wgScriptExtension, '.php', '.php5' ) );
804 * Parse the Accept-Language header sent by the client into an array
805 * @return array( languageCode => q-value ) sorted by q-value in descending order
806 * May contain the "language" '*', which applies to languages other than those explicitly listed.
807 * This is aligned with rfc2616 section 14.4
809 public function getAcceptLang() {
810 // Modified version of code found at http://www.thefutureoftheweb.com/blog/use-accept-language-header
811 $acceptLang = $this->getHeader( 'Accept-Language' );
812 if ( !$acceptLang ) {
816 // Return the language codes in lower case
817 $acceptLang = strtolower( $acceptLang );
819 // Break up string into pieces (languages and q factors)
821 preg_match_all( '/([a-z]{1,8}(-[a-z]{1,8})?|\*)\s*(;\s*q\s*=\s*(1|0(\.[0-9]+)?)?)?/',
822 $acceptLang, $lang_parse );
824 if ( !count( $lang_parse[1] ) ) {
828 // Create a list like "en" => 0.8
829 $langs = array_combine( $lang_parse[1], $lang_parse[4] );
830 // Set default q factor to 1
831 foreach ( $langs as $lang => $val ) {
834 } else if ( $val == 0 ) {
835 unset($langs[$lang]);
840 arsort( $langs, SORT_NUMERIC
);
846 * Object to access the $_FILES array
848 class WebRequestUpload
{
850 protected $doesExist;
854 * Constructor. Should only be called by WebRequest
856 * @param $request WebRequest The associated request
857 * @param $key string Key in $_FILES array (name of form field)
859 public function __construct( $request, $key ) {
860 $this->request
= $request;
861 $this->doesExist
= isset( $_FILES[$key] );
862 if ( $this->doesExist
) {
863 $this->fileInfo
= $_FILES[$key];
868 * Return whether a file with this name was uploaded.
872 public function exists() {
873 return $this->doesExist
;
877 * Return the original filename of the uploaded file
879 * @return mixed Filename or null if non-existent
881 public function getName() {
882 if ( !$this->exists() ) {
887 $name = $this->fileInfo
['name'];
889 # Safari sends filenames in HTML-encoded Unicode form D...
890 # Horrid and evil! Let's try to make some kind of sense of it.
891 $name = Sanitizer
::decodeCharReferences( $name );
892 $name = $wgContLang->normalize( $name );
893 wfDebug( __METHOD__
. ": {$this->fileInfo['name']} normalized to '$name'\n" );
898 * Return the file size of the uploaded file
900 * @return int File size or zero if non-existent
902 public function getSize() {
903 if ( !$this->exists() ) {
907 return $this->fileInfo
['size'];
911 * Return the path to the temporary file
913 * @return mixed Path or null if non-existent
915 public function getTempName() {
916 if ( !$this->exists() ) {
920 return $this->fileInfo
['tmp_name'];
924 * Return the upload error. See link for explanation
925 * http://www.php.net/manual/en/features.file-upload.errors.php
927 * @return int One of the UPLOAD_ constants, 0 if non-existent
929 public function getError() {
930 if ( !$this->exists() ) {
931 return 0; # UPLOAD_ERR_OK
934 return $this->fileInfo
['error'];
938 * Returns whether this upload failed because of overflow of a maximum set
943 public function isIniSizeOverflow() {
944 if ( $this->getError() == UPLOAD_ERR_INI_SIZE
) {
945 # PHP indicated that upload_max_filesize is exceeded
949 $contentLength = $this->request
->getHeader( 'CONTENT_LENGTH' );
950 if ( $contentLength > wfShorthandToInteger( ini_get( 'post_max_size' ) ) ) {
951 # post_max_size is exceeded
960 * WebRequest clone which takes values from a provided array.
964 class FauxRequest
extends WebRequest
{
965 private $wasPosted = false;
966 private $session = array();
969 * @param $data Array of *non*-urlencoded key => value pairs, the
970 * fake GET/POST values
971 * @param $wasPosted Bool: whether to treat the data as POST
972 * @param $session Mixed: session array or null
974 public function __construct( $data, $wasPosted = false, $session = null ) {
975 if( is_array( $data ) ) {
978 throw new MWException( "FauxRequest() got bogus data" );
980 $this->wasPosted
= $wasPosted;
982 $this->session
= $session;
985 private function notImplemented( $method ) {
986 throw new MWException( "{$method}() not implemented" );
989 public function getText( $name, $default = '' ) {
990 # Override; don't recode since we're using internal data
991 return (string)$this->getVal( $name, $default );
994 public function getValues() {
998 public function wasPosted() {
999 return $this->wasPosted
;
1002 public function checkSessionCookie() {
1006 public function getRequestURL() {
1007 $this->notImplemented( __METHOD__
);
1010 public function appendQuery( $query ) {
1013 foreach( $this->data
as $var => $val ) {
1014 if ( $var == 'title' ) {
1017 if ( is_array( $val ) ) {
1018 /* This will happen given a request like
1019 * http://en.wikipedia.org/w/index.php?title[]=Special:Userlogin&returnto[]=Main_Page
1023 $basequery .= '&' . urlencode( $var ) . '=' . urlencode( $val );
1025 $basequery .= '&' . $query;
1028 $basequery = substr( $basequery, 1 );
1029 return $wgTitle->getLocalURL( $basequery );
1032 public function getHeader( $name ) {
1033 return isset( $this->headers
[$name] ) ?
$this->headers
[$name] : false;
1036 public function setHeader( $name, $val ) {
1037 $this->headers
[$name] = $val;
1040 public function getSessionData( $key ) {
1041 if( isset( $this->session
[$key] ) )
1042 return $this->session
[$key];
1045 public function setSessionData( $key, $data ) {
1046 $this->session
[$key] = $data;
1049 public function isPathInfoBad() {