MediaWiki  REL1_19
WebRequest Class Reference

The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form, handling remove of "magic quotes" slashes, stripping illegal input characters and normalizing Unicode sequences. More...

Inheritance diagram for WebRequest:

List of all members.

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.
 escapeAppendQuery ($query)
 HTML-safe version of appendQuery().
 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.
 getFileSize ($key)
 Return the size of the upload, or 0.
 getFileTempname ($key)
 Return the path to the temporary file where PHP has stored the upload.
 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.
 getQueryValues ()
 Get the values passed in the query string.
 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.
 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 ()
static detectProtocolAndStdPort ()
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

Private Member Functions

 checkMagicQuotes ()
 If magic_quotes_gpc option is on, run the global arrays through fix_magic_quotes to strip out the stupid slashes.
fix_magic_quotes (&$arr, $topLevel=true)
 Recursively strips slashes from the given array; used for undoing the evil that is magic_quotes_gpc.
 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

 $ip
 $response

Detailed Description

The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form, handling remove of "magic quotes" slashes, 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.


Constructor & Destructor Documentation

Definition at line 53 of file WebRequest.php.

References checkMagicQuotes().

Referenced by DerivativeRequest\__construct().

Here is the call graph for this function:

Here is the caller graph for this function:


Member Function Documentation

Take an arbitrary query and rewrite the present URL to include it.

Parameters:
$queryString: query string fragment; do not include initial '?'
Returns:
String

Definition at line 652 of file WebRequest.php.

References appendQueryArray(), and wfCgiToArray().

Referenced by escapeAppendQuery().

Here is the call graph for this function:

Here is the caller graph for this function:

WebRequest::appendQueryArray ( array,
onlyquery = false 
)

Appends or replaces value of query variables.

Parameters:
$arrayArray of values to replace/add to query
$onlyqueryBool: whether to only return the query string and not the complete URL
Returns:
String

Definition at line 684 of file WebRequest.php.

References $wgTitle, getQueryValues(), and wfArrayToCGI().

Referenced by appendQuery(), and appendQueryValue().

Here is the call graph for this function:

Here is the caller graph for this function:

WebRequest::appendQueryValue ( key,
value,
onlyquery = false 
)
Parameters:
$key
$value
$onlyquerybool
Returns:
String

Definition at line 672 of file WebRequest.php.

References appendQueryArray().

Here is the call graph for this function:

If magic_quotes_gpc option is on, run the global arrays through fix_magic_quotes to strip out the stupid slashes.

WARNING: This should only be done once! Running a second time could damage the values.

Definition at line 285 of file WebRequest.php.

References fix_magic_quotes().

Referenced by __construct().

Here is the call graph for this function:

Here is the caller graph for this function:

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).

Returns:
Boolean

Reimplemented in DerivativeRequest, and FauxRequest.

Definition at line 573 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.

Parameters:
$extWhitelistarray
Returns:
bool

Reimplemented in FauxRequest.

Definition at line 885 of file WebRequest.php.

References $wgScriptExtension, IEUrlExtension\areServerVarsBad(), doSecurityRedirect(), IEUrlExtension\fixUrlForIE6(), getFullRequestURL(), and wasPosted().

Here is the call graph for this function:

static WebRequest::detectProtocol ( ) [static]
Returns:
string

Definition at line 196 of file WebRequest.php.

References detectProtocolAndStdPort().

Referenced by LoginForm\mainLoginForm(), and wfExpandUrl().

Here is the call graph for this function:

Here is the caller graph for this function:

Returns:
array

Definition at line 189 of file WebRequest.php.

Referenced by detectProtocol(), and detectServer().

Here is the caller graph for this function:

static WebRequest::detectServer ( ) [static]

Work out an appropriate URL prefix containing scheme and host, based on information detected from $_SERVER.

Returns:
string

Definition at line 157 of file WebRequest.php.

References IP\combineHostAndPort(), detectProtocolAndStdPort(), and IP\splitHostAndPort().

Referenced by WebInstaller\envGetDefaultServer(), and WebRequestTest\testDetectServer().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters:
$urlstring
Returns:
bool

Definition at line 910 of file WebRequest.php.

References $url, and echo.

Referenced by checkUrlExtension().

Here is the caller graph for this function:

HTML-safe version of appendQuery().

Parameters:
$queryString: query string fragment; do not include initial '?'
Returns:
String

Definition at line 662 of file WebRequest.php.

References appendQuery().

Here is the call graph for this function:

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.

Parameters:
$pathstring: the URL path given from the client
$basesarray: one or more URLs, optionally with $1 at the end
$keystring: if provided, the matching key in $bases will be passed on as the value of this URL parameter
Returns:
array of URL variables to interpolate; empty if no match

Definition at line 234 of file WebRequest.php.

References $matches, and $path.

& WebRequest::fix_magic_quotes ( &$  arr,
topLevel = true 
) [private]

