Jump to content

Extension:PhpTags Functions/Functions/Useful/WebRequest

From mediawiki.org

The WebRequest class is wrapper of original WebRequest class that which 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.

Note Note: Parser's cache will be disabled on page if the WebRequest class used
class WebRequest {

    /* Methods */
    static array getArray( $name, $default = null )
    static bool getBool( $name, $default = false )
    static bool getCheck( $name )
    static mixed getCookie( $key, $default = null )
    static int getInt( $name, $default = 0 )
    static string getText( $name, $default = '' )
    static mixed getVal( $name, $default = null )
    static bool getValues( ... )
    static bool wasPosted()
}

Methods

[edit]

getArray

[edit]
static array WebRequest::getArray( $name, $default = null )
Description

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.

getBool

[edit]
static bool WebRequest::getBool( $name, $default = false )
Description

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.

getCheck

[edit]
static bool WebRequest::getCheck( $name )
Description

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.

getCookie

[edit]
static mixed WebRequest::getCookie( $key, $default = null )
Description

Get a cookie from the $_COOKIE jar.

Note Note: This function always use ext.phptags. prefix with $key

getInt

[edit]
static int WebRequest::getInt( $key, $default = 0 )
Description

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.

getText

[edit]
static string WebRequest::getText( $name, $default = '' )
Description

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.

getVal

[edit]
static mixed WebRequest::getVal( $name, $default = null )
Description

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

getValues

[edit]
static bool  WebRequest::getValues( ... )
Description

Extracts the given named values into an array. If no arguments are given, returns all input values.

wasPosted

[edit]
static bool  WebRequest::wasPosted()
Description

Returns true if the present request was reached by a POST operation, false otherwise (GET or HEAD).

Example

[edit]

http://test.foxway.org/wiki/PhpTags/WebRequest