MediaWiki master
MediaWiki\Request\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...

Inherited by MediaWiki\Request\FauxRequest.

Collaboration diagram for MediaWiki\Request\WebRequest:

Public Member Functions

 __construct ()
 
 appendQueryArray ( $array)
 Appends or replaces value of query variables.
 
 appendQueryValue ( $key, $value)
 
 getAcceptLang ()
 Parse the Accept-Language header sent by the client into an array.
 
 getAllHeaders ()
 Get an array containing all request headers.
 
 getArray ( $name, $default=null)
 Fetch an array from this web request's $_GET, $_POST or path router vars, or return $default if it's not set.
 
 getBool ( $name, $default=false)
 Fetch a boolean value from this web request's $_GET, $_POST or path router vars or return $default if not set.
 
 getCheck ( $name)
 Return true if the named value is set in this web request's $_GET, $_POST or path router vars, whatever that value is (even "0").
 
 getCookie ( $key, $prefix=null, $default=null)
 Get a cookie from the $_COOKIE jar.
 
 getCrossSiteCookie ( $key, $prefix='', $default=null)
 Get a cookie set with SameSite=None.
 
 getElapsedTime ()
 Get the number of seconds to have elapsed since request start, in fractional seconds, with microsecond resolution.
 
 getFileName ( $key)
 Return the original filename of the uploaded file, as reported by the submitting user agent.
 
 getFileTempname ( $key)
 Return the path to the temporary file where PHP has stored the upload.
 
 getFloat ( $name, $default=0.0)
 Fetch a floating point value from this web request's $_GET, $_POST or path router vars, or return $default if not set.
 
 getFullRequestURL ()
 Return the request URI with the canonical service and hostname, path, and query string.
 
 getFuzzyBool ( $name, $default=false)
 Fetch a boolean value from this web request's $_GET, $_POST or path router vars or return $default if not set.
 
 getHeader ( $name, $flags=0)
 Get a request header, or false if it isn't set.
 
 getInt ( $name, $default=0)
 Fetch an integer value from this web request's $_GET, $_POST or path router vars, or return $default if not set.
 
 getIntArray ( $name, $default=null)
 Fetch an array of integers from this web request's $_GET, $_POST or path router vars, or return $default if it's not set.
 
 getIntOrNull ( $name)
 Fetch an integer value from this web request's $_GET, $_POST or path router vars, or return null if empty.
 
 getIP ()
 Work out the IP address based on various globals For trusted proxies, use the XFF client IP (first of the chain)
 
 getLimitOffsetForUser (UserIdentity $user, $deflimit=50, $optionname='rclimit')
 Check for limit and offset parameters on the input, and return sensible defaults if not given.
 
 getMethod ()
 Get the HTTP method used for this request.
 
 getPostValues ()
 Get the values passed via POST.
 
 getProtocol ()
 Get the current URL protocol (http or https)
 
 getQueryValues ()
 Get the values passed in $_GET and the path router parameters.
 
 getQueryValuesOnly ()
 Get the values passed in $_GET only, not including the path router parameters.
 
 getRawInput ()
 Return the raw request body, with no processing.
 
 getRawPostString ()
 Return the contents of the POST with no decoding.
 
 getRawQueryString ()
 Return the contents of the URL query string with no decoding.
 
 getRawVal ( $name, $default=null)
 Fetch a string from this web request's $_GET, $_POST or path router vars WITHOUT any Unicode or line break normalization.
 
 getRequestURL ()
 Return the path and query string portion of the request URI.
 
 getSession ()
 Return the session for this request.
 
 getSessionData ( $key)
 Get data from the session.
 
 getSessionId ()
 Get the session id for this request, if any.
 
 getText ( $name, $default='')
 Fetch a text string from this web request's $_GET, $_POST or path router vars and return it in normalized form.
 
 getUpload ( $key)
 Return a MediaWiki\Request\WebRequestUpload object corresponding to the key.
 
 getUploadError ( $key)
 Return the upload error or 0.
 
 getVal ( $name, $default=null)
 Fetch a text string from this web request's $_GET, $_POST or path router vars and partially normalize it.
 
 getValueNames ( $exclude=[])
 Returns the names of this web request's $_GET, $_POST or path router vars, excluding those in $exclude.
 
 getValues (... $names)
 Extracts the (given) named values from this web request's $_GET, $_POST or path router vars into an array.
 
 hasSafeMethod ()
 Check if this request uses a "safe" HTTP method.
 
 interpolateTitle ()
 Check for title, action, and/or variant data in the URL and interpolate it into the GET variables.
 
 isSafeRequest ()
 Whether this request should be identified as being "safe".
 
 markAsSafeRequest ()
 Mark this request as identified as being nullipotent even if it is a POST request.
 
 matchURLForCDN (array $cdnUrls)
 Determine if the request URL matches one of a given set of canonical CDN URLs.
 
 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.
 
 setIP ( $ip)
 
 setSessionData ( $key, $data)
 
 setSessionId (SessionId $sessionId)
 Set the session for this request.
 
 setVal ( $key, $value)
 Set an arbitrary value into our get/post data.
 
 unsetVal ( $key)
 Unset an arbitrary value from 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 canonicalizeIPv6LoopbackAddress ( $ip)
 Converts ::1 (IPv6 loopback address) to 127.0.0.1 (IPv4 loopback address); assists in matching trusted proxies.
 
