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.
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.
 normalizeUnicode ($data)
 Recursively normalizes UTF-8 strings in the given array.
 getGPCVal ($arr, $name, $default)
 Fetch a value from the given array or return $default if it's not set.
 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)

Public Attributes

 $data = array()
 $headers

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.

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 50 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 478 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 518 of file WebRequest.php.

References $wgTitle, and wfArrayToCGI().

Referenced by appendQueryValue().

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

Definition at line 507 of file WebRequest.php.

References $key, and appendQueryArray().

WebRequest::checkMagicQuotes (  ) 

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.

Access:
private

Definition at line 184 of file WebRequest.php.

References $_SERVER, and 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 425 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 503 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 140 of file WebRequest.php.

References $key, and $path.

Referenced by interpolateTitle().

& WebRequest::fix_magic_quotes ( &$  arr  ) 

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
Access:
private

Definition at line 166 of file WebRequest.php.

References $key.

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 282 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 343 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 354 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 600 of file WebRequest.php.

References $key, $name, UtfNormal::cleanUp(), Sanitizer::decodeCharReferences(), and wfDebug().

WebRequest::getFileSize ( key  ) 

Return the size of the upload, or 0.

Parameters:
$key String:
Returns:
integer

Definition at line 570 of file WebRequest.php.

References $key.

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

References $key.

WebRequest::getFullRequestURL (  ) 

Return the request URI with the canonical service and hostname.

Returns:
string

Definition at line 468 of file WebRequest.php.

References $wgServer, and getRequestURL().

WebRequest::getGPCVal ( arr,
name,
default 
)

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

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

Definition at line 221 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 630 of file WebRequest.php.

References $_SERVER, and $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 317 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 301 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 328 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 536 of file WebRequest.php.

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

WebRequest::getRequestURL (  ) 

Return the path portion of the request URI.

Returns:
string

Reimplemented in FauxRequest.

Definition at line 433 of file WebRequest.php.

References $_SERVER.

Referenced by getFullRequestURL().

WebRequest::getSessionData ( key  ) 

Reimplemented in FauxRequest.

Definition at line 657 of file WebRequest.php.

References $key.

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

References $key.

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 249 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 385 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 68 of file WebRequest.php.

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

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

References $data, $key, and UtfNormal::cleanUp().

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

WebRequest::setSessionData ( key,
data 
)

Reimplemented in FauxRequest.

Definition at line 662 of file WebRequest.php.

References $data, and $key.

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

References $key.

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

References $_SERVER.


Member Data Documentation

WebRequest::$_response [private]

Definition at line 48 of file WebRequest.php.

WebRequest::$data = array()

WebRequest::$headers

Definition at line 47 of file WebRequest.php.


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

Generated on Sat Sep 5 02:08:50 2009 for MediaWiki by  doxygen 1.5.9