MediaWiki  1.34.0
WebRequest Class Reference

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

Inheritance diagram for WebRequest:
Collaboration diagram for WebRequest:

Public Member Functions

 __construct ()
 
 appendQueryArray ( $array)
 Appends or replaces value of query variables. More...
 
 appendQueryValue ( $key, $value)
 
 checkUrlExtension ( $extWhitelist=[])
 Check if Internet Explorer will detect an incorrect cache extension in PATH_INFO or QUERY_STRING. More...
 
 getAcceptLang ()
 Parse the Accept-Language header sent by the client into an array. More...
 
 getAllHeaders ()
 Get an array containing all request headers. More...
 
 getArray ( $name, $default=null)
 Fetch an array from the input or return $default if it's not set. More...
 
 getBool ( $name, $default=false)
 Fetch a boolean value from the input or return $default if not set. More...
 
 getCheck ( $name)
 Return true if the named value is set in the input, whatever that value is (even "0"). More...
 
 getCookie ( $key, $prefix=null, $default=null)
 Get a cookie from the $_COOKIE jar. More...
 
 getElapsedTime ()
 Get the number of seconds to have elapsed since request start, in fractional seconds, with microsecond resolution. More...
 
 getFileName ( $key)
 Return the original filename of the uploaded file, as reported by the submitting user agent. More...
 
 getFileTempname ( $key)
 Return the path to the temporary file where PHP has stored the upload. More...
 
 getFloat ( $name, $default=0.0)
 Fetch a floating point value from the input or return $default if not set. More...
 
 getFullRequestURL ()
 Return the request URI with the canonical service and hostname, path, and query string. More...
 
 getFuzzyBool ( $name, $default=false)
 Fetch a boolean value from the input or return $default if not set. More...
 
 getHeader ( $name, $flags=0)
 Get a request header, or false if it isn't set. More...
 
 getInt ( $name, $default=0)
 Fetch an integer value from the input or return $default if not set. More...
 
 getIntArray ( $name, $default=null)
 Fetch an array of integers, or return $default if it's not set. More...
 
 getIntOrNull ( $name)
 Fetch an integer value from the input or return null if empty. More...
 
 getIP ()
 Work out the IP address based on various globals For trusted proxies, use the XFF client IP (first of the chain) More...
 
 getLimitOffset ( $deflimit=50, $optionname='rclimit')
 Check for limit and offset parameters on the input, and return sensible defaults if not given. More...
 
 getMethod ()
 Get the HTTP method used for this request. More...
 
 getPostValues ()
 Get the values passed via POST. More...
 
 getProtocol ()
 Get the current URL protocol (http or https) More...
 
 getQueryValues ()
 Get the values passed in the query string and the path router parameters. More...
 
 getQueryValuesOnly ()
 Get the values passed in the query string only, not including the path router parameters. More...
 
 getRawInput ()
 Return the raw request body, with no processing. More...
 
 getRawPostString ()
 Return the contents of the POST with no decoding. More...
 
 getRawQueryString ()
 Return the contents of the Query with no decoding. More...
 
 getRawVal ( $name, $default=null)
 Fetch a scalar from the input without normalization, or return $default if it's not set. More...
 
 getRequestURL ()
 Return the path and query string portion of the request URI. More...
 
 getSession ()
 Return the session for this request. More...
 
 getSessionData ( $key)
 Get data from the session. More...
 
 getSessionId ()
 Get the session id for this request, if any. More...
 
 getText ( $name, $default='')
 Fetch a text string from the given array or return $default if it's not set. More...
 
 getUpload ( $key)
 Return a WebRequestUpload object corresponding to the key. More...
 
 getUploadError ( $key)
 Return the upload error or 0. More...
 
 getVal ( $name, $default=null)
 Fetch a scalar from the input or return $default if it's not set. More...
 
 getValueNames ( $exclude=[])
 Returns the names of all input values excluding those in $exclude. More...
 
 getValues ()
 Extracts the given named values into an array. More...
 
 hasSafeMethod ()
 Check if this request uses a "safe" HTTP method. More...
 
 interpolateTitle ()
 Check for title, action, and/or variant data in the URL and interpolate it into the GET variables. More...
 
 isSafeRequest ()
 Whether this request should be identified as being "safe". More...
 
 markAsSafeRequest ()
 Mark this request as identified as being nullipotent even if it is a POST request. More...
 
 normalizeUnicode ( $data)
 Recursively normalizes UTF-8 strings in the given array. More...
 
 response ()
 Return a handle to WebResponse style object, for setting cookies, headers and other stuff, for Request being worked on. More...
 
 setIP ( $ip)
 
 setSessionData ( $key, $data)
 Set session data. More...
 
 setSessionId (SessionId $sessionId)
 Set the session for this request. More...
 
 setVal ( $key, $value)
 Set an arbitrary value into our get/post data. More...
 
 unsetVal ( $key)
 Unset an arbitrary value from our get/post data. More...
 
 wasPosted ()
 Returns true if the present request was reached by a POST operation, false otherwise (GET, HEAD, or command-line). More...
 