static detectProtocol ()
 Detect the protocol from $_SERVER.
 
static detectServer ( $assumeProxiesUseDefaultProtocolPorts=null)
 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 getGlobalRequestURL ()
 Return the path and query string portion of the main request URI.
 
static getRequestId ()
 Get the current request ID.
 
static getRequestPathSuffix (string $basePath, ?string $requestUrl=null)
 If the request URL matches a given base path, extract the path part of the request URL after that base, and decode escape sequences in it.
 
static overrideRequestId ( $newId)
 Override the unique request ID.
 

Public Attributes

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

Protected Member Functions

 getPathInfo ( $want='all')
 Extract relevant query arguments from the http request uri's path to be merged with the normal php provided query arguments.
 
 getRawIP ()
 Fetch the raw IP from the request.
 
 getServerInfo (string $name, ?string $default=null)
 Returns an entry from the $_SERVER array.
 
 initHeaders ()
 Initialise the header list.
 

Protected Attributes

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

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.

This class should be used instead of accessing globals such as $_GET, $_POST, and $_COOKIE.

Definition at line 51 of file WebRequest.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Request\WebRequest::__construct ( )

Definition at line 123 of file WebRequest.php.

Member Function Documentation

◆ appendQueryArray()

MediaWiki\Request\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 1032 of file WebRequest.php.

References wfArrayToCgi().

◆ appendQueryValue()

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

Definition at line 1022 of file WebRequest.php.

◆ canonicalizeIPv6LoopbackAddress()

static MediaWiki\Request\WebRequest::canonicalizeIPv6LoopbackAddress ( $ip)
static

Converts ::1 (IPv6 loopback address) to 127.0.0.1 (IPv4 loopback address); assists in matching trusted proxies.

Parameters
string$ip
Returns
string either '127.0.0.1' or $ip
Since
1.36

Definition at line 1376 of file WebRequest.php.

◆ detectProtocol()

static MediaWiki\Request\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 331 of file WebRequest.php.

◆ detectServer()

static MediaWiki\Request\WebRequest::detectServer ( $assumeProxiesUseDefaultProtocolPorts = null)
static

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

Parameters
bool | null$assumeProxiesUseDefaultProtocolPortsWhen the wiki is running behind a proxy and this is set to true, assumes that the proxy exposes the wiki on the standard ports (443 for https and 80 for http). Added in 1.38. Calls without this argument are supported for backwards compatibility but deprecated.
Returns
string

