WebRequest Class Reference
[HTTP]

Deal with importing all those nasssty globals and things. More...

Inherited by FauxRequest.

List of all members.

Public Member Functions

 __construct ()
 interpolateTitle ()
 Check for title, action, and/or variant data in the URL and interpolate it into the GET variables.
 normalizeUnicode ($data)
 Recursively normalizes UTF-8 strings in the given array.
 getVal ($name, $default=null)
 Fetch a scalar from the input or return $default if it's not set.
 setVal ($key, $value)
 Set an aribtrary value into our get/post data.
 getArray ($name, $default=null)
 Fetch an array from the input or return $default if it's not set.
 getIntArray ($name, $default=null)
 Fetch an array of integers, or return $default if it's not set.
 getInt ($name, $default=0)
 Fetch an integer value from the input or return $default if not set.
 getIntOrNull ($name)
 Fetch an integer value from the input or return null if empty.
 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").
 getText ($name, $default= '')
 Fetch a text string from the given array or return $default if it's not set.
 getValues ()
 Extracts the given named values into an array.
 wasPosted ()
 Returns true if the present request was reached by a POST operation, false otherwise (GET, HEAD, or command-line).
 checkSessionCookie ()
 Returns true if there is a session cookie set.
 getRequestURL ()
 Return the path portion of the request URI.
 getFullRequestURL ()
 Return the request URI with the canonical service and hostname.
 appendQuery ($query)
 Take an arbitrary query and rewrite the present URL to include it.
 escapeAppendQuery ($query)
 HTML-safe version of appendQuery().
 appendQueryValue ($key, $value, $onlyquery=false)
 appendQueryArray ($array, $onlyquery=false)
 Appends or replaces value of query variables.
 getLimitOffset ($deflimit=50, $optionname= 'rclimit')
 Check for limit and offset parameters on the input, and return sensible defaults if not given.
 getFileTempname ($key)
 Return the path to the temporary file where PHP has stored the upload.
 getFileSize ($key)
 Return the size of the upload, or 0.
 getUploadError ($key)
 Return the upload error or 0.
 getFileName ($key)
 Return the original filename of the uploaded file, as reported by the submitting user agent.
 response ()
 Return a handle to WebResponse style object, for setting cookies, headers and other stuff, for Request being worked on.
 getHeader ($name)
 Get a request header, or false if it isn't set.
 getSessionData ($key)
 setSessionData ($key, $data)
 Set session data.
 isPathInfoBad ()
 Returns true if the PATH_INFO ends with an extension other than a script extension.

Protected Attributes

 $data
 $headers = array()

Private Member Functions

 extractTitle ($path, $bases, $key=false)
 Internal URL rewriting function; tries to extract page title and, optionally, one other fixed parameter value from a URL path.
fix_magic_quotes (&$arr)
 Recursively strips slashes from the given array; used for undoing the evil that is magic_quotes_gpc.
 checkMagicQuotes ()
 If magic_quotes_gpc option is on, run the global arrays through fix_magic_quotes to strip out the stupid slashes.
 getGPCVal ($arr, $name, $default)
 Fetch a value from the given array or return $default if it's not set.

Private Attributes

 $_response


Detailed Description

Deal with importing all those nasssty globals and things.

Some entry points may use this file without first enabling the autoloader. 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 45 of file WebRequest.php.


Constructor & Destructor Documentation

WebRequest::__construct (  ) 

Definition at line 49 of file WebRequest.php.

References checkMagicQuotes().


Member Function Documentation

WebRequest::appendQuery ( query  ) 

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

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

Reimplemented in FauxRequest.

Definition at line 483 of file WebRequest.php.

References $wgTitle.

Referenced by escapeAppendQuery().

WebRequest::appendQueryArray ( array,
onlyquery = false 
)

Appends or replaces value of query variables.

Parameters:
$array Array of values to replace/add to query
$onlyquery Bool: whether to only return the query string and not the complete URL
Returns:
string

Definition at line 523 of file WebRequest.php.

References $wgTitle, and wfArrayToCGI().

Referenced by appendQueryValue().

WebRequest::appendQueryValue ( key,
value,
onlyquery = false 
)

Definition at line 512 of file WebRequest.php.

References appendQueryArray().

WebRequest::checkMagicQuotes (  )  [private]

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

References fix_magic_quotes().

Referenced by __construct().

WebRequest::checkSessionCookie (  ) 

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:
bool

Reimplemented in FauxRequest.

Definition at line 430 of file WebRequest.php.

WebRequest::escapeAppendQuery ( query  ) 

HTML-safe version of appendQuery().

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

Definition at line 508 of file WebRequest.php.

References appendQuery().

WebRequest::extractTitle ( path,
bases,
key = false 
) [private]

Internal URL rewriting function; tries to extract page title and, optionally, one other fixed parameter value from a URL path.

Parameters:
$path string: the URL path given from the client
$bases array: one or more URLs, optionally with $1 at the end
$key string: 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 141 of file WebRequest.php.

References $path.

Referenced by interpolateTitle().

& WebRequest::fix_magic_quotes ( &$  arr  )  [private]

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

Parameters:
$arr array: will be modified
Returns:
array the original array

Definition at line 166 of file WebRequest.php.

Referenced by checkMagicQuotes().

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:
$name string
$default array: optional default (or NULL)
Returns:
array

