MediaWiki master
MediaWiki\Request\DerivativeRequest Class Reference

Similar to MediaWiki\Request\FauxRequest, but only fakes URL parameters and method (POST or GET) and use the base request for the remaining stuff (cookies, session and headers). More...

Inherits MediaWiki\Request\FauxRequest.

Collaboration diagram for MediaWiki\Request\DerivativeRequest:

Public Member Functions

 __construct (WebRequest $base, $data, $wasPosted=false)
 
 getAcceptLang ()
 Parse the Accept-Language header sent by the client into an array.
 
 getAllHeaders ()
 Get an array containing all request headers.
 
 getCookie ( $key, $prefix=null, $default=null)
 Get a cookie from the $_COOKIE jar.
 
 getElapsedTime ()
 Get the number of seconds to have elapsed since request start, in fractional seconds, with microsecond resolution.
 
 getHeader ( $name, $flags=0)
 Get a request header, or false if it isn't set.
 
 getIP ()
 Work out the IP address based on various globals For trusted proxies, use the XFF client IP (first of the chain)
 
 getProtocol ()
 Get the current URL protocol (http or https)
 
 getSession ()
 Return the session for this request.
 
 getSessionData ( $key)
 Get data from the session.
 
 getUpload ( $key)
 Return a MediaWiki\Request\FauxRequestUpload object corresponding to the key.
 
 setIP ( $ip)
 
 setSessionData ( $key, $data)
 
- Public Member Functions inherited from MediaWiki\Request\FauxRequest
 __construct (array $data=[], $wasPosted=false, $session=null, $protocol='http')
 
 getMethod ()
 Get the HTTP method used for this request.
 
 getPostValues ()
 Get the values passed via POST.
 
 getQueryValues ()
 
 getQueryValuesOnly ()
 Get the values passed in $_GET only, not including the path router parameters.
 
 getRawInput ()
 FauxRequests shouldn't depend on raw request data (but that could be implemented here)
 
 getRawPostString ()
 FauxRequests shouldn't depend on raw request data (but that could be implemented here)
 
 getRawQueryString ()
 FauxRequests shouldn't depend on raw request data (but that could be implemented here)
 
 getRequestURL ()
 
 getSessionArray ()
 
 getText ( $name, $default='')
 
 hasRequestURL ()
 
 response ()
 Return a handle to WebResponse style object, for setting cookies, headers and other stuff, for Request being worked on.
 
 setCookie ( $key, $value, $prefix=null)
 
 setCookies ( $cookies, $prefix=null)
 
 setHeader ( $name, $val)
 
 setHeaders ( $headers)
 
 setRequestURL (string $url)
 
 setServerInfo (array $info)
 
 setUpload ( $key, $data)
 Set fake upload data for one file with specific key.
 
 setUploadData ( $uploadData)
 Set fake upload data for all files.
 
 wasPosted ()
 
- Public Member Functions inherited from MediaWiki\Request\WebRequest
 __construct ()
 
 appendQueryArray ( $array)
 Appends or replaces value of query variables.
 
 appendQueryValue ( $key, $value)
 
 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").
 
 getCrossSiteCookie ( $key, $prefix='', $default=null)
 Get a cookie set with SameSite=None.
 
 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.
 
 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.
 
 getLimitOffsetForUser (UserIdentity $user, $deflimit=50, $optionname='rclimit')
 Check for limit and offset parameters on the input, and return sensible defaults if not given.
 
 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.
 
 getSessionId ()
 Get the session id for this request, if any.
 
 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.
 
 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.
 

Additional Inherited Members

- Static Public Member Functions inherited from MediaWiki\Request\WebRequest
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 inherited from MediaWiki\Request\WebRequest
const GETHEADER_LIST = 1
 Flag to make WebRequest::getHeader return an array of values.
 
- Protected Member Functions inherited from MediaWiki\Request\FauxRequest
 getRawIP ()
 
 getServerInfo ( $name, $default=null)
 
 initHeaders ()
 Initialise the header list.
 
- Protected Member Functions inherited from MediaWiki\Request\WebRequest
 getPathInfo ( $want='all')
 Extract relevant query arguments from the http request uri's path to be merged with the normal php provided query arguments.
 
 getServerInfo (string $name, ?string $default=null)
 Returns an entry from the $_SERVER array.
 
- Protected Attributes inherited from MediaWiki\Request\FauxRequest
array $cookies = []
 
- Protected Attributes inherited from MediaWiki\Request\WebRequest
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

Similar to MediaWiki\Request\FauxRequest, but only fakes URL parameters and method (POST or GET) and use the base request for the remaining stuff (cookies, session and headers).

Stability: newable
Since
1.19

Definition at line 40 of file DerivativeRequest.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Request\DerivativeRequest::__construct ( WebRequest $base,
$data,
$wasPosted = false )
Stability: stable
to call
Parameters
WebRequest$base
array$dataArray of non-urlencoded key => value pairs, the fake GET/POST values
bool$wasPostedWhether to treat the data as POST

Definition at line 52 of file DerivativeRequest.php.

References MediaWiki\Request\WebRequest\$data.

Member Function Documentation

◆ getAcceptLang()

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

Definition at line 81 of file DerivativeRequest.php.

◆ getAllHeaders()

MediaWiki\Request\DerivativeRequest::getAllHeaders ( )

Get an array containing all request headers.

Returns
string[] Mapping header name to its value

Reimplemented from MediaWiki\Request\WebRequest.

Definition at line 65 of file DerivativeRequest.php.

◆ getCookie()

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

Definition at line 57 of file DerivativeRequest.php.

◆ getElapsedTime()

MediaWiki\Request\DerivativeRequest::getElapsedTime ( )

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

Returns
float
Since
1.25

Reimplemented from MediaWiki\Request\WebRequest.

Definition at line 102 of file DerivativeRequest.php.

◆ getHeader()

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

Definition at line 61 of file DerivativeRequest.php.

◆ getIP()

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

Definition at line 85 of file DerivativeRequest.php.

◆ getProtocol()

MediaWiki\Request\DerivativeRequest::getProtocol ( )

Get the current URL protocol (http or https)

Returns
string

Reimplemented from MediaWiki\Request\FauxRequest.

Definition at line 93 of file DerivativeRequest.php.

◆ getSession()

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

Definition at line 69 of file DerivativeRequest.php.

◆ getSessionData()

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

Definition at line 73 of file DerivativeRequest.php.

◆ getUpload()

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

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

Parameters
string$key
Returns
FauxRequestUpload

Reimplemented from MediaWiki\Request\FauxRequest.

Definition at line 97 of file DerivativeRequest.php.

◆ setIP()

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

Reimplemented from MediaWiki\Request\WebRequest.

Definition at line 89 of file DerivativeRequest.php.

◆ setSessionData()

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

Reimplemented from MediaWiki\Request\WebRequest.

Definition at line 77 of file DerivativeRequest.php.


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