Definition at line 285 of file WebRequest.php.

◆ extractTitle()

static MediaWiki\Request\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 | false$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 414 of file WebRequest.php.

References $matches, and $path.

◆ getAcceptLang()

MediaWiki\Request\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 logic is aligned with RFC 7231 section 5 (previously RFC 2616 section 14), at https://tools.ietf.org/html/rfc7231#section-5.3.5.

Earlier languages in the list are preferred as per the RFC 23282 extension to HTTP/1.1, at https://tools.ietf.org/html/rfc3282.

Reimplemented in MediaWiki\Request\DerivativeRequest.

Definition at line 1214 of file WebRequest.php.

References $matches.

◆ getAllHeaders()

MediaWiki\Request\WebRequest::getAllHeaders ( )

Get an array containing all request headers.

Returns
string[] Mapping header name to its value

Reimplemented in MediaWiki\Request\DerivativeRequest.

Definition at line 1149 of file WebRequest.php.

◆ getArray()

MediaWiki\Request\WebRequest::getArray ( $name,
$default = null )

Fetch an array from this web request's $_GET, $_POST or path router vars, 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 599 of file WebRequest.php.

Referenced by MediaWiki\Html\FormOptions\fetchValuesFromRequest().

◆ getBool()

MediaWiki\Request\WebRequest::getBool ( $name,
$default = false )

Fetch a boolean value from this web request's $_GET, $_POST or path router vars 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 679 of file WebRequest.php.

Referenced by MediaWiki\Html\FormOptions\fetchValuesFromRequest(), and HistoryAction\onView().

◆ getCheck()

MediaWiki\Request\WebRequest::getCheck ( $name)

Return true if the named value is set in this web request's $_GET, $_POST or path router vars, 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 712 of file WebRequest.php.

Referenced by MediaWiki\HTMLForm\HTMLFormField\isSubmitAttempt(), and HistoryAction\onView().

◆ getCookie()

MediaWiki\Request\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 MediaWiki\Request\DerivativeRequest, and MediaWiki\Request\FauxRequest.

Definition at line 904 of file WebRequest.php.

References $wgCookiePrefix.

Referenced by MediaWiki\Session\ImmutableSessionProviderWithCookie\getSessionIdFromCookie().

◆ getCrossSiteCookie()

MediaWiki\Request\WebRequest::getCrossSiteCookie ( $key,
$prefix = '',
$default = null )

Get a cookie set with SameSite=None.

Deprecated
since 1.42 use getCookie(), but note the different $prefix default
Parameters
string$keyThe name of the cookie
string$prefixA prefix to use, empty by default
mixed | null$defaultWhat to return if the value isn't found
Returns
mixed Cookie value or $default if the cookie is not set

Definition at line 929 of file WebRequest.php.

References wfDeprecated().

◆ getElapsedTime()

MediaWiki\Request\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 MediaWiki\Request\DerivativeRequest.

Definition at line 348 of file WebRequest.php.

◆ getFileName()

MediaWiki\Request\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 1106 of file WebRequest.php.

References getUpload().

◆ getFileTempname()

MediaWiki\Request\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 1081 of file WebRequest.php.

References getUpload().

◆ getFloat()

MediaWiki\Request\WebRequest::getFloat ( $name,
$default = 0.0 )

Fetch a floating point value from this web request's $_GET, $_POST or path router vars, 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 665 of file WebRequest.php.

Referenced by MediaWiki\Html\FormOptions\fetchValuesFromRequest().

◆ getFullRequestURL()

MediaWiki\Request\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 1006 of file WebRequest.php.

References PROTO_HTTP, PROTO_HTTPS, and wfGetServerUrl().

◆ getFuzzyBool()

MediaWiki\Request\WebRequest::getFuzzyBool ( $name,
$default = false )

Fetch a boolean value from this web request's $_GET, $_POST or path router vars 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 694 of file WebRequest.php.

Referenced by MediaWiki\ResourceLoader\Context\__construct().

◆ getGlobalRequestURL()

static MediaWiki\Request\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 942 of file WebRequest.php.

Referenced by MediaWiki\Request\HeaderCallback\callback().

◆ getHeader()

MediaWiki\Request\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|string[]|false 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 MediaWiki\Request\DerivativeRequest.

Definition at line 1167 of file WebRequest.php.

Referenced by MediaWiki\LinkedData\PageDataRequestHandler\httpContentNegotiation().

◆ getInt()

MediaWiki\Request\WebRequest::getInt ( $name,
$default = 0 )

Fetch an integer value from this web request's $_GET, $_POST or path router vars, 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 637 of file WebRequest.php.

Referenced by MediaWiki\Html\FormOptions\fetchValuesFromRequest(), and MediaWiki\LinkedData\PageDataRequestHandler\handleRequest().

◆ getIntArray()

MediaWiki\Request\WebRequest::getIntArray ( $name,
$default = null )

Fetch an array of integers from this web request's $_GET, $_POST or path router vars, 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 620 of file WebRequest.php.

◆ getIntOrNull()

MediaWiki\Request\WebRequest::getIntOrNull ( $name)

Fetch an integer value from this web request's $_GET, $_POST or path router vars, 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 650 of file WebRequest.php.

Referenced by MediaWiki\Html\FormOptions\fetchValuesFromRequest(), and ImagePage\openShowImage().

◆ getIP()

MediaWiki\Request\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
Returns
string

Reimplemented in MediaWiki\Request\DerivativeRequest.

Definition at line 1286 of file WebRequest.php.

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

◆ getLimitOffsetForUser()