Static Public Member Functions

static detectProtocol ()
 Detect the protocol from $_SERVER. More...
 
static detectServer ()
 Work out an appropriate URL prefix containing scheme and host, based on information detected from $_SERVER. More...
 
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. More...
 
static getGlobalRequestURL ()
 Return the path and query string portion of the main request URI. More...
 
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. More...
 
static getRequestId ()
 Get the unique request ID. More...
 
static overrideRequestId ( $id)
 Override the unique request ID. More...
 

Public Attributes

const GETHEADER_LIST = 1
 Flag to make WebRequest::getHeader return an array of values. More...
 

Protected Member Functions

 doSecurityRedirect ( $url)
 Attempt to redirect to a URL with a QUERY_STRING that's not dangerous in IE 6. More...
 
 getRawIP ()
 Fetch the raw IP from the request. More...
 
 initHeaders ()
 Initialise the header list. More...
 

Protected Attributes

array $data
 The parameters from $_GET, $_POST and the path router. More...
 
array $headers = []
 Lazy-initialized request headers indexed by upper-case header name. More...
 
bool $markedAsSafe = false
 Whether this HTTP request is "safe" (even if it is an HTTP post) More...
 
string $protocol
 Cached URL protocol. More...
 
array $queryAndPathParams
 The parameters from $_GET. More...
 
 $queryParams
 The parameters from $_GET only. More...
 
float $requestTime
 The timestamp of the start of the request, with microsecond precision. More...
 
SessionId null $sessionId = null
 Session ID to use for this request. More...
 

Private Member Functions

 getGPCVal ( $arr, $name, $default)
 Fetch a value from the given array or return $default if it's not set. More...
 

Private Attributes

string $ip
 Cached client IP address. More...
 
WebResponse $response
 Lazy-init response object. More...
 

Static Private Attributes

static string $reqId
 The unique request ID. More...
 

Detailed Description

The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping illegal input characters and normalizing Unicode sequences.

Definition at line 42 of file WebRequest.php.

Constructor & Destructor Documentation

◆ __construct()

WebRequest::__construct ( )

Definition at line 116 of file WebRequest.php.

Member Function Documentation

◆ appendQueryArray()

WebRequest::appendQueryArray (   $array)

Appends or replaces value of query variables.

Parameters
array$arrayArray of values to replace/add to query
Returns
string

Definition at line 940 of file WebRequest.php.

References getQueryValues(), and wfArrayToCgi().

Referenced by appendQueryValue().

◆ appendQueryValue()

WebRequest::appendQueryValue (   $key,
  $value 
)
Parameters
string$key
string$value
Returns
string

Definition at line 930 of file WebRequest.php.

References appendQueryArray().

◆ checkUrlExtension()