Definition at line 287 of file WebRequest.php.

References $name, and getGPCVal().

Referenced by getIntArray().

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:
$name string
$default bool
Returns:
bool

Definition at line 348 of file WebRequest.php.

References $name, and getVal().

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.

Parameters:
$name string
Returns:
bool

Definition at line 359 of file WebRequest.php.

References $name, and getVal().

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.

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

Definition at line 605 of file WebRequest.php.

References $name, $wgContLang, Sanitizer::decodeCharReferences(), and wfDebug().

WebRequest::getFileSize ( key  ) 

Return the size of the upload, or 0.

Parameters:
$key String:
Returns:
integer

Definition at line 575 of file WebRequest.php.

WebRequest::getFileTempname ( key  ) 

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

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

Definition at line 563 of file WebRequest.php.

WebRequest::getFullRequestURL (  ) 

Return the request URI with the canonical service and hostname.

Returns:
string

Definition at line 473 of file WebRequest.php.

References $wgServer, and getRequestURL().

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

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

Parameters:
$arr array
$name string
$default mixed
Returns:
mixed

Definition at line 222 of file WebRequest.php.

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

Referenced by getArray(), and getVal().

WebRequest::getHeader ( name  ) 

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

Parameters:
$name String: case-insensitive header name

Reimplemented in FauxRequest.

Definition at line 637 of file WebRequest.php.

References $name.

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:
$name string
$default int
Returns:
int

Definition at line 322 of file WebRequest.php.

References $name, and getVal().

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

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:
$name string
$default array: option default (or NULL)
Returns:
array of ints

Definition at line 306 of file WebRequest.php.

References $name, and getArray().

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.

Parameters:
$name string
Returns:
int

Definition at line 333 of file WebRequest.php.

References $name, and getVal().

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.

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

Definition at line 541 of file WebRequest.php.

References $wgUser, and getInt().

WebRequest::getRequestURL (  ) 

Return the path portion of the request URI.

Returns:
string

Reimplemented in FauxRequest.

Definition at line 438 of file WebRequest.php.

Referenced by getFullRequestURL().

WebRequest::getSessionData ( key  ) 

Reimplemented in FauxRequest.

Definition at line 665 of file WebRequest.php.

WebRequest::getText ( name,
default = '' 
)

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

is 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:
$name string
$default string: optional
Returns:
string

Reimplemented in FauxRequest.

Definition at line 378 of file WebRequest.php.

References $name, $wgContLang, and getVal().

Referenced by FormOptions::fetchValuesFromRequest().

WebRequest::getUploadError ( key  ) 

Return the upload error or 0.

Parameters:
$key String:
Returns:
integer

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

Parameters:
$name string
$default string: optional default (or NULL)
Returns:
string

Definition at line 254 of file WebRequest.php.

References $name, and getGPCVal().

Referenced by getBool(), getCheck(), getInt(), getIntOrNull(), FauxRequest::getText(), getText(), and getValues().

WebRequest::getValues (  ) 

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

References $name, and getVal().

WebRequest::interpolateTitle (  ) 

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

References $path, $url, $wgActionPaths, $wgArticlePath, $wgContLang, $wgScript, $wgUsePathInfo, $wgVariantArticlePath, and extractTitle().

WebRequest::isPathInfoBad (  ) 

Returns true if the PATH_INFO ends with an extension other than a script extension.

This could confuse IE for scripts that send arbitrary data which is not HTML but may be detected as such.

Various past attempts to use the URL to make this check have generally run up against the fact that CGI does not provide a standard method to determine the URL. PATH_INFO may be mangled (e.g. if cgi.fix_pathinfo=0), but only by prefixing it with the script name and maybe some other stuff, the extension is not mangled. So this should be a reasonably portable way to perform this security check.

Also checks for anything that looks like a file extension at the end of QUERY_STRING, since IE 6 and earlier will use this to get the file type if there was no dot before the question mark (bug 28235).

Reimplemented in FauxRequest.

Definition at line 696 of file WebRequest.php.

References $ext, and $wgScriptExtension.

WebRequest::normalizeUnicode ( data  ) 

Recursively normalizes UTF-8 strings in the given array.

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

Definition at line 202 of file WebRequest.php.

References $data, and $wgContLang.

Referenced by getGPCVal().

WebRequest::response (  ) 

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

Definition at line 624 of file WebRequest.php.

WebRequest::setSessionData ( key,
data 
)

Set session data.

Parameters:
$key String Name of key in $_SESSION
$data mixed

Reimplemented in FauxRequest.

Definition at line 676 of file WebRequest.php.

References $data.

WebRequest::setVal ( key,
value 
)

Set an aribtrary value into our get/post data.

Parameters:
$key string Key name to use
$value mixed Value to set
Returns:
mixed old value if one was present, null otherwise

Definition at line 272 of file WebRequest.php.

WebRequest::wasPosted (  ) 

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:
bool

Reimplemented in FauxRequest.

Definition at line 415 of file WebRequest.php.


Member Data Documentation

WebRequest::$_response [private]

Definition at line 47 of file WebRequest.php.

WebRequest::$data [protected]

WebRequest::$headers = array() [protected]

Definition at line 46 of file WebRequest.php.


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

Generated on Sat Apr 30 22:57:53 2011 for MediaWiki by  doxygen 1.5.9