MediaWiki\Request\WebRequest::getLimitOffsetForUser ( UserIdentity $user,
$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
UserIdentity$userUserIdentity to get option for
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 1050 of file WebRequest.php.

◆ getMethod()

MediaWiki\Request\WebRequest::getMethod ( )

Get the HTTP method used for this request.

Returns
string

Reimplemented in MediaWiki\Request\FauxRequest.

Definition at line 835 of file WebRequest.php.

◆ getPathInfo()

MediaWiki\Request\WebRequest::getPathInfo ( $want = 'all')
protected

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.

This internal method handles many odd cases and is tailored specifically for used by WebRequest::interpolateTitle, for index.php requests. Consider using WebRequest::getRequestPathSuffix for other path-related use cases.

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
string[] Any query arguments found in path matches.
Exceptions
FatalErrorIf invalid routes are configured (T48998)

Definition at line 170 of file WebRequest.php.

References $matches, $path, $wgActionPaths, $wgArticlePath, $wgScript, $wgUsePathInfo, $wgVariantArticlePath, MediaWiki\Request\PathRouter\add(), MediaWiki\Request\PathRouter\getActionPaths(), and MediaWiki\MediaWikiServices\getInstance().

◆ getPostValues()

MediaWiki\Request\WebRequest::getPostValues ( )

Get the values passed via POST.

No transformation is performed on the values.

Since
1.32
Returns
(string|string[])[] Might contain arrays in case there was a &param[]=… parameter

Reimplemented in MediaWiki\Request\FauxRequest.

Definition at line 786 of file WebRequest.php.

◆ getProtocol()

MediaWiki\Request\WebRequest::getProtocol ( )

Get the current URL protocol (http or https)

Returns
string

Reimplemented in MediaWiki\Request\DerivativeRequest, and MediaWiki\Request\FauxRequest.

Definition at line 385 of file WebRequest.php.

◆ getQueryValues()

MediaWiki\Request\WebRequest::getQueryValues ( )

Get the values passed in $_GET and the path router parameters.

No transformation is performed on the values.

Returns
(string|string[])[] Might contain arrays in case there was a &param[]=… parameter

Reimplemented in MediaWiki\Request\FauxRequest.

Definition at line 761 of file WebRequest.php.

◆ getQueryValuesOnly()

MediaWiki\Request\WebRequest::getQueryValuesOnly ( )

Get the values passed in $_GET 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
(string|string[])[] Might contain arrays in case there was a &param[]=… parameter

Reimplemented in MediaWiki\Request\FauxRequest.

Definition at line 774 of file WebRequest.php.

Referenced by ImagePage\openShowImage().

◆ getRawInput()

MediaWiki\Request\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 MediaWiki\Request\FauxRequest.

Definition at line 824 of file WebRequest.php.

◆ getRawIP()

MediaWiki\Request\WebRequest::getRawIP ( )
protected

Fetch the raw IP from the request.

Since
1.19
Returns
string|null

Reimplemented in MediaWiki\Request\FauxRequest.

Definition at line 1267 of file WebRequest.php.

◆ getRawPostString()

MediaWiki\Request\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 MediaWiki\Request\FauxRequest.

Definition at line 809 of file WebRequest.php.

◆ getRawQueryString()

MediaWiki\Request\WebRequest::getRawQueryString ( )

Return the contents of the URL query string 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 MediaWiki\Request\FauxRequest.

Definition at line 798 of file WebRequest.php.

◆ getRawVal()

MediaWiki\Request\WebRequest::getRawVal ( $name,
$default = null )

Fetch a string from this web request's $_GET, $_POST or path router vars WITHOUT any Unicode or line break normalization.

This is a fast alternative for values that are known to be simple, e.g. pure ASCII. When reading user input, use {

See also
getText} instead.

Array values are discarded for security reasons. Use {

See also
getArray} or {
getIntArray}.
Since
1.28
Parameters
string$name
string | null$default
Returns
string|null The value, or $default if none set

Definition at line 499 of file WebRequest.php.

Referenced by MediaWiki\ResourceLoader\Context\__construct(), and HistoryAction\onView().

◆ getRequestId()

static MediaWiki\Request\WebRequest::getRequestId ( )
static

Get the current request ID.

This is usually based on the X-Request-Id header, or the UNIQUE_ID environment variable, falling back to (process cached) randomly-generated string.

Returns
string
Since
1.27

Definition at line 361 of file WebRequest.php.

◆ getRequestPathSuffix()

static MediaWiki\Request\WebRequest::getRequestPathSuffix ( string $basePath,
?string $requestUrl = null )
static

If the request URL matches a given base path, extract the path part of the request URL after that base, and decode escape sequences in it.

If the request URL does not match, false is returned.

Since
1.35
Parameters
string$basePathThe base URL path. Trailing slashes will be stripped.
?string$requestUrlThe request URL to examine. If not given, the URL returned by getGlobalRequestURL() will be used.
Returns
string|false

Definition at line 259 of file WebRequest.php.

◆ getRequestURL()

MediaWiki\Request\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 MediaWiki\Request\FauxRequest.

Definition at line 991 of file WebRequest.php.

◆ getServerInfo()

MediaWiki\Request\WebRequest::getServerInfo ( string $name,
?string $default = null )
protected

Returns an entry from the $_SERVER array.

This exists mainly to allow us to inject fake values for testing.

Parameters
string$nameA well known key for $_SERVER, see https://www.php.net/manual/en/reserved.variables.server.php. Only fields that contain string values are supported, so 'argv' and 'argc' are not safe to use.
?string$defaultThe value to return if no value is known for the key $name.
Returns
?string

Definition at line 146 of file WebRequest.php.

◆ getSession()

MediaWiki\Request\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 MediaWiki\Request\DerivativeRequest.

Definition at line 862 of file WebRequest.php.

Referenced by MediaWiki\User\BotPassword\login().

◆ getSessionData()

MediaWiki\Request\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 MediaWiki\Request\DerivativeRequest.

Definition at line 1187 of file WebRequest.php.

◆ getSessionId()

MediaWiki\Request\WebRequest::getSessionId ( )

Get the session id for this request, if any.

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

Definition at line 891 of file WebRequest.php.

◆ getText()

MediaWiki\Request\WebRequest::getText ( $name,
$default = '' )

Fetch a text string from this web request's $_GET, $_POST or path router vars and return it in normalized form.

This normalizes Unicode sequences (via {

See also
getGPCVal}) and line breaks.

This should be used for all user input and form fields that are expected to contain non-ASCII characters, especially if the value will be stored or compared against stored values. Without normalization, logically identically values might not match when they are typed on different OS' or keyboards.

Array values are discarded for security reasons. Use {

See also
getArray} or {
getIntArray}.
Parameters
string$name
string$default
Returns
string The normalized input value, or $default if none set

Reimplemented in MediaWiki\Request\FauxRequest.

Definition at line 555 of file WebRequest.php.

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

◆ getUpload()

MediaWiki\Request\WebRequest::getUpload ( $key)

Return a MediaWiki\Request\WebRequestUpload object corresponding to the key.

Parameters
string$key
Returns
WebRequestUpload

Reimplemented in MediaWiki\Request\DerivativeRequest, and MediaWiki\Request\FauxRequest.

Definition at line 1116 of file WebRequest.php.

◆ getUploadError()

MediaWiki\Request\WebRequest::getUploadError ( $key)

Return the upload error or 0.

Parameters
string$key
Returns
int

Definition at line 1091 of file WebRequest.php.

References getUpload().

◆ getVal()

MediaWiki\Request\WebRequest::getVal ( $name,
$default = null )

Fetch a text string from this web request's $_GET, $_POST or path router vars and partially normalize it.

Use of this method is discouraged. It doesn't normalize line breaks and defaults to null instead of the empty string. Instead:

  • Use {
    See also
    getText} when reading user input or form fields that are expected to contain non-ASCII characters.
  • Use {
    See also
    getRawVal} when reading ASCII strings, such as parameters used to select predefined behaviour in the software.
    Array values are discarded for security reasons. Use {
    See also
    getArray} or {
    getIntArray}.
    Parameters
    string$name
    string | null$default
    Returns
    string|null The input value, or $default if none set

Definition at line 528 of file WebRequest.php.

Referenced by HistoryAction\onView().

◆ getValueNames()

MediaWiki\Request\WebRequest::getValueNames ( $exclude = [])

Returns the names of this web request's $_GET, $_POST or path router vars, excluding those in $exclude.

Parameters
array$exclude
Returns
array

Definition at line 749 of file WebRequest.php.

◆ getValues()

MediaWiki\Request\WebRequest::getValues ( $names)

Extracts the (given) named values from this web request's $_GET, $_POST or path router vars into an array.

No transformation is performed on the values.

Parameters
string...$names If no arguments are given, returns all input values
Returns
array

Definition at line 726 of file WebRequest.php.

◆ hasSafeMethod()

MediaWiki\Request\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 1405 of file WebRequest.php.

◆ initHeaders()

MediaWiki\Request\WebRequest::initHeaders ( )
protected

Initialise the header list.

Reimplemented in MediaWiki\Request\FauxRequest.

Definition at line 1135 of file WebRequest.php.

◆ interpolateTitle()

MediaWiki\Request\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 397 of file WebRequest.php.

References $matches.

◆ isSafeRequest()

MediaWiki\Request\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).
Deprecated
since 1.41, use hasSafeMethod() instead.
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 1433 of file WebRequest.php.