WebRequest::checkUrlExtension (   $extWhitelist = [])

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
array$extWhitelist
Exceptions
HttpError
Returns
bool

Reimplemented in FauxRequest.

Definition at line 1137 of file WebRequest.php.

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

◆ detectProtocol()

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

Returns
string

Definition at line 274 of file WebRequest.php.

Referenced by detectServer(), and getProtocol().

◆ detectServer()

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

References $wgAssumeProxiesUseDefaultProtocolPorts, IP\combineHostAndPort(), detectProtocol(), and IP\splitHostAndPort().

Referenced by WebInstaller\envGetDefaultServer().

◆ doSecurityRedirect()

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
string$url
Returns
bool

Definition at line 1161 of file WebRequest.php.

Referenced by checkUrlExtension().

◆ extractTitle()

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
string$pathThe URL path given from the client
array$basesOne or more URLs, optionally with $1 at the end
string | bool$keyIf provided, the matching key in $bases will be passed on as the value of this URL parameter
Returns
array Array of URL variables to interpolate; empty if no match

Definition at line 374 of file WebRequest.php.

References $base, $matches, and $path.

◆ getAcceptLang()

WebRequest::getAcceptLang ( )

Parse the Accept-Language header sent by the client into an array.

Returns
array [ languageCode => q-value ] sorted by q-value in descending order then appearing time in the header in ascending order. May contain the "language" '*', which applies to languages other than those explicitly listed. This is aligned with rfc2616 section 14.4 Preference for earlier languages appears in rfc3282 as an extension to HTTP/1.1.

Reimplemented in DerivativeRequest.

Definition at line 1197 of file WebRequest.php.

◆ getAllHeaders()

WebRequest::getAllHeaders ( )

Get an array containing all request headers.

Returns
array Mapping header name to its value

Reimplemented in DerivativeRequest.

Definition at line 1075 of file WebRequest.php.

References $headers, and initHeaders().

◆ getArray()

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
string$name
array | null$defaultOptional default (or null)
Returns
array|null

Definition at line 533 of file WebRequest.php.

References getGPCVal().

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

◆ getBool()

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

Definition at line 611 of file WebRequest.php.

References getRawVal().

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

◆ getCheck()

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

Definition at line 637 of file WebRequest.php.

References getRawVal().

Referenced by HTMLFormField\isSubmitAttempt().

◆ getCookie()

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

Get a cookie from the $_COOKIE jar.

Parameters
string$keyThe name of the cookie
string | null$prefixA prefix to use for the cookie name, if not $wgCookiePrefix
mixed | null$defaultWhat to return if the value isn't found
Returns
mixed Cookie value or $default if the cookie not set

Reimplemented in FauxRequest, and DerivativeRequest.

Definition at line 839 of file WebRequest.php.

References $wgCookiePrefix, and getGPCVal().

Referenced by MediaWiki\Block\BlockManager\getBlockFromCookieValue(), and MediaWiki\Session\ImmutableSessionProviderWithCookie\getSessionIdFromCookie().

◆ getElapsedTime()

WebRequest::getElapsedTime ( )

Get the number of seconds to have elapsed since request start, in fractional seconds, with microsecond resolution.

Returns
float
Since
1.25

Reimplemented in DerivativeRequest.

Definition at line 291 of file WebRequest.php.

References $requestTime.

◆ getFileName()

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
string$key
Returns
string|null String or null if no such file.

Definition at line 1015 of file WebRequest.php.

References $file.

◆ getFileTempname()

WebRequest::getFileTempname (   $key)

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

Parameters
string$key
Returns
string|null String or null if no such file.

Definition at line 988 of file WebRequest.php.

References $file.

◆ getFloat()

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.

Since
1.23
Parameters
string$name
float$default
Returns
float

Definition at line 598 of file WebRequest.php.

References getRawVal().

Referenced by FormOptions\fetchValuesFromRequest().

◆ getFullRequestURL()

WebRequest::getFullRequestURL ( )

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 of this request object.

Returns
string