Recursively strips slashes from the given array; used for undoing the evil that is magic_quotes_gpc.

Parameters:
$arrarray: will be modified
$topLevelbool Specifies if the array passed is from the top level of the source. In PHP5 magic_quotes only escapes the first level of keys that belong to an array.
Returns:
array the original array
See also:
http://www.php.net/manual/en/function.get-magic-quotes-gpc.php#49612

Definition at line 264 of file WebRequest.php.

Referenced by checkMagicQuotes().

Here is the caller graph for this function:

Get an array containing all request headers.

Returns:
Array mapping header name to its value

Reimplemented in DerivativeRequest.

Definition at line 832 of file WebRequest.php.

References initHeaders().

Here is the call graph for this function:

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.

Parameters:
$nameString
$defaultArray: optional default (or NULL)
Returns:
Array

Definition at line 391 of file WebRequest.php.

References getGPCVal().

Referenced by getIntArray().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters:
$nameString
$defaultBoolean
Returns:
Boolean

Definition at line 455 of file WebRequest.php.

References getVal().

Referenced by FormOptions\fetchValuesFromRequest(), and getFuzzyBool().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters:
$nameString
Returns:
Boolean

Definition at line 480 of file WebRequest.php.

References getVal().

Here is the call graph for this function:

WebRequest::getCookie ( key,
prefix = null,
default = null 
)

Get a cookie from the $_COOKIE jar.

Parameters:
$keyString: the name of the cookie
$prefixString: a prefix to use for the cookie name, if not $wgCookiePrefix
$defaultMixed: what to return if the value isn't found
Returns:
Mixed: cookie value or $default if the cookie not set

Reimplemented in DerivativeRequest, and FauxRequest.

Definition at line 585 of file WebRequest.php.

References $wgCookiePrefix, and getGPCVal().

Here is the call graph for this function:

Return the upload error.

See link for explanation http://www.php.net/manual/en/features.file-upload.errors.php

Returns:
int One of the UPLOAD_ constants, 0 if non-existent

Definition at line 1162 of file WebRequest.php.

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.

Parameters:
$keyString:
Returns:
string or NULL if no such file.

Definition at line 773 of file WebRequest.php.

References $file.

Return the size of the upload, or 0.

Deprecated:
since 1.17
Parameters:
$keyString:
Returns:
integer

Definition at line 745 of file WebRequest.php.

References $file, and wfDeprecated().

Here is the call graph for this function:

Return the path to the temporary file where PHP has stored the upload.

Parameters:
$keyString:
Returns:
string or NULL if no such file.

Definition at line 733 of file WebRequest.php.

References $file.

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.

Returns:
String

Definition at line 642 of file WebRequest.php.

References getRequestURL(), and wfExpandUrl().

Referenced by checkUrlExtension().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters:
$nameString
$defaultBoolean
Returns:
Boolean

Definition at line 468 of file WebRequest.php.

References getBool(), and getVal().

Referenced by ResourceLoaderContext\__construct().

Here is the call graph for this function:

Here is the caller graph for this function:

WebRequest::getGPCVal ( arr,
name,
default 
) [private]

Fetch a value from the given array or return $default if it's not set.

Parameters:
$arrArray
$nameString
$defaultMixed
Returns:
mixed

Definition at line 325 of file WebRequest.php.

References $data, $wgContLang, and normalizeUnicode().

Referenced by getArray(), getCookie(), and getVal().

Here is the call graph for this function:

Here is the caller graph for this function:

WebRequest::getHeader ( name)

Get a request header, or false if it isn't set.

Parameters:
$nameString: case-insensitive header name
Returns:
string|false

Reimplemented in DerivativeRequest, and FauxRequest.

Definition at line 843 of file WebRequest.php.

References initHeaders().

Here is the call graph for this function:

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.

Parameters:
$nameString
$defaultInteger
Returns:
Integer

Definition at line 427 of file WebRequest.php.

References getVal().

Referenced by FormOptions\fetchValuesFromRequest(), and getLimitOffset().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters:
$nameString
$defaultArray: option default (or NULL)
Returns:
Array of ints

Definition at line 410 of file WebRequest.php.

References getArray().

Here is the call graph for this function:

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.

Parameters:
$nameString
Returns:
Integer

Definition at line 439 of file WebRequest.php.

References getVal().

Referenced by FormOptions\fetchValuesFromRequest().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters:
$deflimitInteger: limit to use if no input and the user hasn't set the option.
$optionnameString: to specify an option other than rclimit to pull from.
Returns:
array first element is limit, second is offset

Definition at line 702 of file WebRequest.php.

References $limit, $wgUser, and getInt().

Here is the call graph for this function:

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.

Parameters:
$wantstring: If this is not 'all', then the function will return an empty array if it determines that the URL is inside a rewrite path.
Returns:
Array: Any query arguments found in path matches.

Definition at line 79 of file WebRequest.php.