References wfDeprecated().

◆ markAsSafeRequest()

MediaWiki\Request\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.

Deprecated
since 1.41
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 1454 of file WebRequest.php.

References wfDeprecated().

◆ matchURLForCDN()

MediaWiki\Request\WebRequest::matchURLForCDN ( array $cdnUrls)

Determine if the request URL matches one of a given set of canonical CDN URLs.

MediaWiki uses this to determine whether to set a long 'Cache-Control: s-maxage=' header on the response. {

See also
MainConfigNames::CdnMatchParameterOrder} controls whether the matching is sensitive to the order of query parameters.
Parameters
string[]$cdnUrlsURLs to match against
Returns
bool
Since
1.39

Definition at line 1470 of file WebRequest.php.

References PROTO_INTERNAL.

◆ normalizeUnicode()

MediaWiki\Request\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: internal

Definition at line 439 of file WebRequest.php.

References MediaWiki\MediaWikiServices\getInstance().

◆ overrideRequestId()

static MediaWiki\Request\WebRequest::overrideRequestId ( $newId)
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 | null$newId
Since
1.27

Definition at line 372 of file WebRequest.php.

◆ response()

◆ setIP()

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

Reimplemented in MediaWiki\Request\DerivativeRequest.

Definition at line 1389 of file WebRequest.php.