Definition at line 914 of file WebRequest.php.

References getProtocol(), getRequestURL(), PROTO_HTTP, PROTO_HTTPS, and wfGetServerUrl().

Referenced by checkUrlExtension().

◆ getFuzzyBool()

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

Definition at line 624 of file WebRequest.php.

References getBool(), and getRawVal().

◆ getGlobalRequestURL()

static WebRequest::getGlobalRequestURL ( )
static

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

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

Exceptions
MWException
Returns
string

Definition at line 854 of file WebRequest.php.

References $base.

Referenced by MediaWiki\HeaderCallback\callback(), getRequestURL(), MediaWiki\Rest\RequestFromGlobals\getUri(), and MWExceptionHandler\handleFatalError().

◆ getGPCVal()

WebRequest::getGPCVal (   $arr,
  $name,
  $default 
)
private

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

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

Definition at line 421 of file WebRequest.php.

References $data, and normalizeUnicode().

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

◆ getHeader()

WebRequest::getHeader (   $name,
  $flags = 0 
)

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

Parameters
string$nameCase-insensitive header name
int$flagsBitwise combination of: WebRequest::GETHEADER_LIST Treat the header as a comma-separated list of values, as described in RFC 2616 § 4.2. (since 1.26).
Returns
string|array|bool False if header is unset; otherwise the header value(s) as either a string (the default) or an array, if WebRequest::GETHEADER_LIST flag was set.

Reimplemented in DerivativeRequest.

Definition at line 1092 of file WebRequest.php.

References initHeaders().

Referenced by MediaWiki\Block\BlockManager\getAdditionalIpBlocks(), and PageDataRequestHandler\httpContentNegotiation().

◆ getInt()

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

Definition at line 569 of file WebRequest.php.

References getRawVal().

Referenced by FormOptions\fetchValuesFromRequest(), getLimitOffset(), HistoryAction\getTimestampFromRequest(), and PageDataRequestHandler\handleRequest().

◆ getIntArray()

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
string$name
array | null$defaultOption default (or null)
Returns
int[]|null

Definition at line 552 of file WebRequest.php.

References getArray().

◆ getIntOrNull()

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

Definition at line 581 of file WebRequest.php.

References getRawVal().

Referenced by FormOptions\fetchValuesFromRequest().

◆ getIP()

WebRequest::getIP ( )

Work out the IP address based on various globals For trusted proxies, use the XFF client IP (first of the chain)

Since
1.19
Exceptions
MWException
Returns
string

Reimplemented in DerivativeRequest.

Definition at line 1274 of file WebRequest.php.

Referenced by MWRestrictions\check(), MediaWiki\Block\BlockManager\getAdditionalIpBlocks(), FileCacheBase\incrMissesRecent(), and BotPassword\login().

◆ getLimitOffset()

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
int$deflimitLimit to use if no input and the user hasn't set the option.
string$optionnameTo specify an option other than rclimit to pull from.
Returns
int[] First element is limit, second is offset

Definition at line 957 of file WebRequest.php.

References getInt().

◆ getMethod()

WebRequest::getMethod ( )

Get the HTTP method used for this request.

Returns
string

Reimplemented in FauxRequest.

Definition at line 771 of file WebRequest.php.

Referenced by wasPosted().

◆ getPathInfo()

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
string$wantIf 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 141 of file WebRequest.php.

References $matches, $path, $wgActionPaths, $wgArticlePath, $wgScript, $wgUsePathInfo, $wgVariantArticlePath, PathRouter\add(), PathRouter\getActionPaths(), and Hooks\run().

Referenced by interpolateTitle(), and wfThumbHandle404().

◆ getPostValues()

WebRequest::getPostValues ( )

Get the values passed via POST.

No transformation is performed on the values.

Since
1.32
Returns
array

Definition at line 723 of file WebRequest.php.

◆ getProtocol()

WebRequest::getProtocol ( )

Get the current URL protocol (http or https)

Returns
string

Reimplemented in FauxRequest, and DerivativeRequest.

Definition at line 338 of file WebRequest.php.

References $protocol, and detectProtocol().

Referenced by getFullRequestURL().

◆ getQueryValues()

WebRequest::getQueryValues ( )

Get the values passed in the query string and the path router parameters.

No transformation is performed on the values.

Returns
array

Reimplemented in FauxRequest.

Definition at line 698 of file WebRequest.php.

References $queryAndPathParams.

Referenced by appendQueryArray().

◆ getQueryValuesOnly()

WebRequest::getQueryValuesOnly ( )

Get the values passed in the query string only, not including the path router parameters.

This is less suitable for self-links to index.php but useful for other entry points. No transformation is performed on the values.

Since
1.34
Returns
array

Definition at line 711 of file WebRequest.php.

References $queryParams.

◆ getRawInput()

WebRequest::getRawInput ( )

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

Returns
string

Reimplemented in FauxRequest.

Definition at line 758 of file WebRequest.php.

Referenced by getRawPostString().

◆ getRawIP()

WebRequest::getRawIP ( )
protected

Fetch the raw IP from the request.

Since
1.19
Exceptions
MWException
Returns
string

Reimplemented in FauxRequest.

Definition at line 1250 of file WebRequest.php.

◆ getRawPostString()

WebRequest::getRawPostString ( )

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.

Returns
string

Reimplemented in FauxRequest.

Definition at line 744 of file WebRequest.php.

References getRawInput(), and wasPosted().

◆ getRawQueryString()

WebRequest::getRawQueryString ( )

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.

Returns
string

Reimplemented in FauxRequest.

Definition at line 734 of file WebRequest.php.

◆ getRawVal()

WebRequest::getRawVal (   $name,
  $default = null 
)

Fetch a scalar from the input without normalization, or return $default if it's not set.

Unlike self::getVal(), this does not perform any normalization on the input value.

Since
1.28
Parameters
string$name
string | null$default
Returns
string|null

Definition at line 459 of file WebRequest.php.

Referenced by getBool(), getCheck(), getFloat(), getFuzzyBool(), getInt(), getIntOrNull(), and RequestContext\getLanguage().

◆ getRequestId()

◆ getRequestURL()

WebRequest::getRequestURL ( )

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

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

Exceptions
MWException
Returns
string

Reimplemented in FauxRequest.

Definition at line 900 of file WebRequest.php.

References getGlobalRequestURL().

Referenced by getFullRequestURL().

◆ getSession()

WebRequest::getSession ( )

Return the session for this request.

This might unpersist an existing session if it was invalid.

Since
1.27
Note
For performance, keep the session locally if you will be making much use of it instead of calling this method repeatedly.
Returns
Session

Reimplemented in DerivativeRequest.

Definition at line 798 of file WebRequest.php.

Referenced by FauxRequest\getSessionArray(), getSessionData(), and setSessionData().

◆ getSessionData()

WebRequest::getSessionData (   $key)

Get data from the session.

Note
Prefer $this->getSession() instead if making multiple calls.
Parameters
string$keyName of key in the session
Returns
mixed

Reimplemented in DerivativeRequest.

Definition at line 1112 of file WebRequest.php.

References getSession().

◆ getSessionId()

WebRequest::getSessionId ( )

Get the session id for this request, if any.

Since
1.27
Access:\n private For use by MediaWiki\Session classes only
Returns
SessionId|null

Definition at line 827 of file WebRequest.php.

References $sessionId.

◆ getText()

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. This should generally be used for form "<textarea>" and "<input>" fields, and for user-supplied freeform text input.

Parameters
string$name
string$defaultOptional
Returns
string

Reimplemented in FauxRequest.

Definition at line 653 of file WebRequest.php.

References getVal().

Referenced by PageDataRequestHandler\canHandleRequest(), FormOptions\fetchValuesFromRequest(), and PageDataRequestHandler\handleRequest().

◆ getUpload()

WebRequest::getUpload (   $key)

Return a WebRequestUpload object corresponding to the key.

Parameters
string$key
Returns
WebRequestUpload

Definition at line 1026 of file WebRequest.php.

◆ getUploadError()

WebRequest::getUploadError (   $key)

Return the upload error or 0.

Parameters
string$key
Returns
int

Definition at line 999 of file WebRequest.php.

References $file.

◆ getVal()

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
string$name
string | null$defaultOptional default (or null)
Returns
string|null

Definition at line 483 of file WebRequest.php.

References getGPCVal().

Referenced by SimpleCaptcha\getCaptchaParamsFromRequest(), ImagePage\getLanguageForRendering(), FauxRequest\getText(), getText(), and HistoryAction\getTimestampFromRequest().

◆ getValueNames()

WebRequest::getValueNames (   $exclude = [])

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

Parameters
array$exclude
Returns
array

Definition at line 687 of file WebRequest.php.

References getValues().

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

Returns
array

Definition at line 665 of file WebRequest.php.

References getGPCVal().

Referenced by getValueNames().

◆ hasSafeMethod()

WebRequest::hasSafeMethod ( )

Check if this request uses a "safe" HTTP method.

Safe methods are verbs (e.g. GET/HEAD/OPTIONS) used for obtaining content. Such requests are not expected to mutate content, especially in ways attributable to the client. Verbs like POST and PUT are typical of non-safe requests which often change content.

Returns
bool
See also
https://tools.ietf.org/html/rfc7231#section-4.2.1
https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
Since
1.28

Definition at line 1362 of file WebRequest.php.

◆ initHeaders()

WebRequest::initHeaders ( )
protected

Initialise the header list.

Reimplemented in FauxRequest.

Definition at line 1048 of file WebRequest.php.

Referenced by getAllHeaders(), and getHeader().

◆ interpolateTitle()

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 the content language is available, as we may need the list of language variants to determine available variant URLs.

Definition at line 352 of file WebRequest.php.

References $matches, and getPathInfo().

◆ isSafeRequest()

WebRequest::isSafeRequest ( )

Whether this request should be identified as being "safe".

This means that the client is not requesting any state changes and that database writes are not inherently required. Ideally, no visible updates would happen at all. If they must, then they should not be publicly attributed to the end user.

In more detail:

  • Cache populations and refreshes MAY occur.
  • Private user session updates and private server logging MAY occur.
  • Updates to private viewing activity data MAY occur via DeferredUpdates.
  • Other updates SHOULD NOT occur (e.g. modifying content assets).
Returns
bool
See also
https://tools.ietf.org/html/rfc7231#section-4.2.1
https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
Since
1.28

Definition at line 1388 of file WebRequest.php.

◆ markAsSafeRequest()

WebRequest::markAsSafeRequest ( )

Mark this request as identified as being nullipotent even if it is a POST request.

POST requests are often used due to the need for a client payload, even if the request is otherwise equivalent to a "safe method" request.

See also
https://tools.ietf.org/html/rfc7231#section-4.2.1
https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
Since
1.28

Definition at line 1406 of file WebRequest.php.

◆ normalizeUnicode()

WebRequest::normalizeUnicode (   $data)

Recursively normalizes UTF-8 strings in the given array.

Parameters
string | array$data
Returns
array|string Cleaned-up version of the given
Access:\n private

Definition at line 400 of file WebRequest.php.

References $data.

Referenced by getGPCVal().

◆ overrideRequestId()

static WebRequest::overrideRequestId (   $id)
static

Override the unique request ID.

This is for sub-requests, such as jobs, that wish to use the same id but are not part of the same execution context.

Parameters
string$id
Since
1.27

Definition at line 330 of file WebRequest.php.

Referenced by JobRunner\run().

◆ response()

◆ setIP()

WebRequest::setIP (   $ip)
Parameters
string$ip
Returns
void
Since
1.21

Reimplemented in DerivativeRequest.

Definition at line 1346 of file WebRequest.php.

Referenced by RequestContext\importScopedSession().

◆ setSessionData()

WebRequest::setSessionData (   $key,
  $data 
)

Set session data.

Note
Prefer $this->getSession() instead if making multiple calls.
Parameters
string$keyName of key in the session
mixed$data

Reimplemented in DerivativeRequest.

Definition at line 1123 of file WebRequest.php.

References $data, and getSession().

◆ setSessionId()

WebRequest::setSessionId ( SessionId  $sessionId)

Set the session for this request.

Since
1.27
Access:\n private For use by MediaWiki\Session classes only
Parameters
SessionId$sessionId

Definition at line 817 of file WebRequest.php.

References $sessionId.

Referenced by MediaWiki\Session\SessionManager\getSessionFromInfo(), and MediaWiki\Session\Session\sessionWithRequest().

◆ setVal()

WebRequest::setVal (   $key,
  $value 
)

Set an arbitrary value into our get/post data.

Parameters
string$keyKey name to use
mixed$valueValue to set
Returns
mixed Old value if one was present, null otherwise

Definition at line 502 of file WebRequest.php.

◆ unsetVal()

WebRequest::unsetVal (   $key)

Unset an arbitrary value from our get/post data.

Parameters
string$keyKey name to use
Returns
mixed Old value if one was present, null otherwise

Definition at line 514 of file WebRequest.php.

◆ wasPosted()

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

References getMethod().

Referenced by checkUrlExtension(), and getRawPostString().

Member Data Documentation

◆ $data

array WebRequest::$data
protected

◆ $headers

array WebRequest::$headers = []
protected

Lazy-initialized request headers indexed by upper-case header name.

Definition at line 65 of file WebRequest.php.

Referenced by getAllHeaders(), and FauxRequest\setHeaders().

◆ $ip

string WebRequest::$ip
private

Cached client IP address.

Definition at line 89 of file WebRequest.php.

◆ $markedAsSafe

bool WebRequest::$markedAsSafe = false
protected

Whether this HTTP request is "safe" (even if it is an HTTP post)

Definition at line 111 of file WebRequest.php.

◆ $protocol

string WebRequest::$protocol
protected

Cached URL protocol.

Definition at line 101 of file WebRequest.php.

Referenced by FauxRequest\__construct(), FauxRequest\getProtocol(), and getProtocol().

◆ $queryAndPathParams

array WebRequest::$queryAndPathParams
protected

The parameters from $_GET.

The parameters from the path router are added by interpolateTitle() during Setup.php.

Definition at line 54 of file WebRequest.php.

Referenced by getQueryValues().

◆ $queryParams

WebRequest::$queryParams
protected

The parameters from $_GET only.

Definition at line 59 of file WebRequest.php.

Referenced by getQueryValuesOnly().

◆ $reqId

string WebRequest::$reqId
staticprivate

The unique request ID.

Definition at line 77 of file WebRequest.php.

Referenced by getRequestId().

◆ $requestTime

float WebRequest::$requestTime
protected

The timestamp of the start of the request, with microsecond precision.

Definition at line 95 of file WebRequest.php.

Referenced by getElapsedTime().

◆ $response

WebResponse WebRequest::$response
private

Lazy-init response object.

Definition at line 83 of file WebRequest.php.

Referenced by response().

◆ $sessionId

SessionId null WebRequest::$sessionId = null
protected

Session ID to use for this request.

We can't save the session directly due to reference cycles not working too well (slow GC in Zend and never collected in HHVM).

Definition at line 108 of file WebRequest.php.

Referenced by getSessionId(), and setSessionId().

◆ GETHEADER_LIST

const WebRequest::GETHEADER_LIST = 1

Flag to make WebRequest::getHeader return an array of values.

Since
1.26

Definition at line 71 of file WebRequest.php.

Referenced by ApiMain\checkConditionalRequestHeaders().


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