References $matches, $path, $url, $wgActionPaths, $wgArticlePath, $wgContLang, $wgScript, $wgVariantArticlePath, PathRouter\add(), and wfRunHooks().

Referenced by interpolateTitle().

Here is the call graph for this function:

Here is the caller graph for this function:

Get the values passed in the query string.

No transformation is performed on the values.

Returns:
Array

Reimplemented in FauxRequest.

Definition at line 545 of file WebRequest.php.

Referenced by appendQueryArray().

Here is the caller graph for this function:

Return the path and query string portion of the request URI.

This will be suitable for use as a relative link in HTML output.

Returns:
String

Reimplemented in FauxRequest.

Definition at line 599 of file WebRequest.php.

Referenced by getFullRequestURL().

Here is the caller graph for this function:

Get data from $_SESSION.

Parameters:
$keyString: name of key in $_SESSION
Returns:
Mixed

Reimplemented in DerivativeRequest, and FauxRequest.

Definition at line 859 of file WebRequest.php.

Return the file size of the uploaded file.

Returns:
int File size or zero if non-existent

Definition at line 1135 of file WebRequest.php.

Return the path to the temporary file.

Returns:
mixed Path or null if non-existent

Definition at line 1148 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).

Parameters:
$nameString
$defaultString: optional
Returns:
String

Reimplemented in FauxRequest.

Definition at line 499 of file WebRequest.php.

References $wgContLang, and getVal().

Referenced by FormOptions\fetchValuesFromRequest().

Here is the call graph for this function:

Here is the caller graph for this function:

Return a WebRequestUpload object corresponding to the key.

Parameters:
$keystring
Returns:
WebRequestUpload

Definition at line 784 of file WebRequest.php.

Return the upload error or 0.

Parameters:
$keyString:
Returns:
integer

Definition at line 757 of file WebRequest.php.

References $file.

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().

Parameters:
$nameString
$defaultString: optional default (or NULL)
Returns:
String

Definition at line 357 of file WebRequest.php.

References getGPCVal().

Referenced by ResourceLoaderContext\__construct(), getBool(), getCheck(), getFuzzyBool(), getInt(), getIntOrNull(), getText(), FauxRequest\getText(), and getValues().

Here is the call graph for this function:

Here is the caller graph for this function:

WebRequest::getValueNames ( exclude = array())

Returns the names of all input values excluding those in $exclude.

Parameters:
$excludeArray
Returns:
array

Definition at line 535 of file WebRequest.php.

References $exclude, and getValues().

Here is the call graph for this function:

Extracts the given named values into an array.

If no arguments are given, returns all input values. No transformation is performed on the values.

Returns:
array

Reimplemented in FauxRequest.

Definition at line 513 of file WebRequest.php.

References getVal().

Referenced by getValueNames().

Here is the call graph for this function:

Here is the caller graph for this function:

WebRequest::initHeaders ( ) [private]

Initialise the header list.

Definition at line 806 of file WebRequest.php.

Referenced by getAllHeaders(), and getHeader().

Here is the caller graph for this function:

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 208 of file WebRequest.php.

References $matches, $wgUsePathInfo, and getPathInfo().

Here is the call graph for this function:

Returns whether this upload failed because of overflow of a maximum set in php.ini.

Returns:
bool

Definition at line 1176 of file WebRequest.php.

References wfShorthandToInteger().

Here is the call graph for this function:

Recursively normalizes UTF-8 strings in the given array.

Parameters:
$datastring or array
Returns:
cleaned-up version of the given
Access:
private

Definition at line 305 of file WebRequest.php.

References $data, $wgContLang, and UtfNormal\cleanUp().

Referenced by getGPCVal().

Here is the call graph for this function:

Here is the caller graph for this function:

Return a handle to WebResponse style object, for setting cookies, headers and other stuff, for Request being worked on.

Returns:
WebResponse

Definition at line 794 of file WebRequest.php.

WebRequest::setSessionData ( key,
data 
)

Set session data.

Parameters:
$keyString: name of key in $_SESSION
$dataMixed

Reimplemented in DerivativeRequest, and FauxRequest.

Definition at line 872 of file WebRequest.php.

References $data.

WebRequest::setVal ( key,
value 
)

Set an arbitrary value into our get/post data.

Parameters:
$keyString: key name to use
$valueMixed: value to set
Returns:
Mixed: old value if one was present, null otherwise

Definition at line 376 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.

Returns:
Boolean

Reimplemented in FauxRequest.

Definition at line 558 of file WebRequest.php.

Referenced by checkUrlExtension().

Here is the caller graph for this function:


Member Data Documentation

WebRequest::$headers = array()

Definition at line 39 of file WebRequest.php.

WebRequest::$ip [private]

Definition at line 51 of file WebRequest.php.

WebRequest::$response [private]

Definition at line 45 of file WebRequest.php.


The documentation for this class was generated from the following file: