MediaWiki
REL1_24
|
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping illegal input characters and normalizing Unicode sequences. More...
Public Member Functions | |
__construct () | |
appendQuery ($query) | |
Take an arbitrary query and rewrite the present URL to include it. | |
appendQueryArray ($array, $onlyquery=false) | |
Appends or replaces value of query variables. | |
appendQueryValue ($key, $value, $onlyquery=false) | |
checkSessionCookie () | |
Returns true if there is a session cookie set. | |
checkUrlExtension ($extWhitelist=array()) | |
Check if Internet Explorer will detect an incorrect cache extension in PATH_INFO or QUERY_STRING. | |
getAllHeaders () | |
Get an array containing all request headers. | |
getArray ($name, $default=null) | |
Fetch an array from the input or return $default if it's not set. | |
getBool ($name, $default=false) | |
Fetch a boolean value from the input or return $default if not set. | |
getCheck ($name) | |
Return true if the named value is set in the input, whatever that value is (even "0"). | |
getCookie ($key, $prefix=null, $default=null) | |
Get a cookie from the $_COOKIE jar. | |
getError () | |
Return the upload error. | |
getFileName ($key) | |
Return the original filename of the uploaded file, as reported by the submitting user agent. | |
getFileTempname ($key) | |
Return the path to the temporary file where PHP has stored the upload. | |
getFloat ($name, $default=0.0) | |
Fetch a floating point value from the input or return $default if not set. | |
getFullRequestURL () | |
Return the request URI with the canonical service and hostname, path, and query string. | |
getFuzzyBool ($name, $default=false) | |
Fetch a boolean value from the input or return $default if not set. | |
getHeader ($name) | |
Get a request header, or false if it isn't set. | |
getInt ($name, $default=0) | |
Fetch an integer value from the input or return $default if not set. | |
getIntArray ($name, $default=null) | |
Fetch an array of integers, or return $default if it's not set. | |
getIntOrNull ($name) | |
Fetch an integer value from the input or return null if empty. | |
getLimitOffset ($deflimit=50, $optionname= 'rclimit') | |
Check for limit and offset parameters on the input, and return sensible defaults if not given. | |
getMethod () | |
Get the HTTP method used for this request. | |
getProtocol () | |
Get the current URL protocol (http or https) | |
getQueryValues () | |
Get the values passed in the query string. | |
getRawInput () | |
Return the raw request body, with no processing. | |
getRawPostString () | |
Return the contents of the POST with no decoding. | |
getRawQueryString () | |
Return the contents of the Query with no decoding. | |
getRequestURL () | |
Return the path and query string portion of the request URI. | |
getSessionData ($key) | |
Get data from $_SESSION. | |
getSize () | |
Return the file size of the uploaded file. | |
getTempName () | |
Return the path to the temporary file. | |
getText ($name, $default= '') | |
Fetch a text string from the given array or return $default if it's not set. | |
getUpload ($key) | |
Return a WebRequestUpload object corresponding to the key. | |
getUploadError ($key) | |
Return the upload error or 0. | |
getVal ($name, $default=null) | |
Fetch a scalar from the input or return $default if it's not set. | |
getValueNames ($exclude=array()) | |
Returns the names of all input values excluding those in $exclude. | |
getValues () | |
Extracts the given named values into an array. | |
interpolateTitle () | |
Check for title, action, and/or variant data in the URL and interpolate it into the GET variables. | |
isIniSizeOverflow () | |
Returns whether this upload failed because of overflow of a maximum set in php.ini. | |
normalizeUnicode ($data) | |
Recursively normalizes UTF-8 strings in the given array. | |
response () | |
Return a handle to WebResponse style object, for setting cookies, headers and other stuff, for Request being worked on. | |
setSessionData ($key, $data) | |
Set session data. | |
setVal ($key, $value) | |
Set an arbitrary value into our get/post data. | |
unsetVal ($key) | |
Unset an arbitrary value from our get/post data. | |
wasPosted () | |
Returns true if the present request was reached by a POST operation, false otherwise (GET, HEAD, or command-line). | |
Static Public Member Functions | |
static | detectProtocol () |
Detect the protocol from $_SERVER. | |
static | detectServer () |
Work out an appropriate URL prefix containing scheme and host, based on information detected from $_SERVER. | |
static | extractTitle ($path, $bases, $key=false) |
URL rewriting function; tries to extract page title and, optionally, one other fixed parameter value from a URL path. | |
static | getPathInfo ($want= 'all') |
Extract relevant query arguments from the http request uri's path to be merged with the normal php provided query arguments. | |
Public Attributes | |
$headers = array() | |
Protected Member Functions | |
doSecurityRedirect ($url) | |
Attempt to redirect to a URL with a QUERY_STRING that's not dangerous in IE 6. | |
Protected Attributes | |
$data | |
string | $protocol |
Cached URL protocol. | |
Private Member Functions | |
getGPCVal ($arr, $name, $default) | |
Fetch a value from the given array or return $default if it's not set. | |
initHeaders () | |
Initialise the header list. | |
Private Attributes | |
string | $ip |
Cached client IP address. | |
WebResponse | $response |
Lazy-init response object. |
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping illegal input characters and normalizing Unicode sequences.
Usually this is used via a global singleton, $wgRequest. You should not create a second WebRequest object; make a FauxRequest object if you want to pass arbitrary data to some function in place of the web input.
Definition at line 38 of file WebRequest.php.
Definition at line 56 of file WebRequest.php.
WebRequest::appendQuery | ( | $ | query | ) |
Take an arbitrary query and rewrite the present URL to include it.
string | $query | Query string fragment; do not include initial '?' |
Definition at line 709 of file WebRequest.php.
WebRequest::appendQueryArray | ( | $ | array, |
$ | onlyquery = false |
||
) |
Appends or replaces value of query variables.
array | $array | Array of values to replace/add to query |
bool | $onlyquery | Whether to only return the query string and not the complete URL |
Definition at line 730 of file WebRequest.php.
WebRequest::appendQueryValue | ( | $ | key, |
$ | value, | ||
$ | onlyquery = false |
||
) |
string | $key | |
string | $value | |
bool | $onlyquery |
Definition at line 719 of file WebRequest.php.
Returns true if there is a session cookie set.
This does not necessarily mean that the user is logged in!
If you want to check for an open session, use session_id() instead; that will also tell you if the session was opened during the current request (in which case the cookie will be sent back to the client at the end of the script run).
Reimplemented in DerivativeRequest, and FauxRequest.
Definition at line 625 of file WebRequest.php.
WebRequest::checkUrlExtension | ( | $ | extWhitelist = array() | ) |
Check if Internet Explorer will detect an incorrect cache extension in PATH_INFO or QUERY_STRING.
If the request can't be allowed, show an error message or redirect to a safer URL. Returns true if the URL is OK, and false if an error message has been shown and the request should be aborted.
array | $extWhitelist |
HttpError |
Reimplemented in FauxRequest.
Definition at line 920 of file WebRequest.php.
static WebRequest::detectProtocol | ( | ) | [static] |
Detect the protocol from $_SERVER.
This is for use prior to Setup.php, when no WebRequest object is available. At other times, use the non-static function getProtocol().
Definition at line 206 of file WebRequest.php.
static WebRequest::detectServer | ( | ) | [static] |
Work out an appropriate URL prefix containing scheme and host, based on information detected from $_SERVER.
Definition at line 164 of file WebRequest.php.
Referenced by WebInstaller\outputCss(), and WebRequestTest\testDetectServer().
WebRequest::doSecurityRedirect | ( | $ | url | ) | [protected] |
Attempt to redirect to a URL with a QUERY_STRING that's not dangerous in IE 6.
Returns true if it was successful, false otherwise.
string | $url |
Definition at line 945 of file WebRequest.php.
static WebRequest::extractTitle | ( | $ | path, |
$ | bases, | ||
$ | key = false |
||
) | [static] |
URL rewriting function; tries to extract page title and, optionally, one other fixed parameter value from a URL path.
string | $path | The URL path given from the client |
array | $bases | One or more URLs, optionally with $1 at the end |
string | $key | If provided, the matching key in $bases will be passed on as the value of this URL parameter |
Definition at line 256 of file WebRequest.php.
Get an array containing all request headers.
Reimplemented in DerivativeRequest.
Definition at line 866 of file WebRequest.php.
WebRequest::getArray | ( | $ | name, |
$ | default = null |
||
) |
Fetch an array from the input or return $default if it's not set.
If source was scalar, will return an array with a single element. If no source and no default, returns null.
string | $name | |
array | $default | Optional default (or null) |
Definition at line 383 of file WebRequest.php.
WebRequest::getBool | ( | $ | name, |
$ | default = false |
||
) |
Fetch a boolean value from the input or return $default if not set.
Guaranteed to return true or false, with normal PHP semantics for boolean interpretation of strings.
string | $name | |
bool | $default |
Definition at line 461 of file WebRequest.php.
Referenced by FormOptions\fetchValuesFromRequest().
WebRequest::getCheck | ( | $ | name | ) |
Return true if the named value is set in the input, whatever that value is (even "0").
Return false if the named value is not set. Example use is checking for the presence of check boxes in forms.
string | $name |
Definition at line 486 of file WebRequest.php.
WebRequest::getCookie | ( | $ | key, |
$ | prefix = null , |
||
$ | default = null |
||
) |
Get a cookie from the $_COOKIE jar.
string | $key | The name of the cookie |
string | $prefix | A prefix to use for the cookie name, if not $wgCookiePrefix |
mixed | $default | What to return if the value isn't found |
Reimplemented in DerivativeRequest, and FauxRequest.
Definition at line 637 of file WebRequest.php.
Return the upload error.
See link for explanation http://www.php.net/manual/en/features.file-upload.errors.php
Definition at line 1217 of file WebRequest.php.
WebRequest::getFileName | ( | $ | key | ) |
Return the original filename of the uploaded file, as reported by the submitting user agent.
HTML-style character entities are interpreted and normalized to Unicode normalization form C, in part to deal with weird input from Safari with non-ASCII filenames.
Other than this the name is not verified for being a safe filename.
string | $key |
Definition at line 806 of file WebRequest.php.
WebRequest::getFileTempname | ( | $ | key | ) |
Return the path to the temporary file where PHP has stored the upload.
string | $key |
Definition at line 779 of file WebRequest.php.
WebRequest::getFloat | ( | $ | name, |
$ | default = 0.0 |
||
) |
Fetch a floating point value from the input or return $default if not set.
Guaranteed to return a float; non-numeric input will typically return 0.
string | $name | |
float | $default |
Definition at line 448 of file WebRequest.php.
Referenced by FormOptions\fetchValuesFromRequest().
Return the request URI with the canonical service and hostname, path, and query string.
This will be suitable for use as an absolute link in HTML or other output.
If $wgServer is protocol-relative, this will return a fully qualified URL with the protocol that was used for this request.
Definition at line 699 of file WebRequest.php.
WebRequest::getFuzzyBool | ( | $ | name, |
$ | default = false |
||
) |
Fetch a boolean value from the input or return $default if not set.
Unlike getBool, the string "false" will result in boolean false, which is useful when interpreting information sent from JavaScript.
string | $name | |
bool | $default |
Definition at line 474 of file WebRequest.php.
Referenced by ResourceLoaderContext\__construct().
WebRequest::getGPCVal | ( | $ | arr, |
$ | name, | ||
$ | default | ||
) | [private] |
Fetch a value from the given array or return $default if it's not set.
array | $arr | |
string | $name | |
mixed | $default |
Definition at line 302 of file WebRequest.php.
WebRequest::getHeader | ( | $ | name | ) |
Get a request header, or false if it isn't set.
string | $name | Case-insensitive header name |
Reimplemented in DerivativeRequest, and FauxRequest.
Definition at line 877 of file WebRequest.php.
WebRequest::getInt | ( | $ | name, |
$ | default = 0 |
||
) |
Fetch an integer value from the input or return $default if not set.
Guaranteed to return an integer; non-numeric input will typically return 0.
string | $name | |
int | $default |
Definition at line 419 of file WebRequest.php.
Referenced by FormOptions\fetchValuesFromRequest().
WebRequest::getIntArray | ( | $ | name, |
$ | default = null |
||
) |
Fetch an array of integers, or return $default if it's not set.
If source was scalar, will return an array with a single element. If no source and no default, returns null. If an array is returned, contents are guaranteed to be integers.
string | $name | |
array | $default | Option default (or null) |
Definition at line 402 of file WebRequest.php.
WebRequest::getIntOrNull | ( | $ | name | ) |
Fetch an integer value from the input or return null if empty.
Guaranteed to return an integer or null; non-numeric input will typically return null.
string | $name |
Definition at line 431 of file WebRequest.php.
Referenced by FormOptions\fetchValuesFromRequest().
WebRequest::getLimitOffset | ( | $ | deflimit = 50 , |
$ | optionname = 'rclimit' |
||
) |
Check for limit and offset parameters on the input, and return sensible defaults if not given.
The limit must be positive and is capped at 5000. Offset must be positive but is not capped.
int | $deflimit | Limit to use if no input and the user hasn't set the option. |
string | $optionname | To specify an option other than rclimit to pull from. |
Definition at line 748 of file WebRequest.php.
Get the HTTP method used for this request.
Reimplemented in FauxRequest.
Definition at line 597 of file WebRequest.php.
static WebRequest::getPathInfo | ( | $ | want = 'all' | ) | [static] |
Extract relevant query arguments from the http request uri's path to be merged with the normal php provided query arguments.
Tries to use the REQUEST_URI data if available and parses it according to the wiki's configuration looking for any known pattern.
If the REQUEST_URI is not provided we'll fall back on the PATH_INFO provided by the server if any and use that to set a 'title' parameter.
string | $want | If this is not 'all', then the function will return an empty array if it determines that the URL is inside a rewrite path. |
Definition at line 81 of file WebRequest.php.
Referenced by wfThumbHandle404().
Get the current URL protocol (http or https)
Reimplemented in DerivativeRequest, and FauxRequest.
Definition at line 220 of file WebRequest.php.
Get the values passed in the query string.
No transformation is performed on the values.
Reimplemented in FauxRequest.
Definition at line 550 of file WebRequest.php.
Return the raw request body, with no processing.
Cached since some methods disallow reading the stream more than once. As stated in the php docs, this does not work with enctype="multipart/form-data".
Reimplemented in FauxRequest.
Definition at line 584 of file WebRequest.php.
Return the contents of the POST with no decoding.
Use when you need to know exactly what was sent, e.g. for an OAuth signature over the elements.
Reimplemented in FauxRequest.
Definition at line 570 of file WebRequest.php.
Return the contents of the Query with no decoding.
Use when you need to know exactly what was sent, e.g. for an OAuth signature over the elements.
Reimplemented in FauxRequest.
Definition at line 560 of file WebRequest.php.
Return the path and query string portion of the request URI.
This will be suitable for use as a relative link in HTML output.
MWException |
Reimplemented in FauxRequest.
Definition at line 652 of file WebRequest.php.
WebRequest::getSessionData | ( | $ | key | ) |
Get data from $_SESSION.
string | $key | Name of key in $_SESSION |
Reimplemented in DerivativeRequest, and FauxRequest.
Definition at line 893 of file WebRequest.php.
Return the file size of the uploaded file.
Definition at line 1190 of file WebRequest.php.
Return the path to the temporary file.
Definition at line 1203 of file WebRequest.php.
WebRequest::getText | ( | $ | name, |
$ | default = '' |
||
) |
Fetch a text string from the given array or return $default if it's not set.
Carriage returns are stripped from the text, and with some language modules there is an input transliteration applied. This should generally be used for form "<textarea>" and "<input>" fields. Used for user-supplied freeform text input (for which input transformations may be required - e.g. Esperanto x-coding).
string | $name | |
string | $default | Optional |
Reimplemented in FauxRequest.
Definition at line 504 of file WebRequest.php.
Referenced by FormOptions\fetchValuesFromRequest().
WebRequest::getUpload | ( | $ | key | ) |
Return a WebRequestUpload object corresponding to the key.
string | $key |
Definition at line 817 of file WebRequest.php.
WebRequest::getUploadError | ( | $ | key | ) |
Return the upload error or 0.
string | $key |
Definition at line 790 of file WebRequest.php.
WebRequest::getVal | ( | $ | name, |
$ | default = null |
||
) |
Fetch a scalar from the input or return $default if it's not set.
Returns a string. Arrays are discarded. Useful for non-freeform text inputs (e.g. predefined internal text keys selected by a drop-down menu). For freeform input, see getText().
string | $name | |
string | $default | Optional default (or null) |
Definition at line 333 of file WebRequest.php.
Referenced by ResourceLoaderContext\__construct(), and RequestContext\getLanguage().
WebRequest::getValueNames | ( | $ | exclude = array() | ) |
Returns the names of all input values excluding those in $exclude.
array | $exclude |
Definition at line 540 of file WebRequest.php.
Extracts the given named values into an array.
If no arguments are given, returns all input values. No transformation is performed on the values.
Reimplemented in FauxRequest.
Definition at line 518 of file WebRequest.php.
WebRequest::initHeaders | ( | ) | [private] |
Initialise the header list.
Definition at line 839 of file WebRequest.php.
Check for title, action, and/or variant data in the URL and interpolate it into the GET variables.
This should only be run after $wgContLang is available, as we may need the list of language variants to determine available variant URLs.
Definition at line 234 of file WebRequest.php.
Returns whether this upload failed because of overflow of a maximum set in php.ini.
Definition at line 1231 of file WebRequest.php.
WebRequest::normalizeUnicode | ( | $ | data | ) |
Recursively normalizes UTF-8 strings in the given array.
string | array | $data |
Definition at line 282 of file WebRequest.php.
Return a handle to WebResponse style object, for setting cookies, headers and other stuff, for Request being worked on.
Definition at line 827 of file WebRequest.php.
WebRequest::setSessionData | ( | $ | key, |
$ | data | ||
) |
Set session data.
string | $key | Name of key in $_SESSION |
mixed | $data |
Reimplemented in DerivativeRequest, and FauxRequest.
Definition at line 906 of file WebRequest.php.
WebRequest::setVal | ( | $ | key, |
$ | value | ||
) |
Set an arbitrary value into our get/post data.
string | $key | Key name to use |
mixed | $value | Value to set |
Definition at line 352 of file WebRequest.php.
WebRequest::unsetVal | ( | $ | key | ) |
Unset an arbitrary value from our get/post data.
string | $key | Key name to use |
Definition at line 364 of file WebRequest.php.
Returns true if the present request was reached by a POST operation, false otherwise (GET, HEAD, or command-line).
Note that values retrieved by the object may come from the GET URL etc even on a POST request.
Reimplemented in FauxRequest.
Definition at line 610 of file WebRequest.php.
WebRequest::$data [protected] |
Definition at line 39 of file WebRequest.php.
Definition at line 39 of file WebRequest.php.
string WebRequest::$ip [private] |
Cached client IP address.
Definition at line 49 of file WebRequest.php.
string WebRequest::$protocol [protected] |
Cached URL protocol.
Definition at line 54 of file WebRequest.php.
WebResponse WebRequest::$response [private] |
Lazy-init response object.
Definition at line 44 of file WebRequest.php.