◆ setSessionData()

MediaWiki\Request\WebRequest::setSessionData ( $key,
$data )
Note
Prefer $this->getSession() instead if making multiple calls.
Parameters
string$keyName of key in the session
mixed$data

Reimplemented in MediaWiki\Request\DerivativeRequest.

Definition at line 1196 of file WebRequest.php.

◆ setSessionId()

MediaWiki\Request\WebRequest::setSessionId ( SessionId $sessionId)

Set the session for this request.

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

Definition at line 881 of file WebRequest.php.

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

◆ setVal()

MediaWiki\Request\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 567 of file WebRequest.php.

◆ unsetVal()

MediaWiki\Request\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 579 of file WebRequest.php.

◆ wasPosted()

MediaWiki\Request\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 MediaWiki\Request\FauxRequest.

Definition at line 848 of file WebRequest.php.

Referenced by MediaWiki\HTMLForm\HTMLFormField\isSubmitAttempt().

Member Data Documentation

◆ $data

array MediaWiki\Request\WebRequest::$data
protected

The parameters from $_GET, $_POST and the path router.

Definition at line 56 of file WebRequest.php.

Referenced by MediaWiki\Request\FauxRequest\__construct(), and MediaWiki\Request\DerivativeRequest\__construct().

◆ $headers

string [] MediaWiki\Request\WebRequest::$headers = []
protected

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

Definition at line 75 of file WebRequest.php.

◆ $markedAsSafe

bool MediaWiki\Request\WebRequest::$markedAsSafe = false
protected

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

Definition at line 118 of file WebRequest.php.

◆ $protocol

string MediaWiki\Request\WebRequest::$protocol
protected

Cached URL protocol.

Definition at line 105 of file WebRequest.php.

Referenced by MediaWiki\Request\FauxRequest\__construct().

◆ $queryAndPathParams

string string [][] MediaWiki\Request\WebRequest::$queryAndPathParams
protected

The parameters from $_GET.

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

Definition at line 63 of file WebRequest.php.

◆ $queryParams

string string [][] MediaWiki\Request\WebRequest::$queryParams
protected

The parameters from $_GET only.

Definition at line 69 of file WebRequest.php.

◆ $requestTime

float MediaWiki\Request\WebRequest::$requestTime
protected

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

Definition at line 99 of file WebRequest.php.

◆ $response

WebResponse WebResponse MediaWiki\Request\WebRequest::$response = null
protected

Lazy-init response object.

Definition at line 87 of file WebRequest.php.

◆ $sessionId

SessionId null MediaWiki\Request\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).

TODO: Investigate whether this GC slowness concern (added in a73c5b7395 with regard to PHP 5.6) still applies in PHP 7.2+.

Definition at line 115 of file WebRequest.php.

◆ GETHEADER_LIST

const MediaWiki\Request\WebRequest::GETHEADER_LIST = 1

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

Since
1.26

Definition at line 81 of file WebRequest.php.


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