MediaWiki
master
|
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...
Public Member Functions | |
__construct () | |
appendQueryArray ( $array) | |
Appends or replaces value of query variables. More... | |
appendQueryValue ( $key, $value) | |
checkUrlExtension ( $extWhitelist=[]) | |
This function formerly did a security check to prevent an XSS vulnerability in IE6, as documented in T30235. 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... | |
getCrossSiteCookie ( $key, $prefix='', $default=null) | |
Get a cookie set with SameSite=None possibly with a legacy fallback cookie. 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... | |
getLimitOffsetForUser (User $user, $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 (... $names) | |
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) | |
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 | canonicalizeIPv6LoopbackAddress ( $ip) |
Converts ::1 (IPv6 loopback address) to 127.0.0.1 (IPv4 loopback address); assists in matching trusted proxies. More... | |
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 | getRequestId () |
Get the current request ID. More... | |
static | getRequestPathSuffix ( $basePath) |
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. 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 | |
getRawIP () | |
Fetch the raw IP from the request. More... | |
initHeaders () | |
Initialise the header list. More... | |
Static Protected Member Functions | |
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... | |
Protected Attributes | |
array | $data |
The parameters from $_GET, $_POST and the path router. More... | |
string[] | $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... | |
string[] | $queryAndPathParams |
The parameters from $_GET. More... | |
string[] | $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... | |
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.
WebRequest::__construct | ( | ) |
Definition at line 120 of file WebRequest.php.
WebRequest::appendQueryArray | ( | $array | ) |
Appends or replaces value of query variables.
array | $array | Array of values to replace/add to query |
Definition at line 993 of file WebRequest.php.
References getQueryValues(), and wfArrayToCgi().
Referenced by appendQueryValue().
WebRequest::appendQueryValue | ( | $key, | |
$value | |||
) |
string | $key | |
string | $value |
Definition at line 983 of file WebRequest.php.
References appendQueryArray().
|
static |
Converts ::1 (IPv6 loopback address) to 127.0.0.1 (IPv4 loopback address); assists in matching trusted proxies.
string | $ip |
Definition at line 1352 of file WebRequest.php.
References $ip, and RE_IPV6_GAP.
WebRequest::checkUrlExtension | ( | $extWhitelist = [] | ) |
This function formerly did a security check to prevent an XSS vulnerability in IE6, as documented in T30235.
Since IE6 support has been dropped, this function now returns true unconditionally.
array | $extWhitelist |
Definition at line 1172 of file WebRequest.php.
References wfDeprecated().
|
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().
Definition at line 300 of file WebRequest.php.
Referenced by detectServer(), and getProtocol().
|
static |
Work out an appropriate URL prefix containing scheme and host, based on information detected from $_SERVER.
Definition at line 254 of file WebRequest.php.
References $wgAssumeProxiesUseDefaultProtocolPorts, and detectProtocol().
Referenced by WebInstaller\envGetDefaultServer().
|
static |
URL rewriting function; tries to extract page title and, optionally, one other fixed parameter value from a URL path.
string | $path | The URL path given from the client |
array | $bases | One or more URLs, optionally with $1 at the end |
string | false | $key | If provided, the matching key in $bases will be passed on as the value of this URL parameter |
Definition at line 396 of file WebRequest.php.
WebRequest::getAcceptLang | ( | ) |
Parse the Accept-Language header sent by the client into an array.
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 DerivativeRequest.
Definition at line 1190 of file WebRequest.php.
References $matches, and getHeader().
WebRequest::getAllHeaders | ( | ) |
Get an array containing all request headers.
Reimplemented in DerivativeRequest.
Definition at line 1113 of file WebRequest.php.
References $headers, and initHeaders().
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.
string | $name | |
array | null | $default | Optional default (or null) |
Definition at line 554 of file WebRequest.php.
References getGPCVal().
Referenced by FormOptions\fetchValuesFromRequest(), and getIntArray().
WebRequest::getBool | ( | $name, | |
$default = false |
|||
) |
Fetch a boolean value from the input or return $default if not set.
Guaranteed to return true or false, with normal PHP semantics for boolean interpretation of strings.
string | $name | |
bool | $default |
Definition at line 632 of file WebRequest.php.
References getRawVal().
Referenced by FormOptions\fetchValuesFromRequest(), and getFuzzyBool().
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.
string | $name |
Definition at line 658 of file WebRequest.php.
References getRawVal().
Referenced by HTMLFormField\isSubmitAttempt().
WebRequest::getCookie | ( | $key, | |
$prefix = null , |
|||
$default = null |
|||
) |
Get a cookie from the $_COOKIE jar.
string | $key | The name of the cookie |
string | null | $prefix | A prefix to use for the cookie name, if not $wgCookiePrefix |
mixed | null | $default | What to return if the value isn't found |
Reimplemented in FauxRequest, and DerivativeRequest.
Definition at line 859 of file WebRequest.php.
References $wgCookiePrefix.
Referenced by MediaWiki\Block\BlockManager\getBlockFromCookieValue(), and MediaWiki\Session\ImmutableSessionProviderWithCookie\getSessionIdFromCookie().
WebRequest::getCrossSiteCookie | ( | $key, | |
$prefix = '' , |
|||
$default = null |
|||
) |
Get a cookie set with SameSite=None possibly with a legacy fallback cookie.
string | $key | The name of the cookie |
string | $prefix | A prefix to use, empty by default |
mixed | null | $default | What to return if the value isn't found |
Definition at line 882 of file WebRequest.php.
References $wgUseSameSiteLegacyCookies.
WebRequest::getElapsedTime | ( | ) |
Get the number of seconds to have elapsed since request start, in fractional seconds, with microsecond resolution.
Reimplemented in DerivativeRequest.
Definition at line 317 of file WebRequest.php.
References $requestTime.
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.
string | $key |
Definition at line 1067 of file WebRequest.php.
References $file.
WebRequest::getFileTempname | ( | $key | ) |
Return the path to the temporary file where PHP has stored the upload.
string | $key |
Definition at line 1040 of file WebRequest.php.
References $file.
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.
string | $name | |
float | $default |
Definition at line 619 of file WebRequest.php.
References getRawVal().
Referenced by FormOptions\fetchValuesFromRequest().
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.
Definition at line 967 of file WebRequest.php.
References getProtocol(), getRequestURL(), PROTO_HTTP, PROTO_HTTPS, and wfGetServerUrl().
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.
string | $name | |
bool | $default |
Definition at line 645 of file WebRequest.php.
References getBool(), and getRawVal().
|
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.
MWException |
Definition at line 907 of file WebRequest.php.
References $base.
Referenced by MediaWiki\HeaderCallback\callback(), getRequestPathSuffix(), getRequestURL(), MediaWiki\Rest\RequestFromGlobals\getUri(), and MWExceptionHandler\handleFatalError().
|
private |
Fetch a value from the given array or return $default if it's not set.
array | $arr | |
string | $name | |
mixed | $default |
Definition at line 442 of file WebRequest.php.
References $data, and normalizeUnicode().
Referenced by getArray(), getVal(), and getValues().
WebRequest::getHeader | ( | $name, | |
$flags = 0 |
|||
) |
Get a request header, or false if it isn't set.
string | $name | Case-insensitive header name |
int | $flags | Bitwise 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). |
Reimplemented in DerivativeRequest.
Definition at line 1130 of file WebRequest.php.
References initHeaders().
Referenced by getAcceptLang(), MediaWiki\Block\BlockManager\getAdditionalIpBlocks(), getIP(), PageDataRequestHandler\httpContentNegotiation(), MediaWiki\Session\SessionBackend\logPersistenceChange(), and MediaWiki\Session\SessionManager\logUnpersist().
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.
string | $name | |
int | $default |
Definition at line 590 of file WebRequest.php.
References getRawVal().
Referenced by FormOptions\fetchValuesFromRequest(), getLimitOffsetForUser(), HistoryAction\getTimestampFromRequest(), and PageDataRequestHandler\handleRequest().
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.
string | $name | |
array | null | $default | Option default (or null) |
Definition at line 573 of file WebRequest.php.
References getArray().
WebRequest::getIntOrNull | ( | $name | ) |
Fetch an integer value from the input or return null if empty.
Guaranteed to return an integer or null; non-numeric input will typically return null.
string | $name |
Definition at line 602 of file WebRequest.php.
References getRawVal().
Referenced by FormOptions\fetchValuesFromRequest().
WebRequest::getIP | ( | ) |
Work out the IP address based on various globals For trusted proxies, use the XFF client IP (first of the chain)
MWException |
Reimplemented in DerivativeRequest.
Definition at line 1269 of file WebRequest.php.
References $ip, $wgUsePrivateIPs, getHeader(), getRawIP(), and Hooks\runner().
Referenced by MWRestrictions\check(), MediaWiki\Block\BlockManager\getAdditionalIpBlocks(), FileCacheBase\incrMissesRecent(), BotPassword\login(), MediaWiki\Session\SessionBackend\logPersistenceChange(), and MediaWiki\Session\SessionManager\logUnpersist().
WebRequest::getLimitOffsetForUser | ( | User | $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.
User | $user | User to get option for |
int | $deflimit | Limit to use if no input and the user hasn't set the option. |
string | $optionname | To specify an option other than rclimit to pull from. |
Definition at line 1011 of file WebRequest.php.
References getInt(), and User\getIntOption().
WebRequest::getMethod | ( | ) |
Get the HTTP method used for this request.
Reimplemented in FauxRequest.
Definition at line 791 of file WebRequest.php.
Referenced by wasPosted().
|
staticprotected |
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.
string | $want | If this is not 'all', then the function will return an empty array if it determines that the URL is inside a rewrite path. |
FatalError | If invalid routes are configured (T48998) |
Definition at line 150 of file WebRequest.php.
References $matches, $path, $wgActionPaths, $wgArticlePath, $wgScript, $wgUsePathInfo, $wgVariantArticlePath, PathRouter\add(), PathRouter\getActionPaths(), and Hooks\runner().
Referenced by interpolateTitle().
WebRequest::getPostValues | ( | ) |
Get the values passed via POST.
No transformation is performed on the values.
Reimplemented in FauxRequest.
Definition at line 743 of file WebRequest.php.
WebRequest::getProtocol | ( | ) |
Get the current URL protocol (http or https)
Reimplemented in FauxRequest, and DerivativeRequest.
Definition at line 360 of file WebRequest.php.
References $protocol, and detectProtocol().
Referenced by getFullRequestURL().
WebRequest::getQueryValues | ( | ) |
Get the values passed in the query string and the path router parameters.
No transformation is performed on the values.
Reimplemented in FauxRequest.
Definition at line 718 of file WebRequest.php.
References $queryAndPathParams.
Referenced by appendQueryArray().
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.
Definition at line 731 of file WebRequest.php.
References $queryParams.
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".
Reimplemented in FauxRequest.
Definition at line 778 of file WebRequest.php.
Referenced by getRawPostString().
|
protected |
Fetch the raw IP from the request.
MWException |
Reimplemented in FauxRequest.
Definition at line 1245 of file WebRequest.php.
Referenced by getIP().
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.
Reimplemented in FauxRequest.
Definition at line 764 of file WebRequest.php.
References getRawInput(), and wasPosted().
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.
Reimplemented in FauxRequest.
Definition at line 754 of file WebRequest.php.
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.
string | $name | |
string | null | $default |
Definition at line 480 of file WebRequest.php.
Referenced by getBool(), getCheck(), getFloat(), getFuzzyBool(), getInt(), getIntOrNull(), and RequestContext\getLanguage().
|
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.
Definition at line 330 of file WebRequest.php.
References $reqId, $wgAllowExternalReqID, and wfRandomString().
Referenced by Job\__construct(), MWHttpRequest\__construct(), MediaWiki\Logger\Monolog\WikiProcessor\__invoke(), MediaWiki\HeaderCallback\callback(), WikiPage\doDeleteArticleBatched(), ApiMain\errorMessagesFromException(), JobRunner\executeJob(), MWException\getHTML(), MWExceptionRenderer\getHTML(), OutputPage\getJSVars(), MWExceptionHandler\getLogContext(), MWExceptionHandler\getLogMessage(), MWExceptionHandler\getPublicLogMessage(), MWExceptionHandler\getStructuredExceptionData(), ApiMain\logRequest(), MediaWiki\Shell\ShellboxHttpClient\modifyRequest(), and MediaWiki\HeaderCallback\register().
|
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.
string | $basePath | The base URL path. Trailing slashes will be stripped. |
Definition at line 233 of file WebRequest.php.
References getGlobalRequestURL().
Referenced by wfImageAuthMain(), and wfThumbHandle404().
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.
MWException |
Reimplemented in FauxRequest.
Definition at line 953 of file WebRequest.php.
References getGlobalRequestURL().
Referenced by getFullRequestURL().
WebRequest::getSession | ( | ) |
Return the session for this request.
This might unpersist an existing session if it was invalid.
Reimplemented in DerivativeRequest.
Definition at line 818 of file WebRequest.php.
Referenced by FauxRequest\getSessionArray(), getSessionData(), and setSessionData().
WebRequest::getSessionData | ( | $key | ) |
Get data from the session.
string | $key | Name of key in the session |
Reimplemented in DerivativeRequest.
Definition at line 1150 of file WebRequest.php.
References getSession().
WebRequest::getSessionId | ( | ) |
Get the session id for this request, if any.
Definition at line 847 of file WebRequest.php.
References $sessionId.
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.
string | $name | |
string | $default | Optional |
Reimplemented in FauxRequest.
Definition at line 674 of file WebRequest.php.
References getVal().
Referenced by PageDataRequestHandler\canHandleRequest(), FormOptions\fetchValuesFromRequest(), and PageDataRequestHandler\handleRequest().
WebRequest::getUpload | ( | $key | ) |
Return a WebRequestUpload object corresponding to the key.
string | $key |
Definition at line 1078 of file WebRequest.php.
WebRequest::getUploadError | ( | $key | ) |
Return the upload error or 0.
string | $key |
Definition at line 1051 of file WebRequest.php.
References $file.
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().
string | $name | |
string | null | $default | Optional default (or null) |
Definition at line 504 of file WebRequest.php.
References getGPCVal().
Referenced by ImagePage\getLanguageForRendering(), SpecialUnblock\getTargetAndType(), FauxRequest\getText(), getText(), and HistoryAction\getTimestampFromRequest().
WebRequest::getValueNames | ( | $exclude = [] | ) |
Returns the names of all input values excluding those in $exclude.
array | $exclude |
Definition at line 707 of file WebRequest.php.
References getValues().
WebRequest::getValues | ( | $names | ) |
Extracts the (given) named values into an array.
No transformation is performed on the values.
string | ...$names If no arguments are given, returns all input values |
Definition at line 686 of file WebRequest.php.
References getGPCVal().
Referenced by getValueNames().
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.
Definition at line 1382 of file WebRequest.php.
Referenced by isSafeRequest().
|
protected |
Initialise the header list.
Reimplemented in FauxRequest.
Definition at line 1100 of file WebRequest.php.
Referenced by getAllHeaders(), and getHeader().
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 374 of file WebRequest.php.
References $matches, and getPathInfo().
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:
Definition at line 1408 of file WebRequest.php.
References hasSafeMethod(), and wasPosted().
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.
Definition at line 1426 of file WebRequest.php.
WebRequest::normalizeUnicode | ( | $data | ) |
Recursively normalizes UTF-8 strings in the given array.
string | array | $data |
Definition at line 422 of file WebRequest.php.
References $data.
Referenced by getGPCVal().
|
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.
string | $id |
Definition at line 352 of file WebRequest.php.
Referenced by JobRunner\executeJob().
WebRequest::response | ( | ) |
Return a handle to WebResponse style object, for setting cookies, headers and other stuff, for Request being worked on.
Definition at line 1088 of file WebRequest.php.
References $response.
Referenced by MediaWiki\Session\CookieSessionProvider\persistSession(), MediaWiki\Session\ImmutableSessionProviderWithCookie\persistSession(), MediaWiki\Session\CookieSessionProvider\setForceHTTPSCookie(), MediaWiki\Session\CookieSessionProvider\setLoggedOutCookie(), MediaWiki\Session\CookieSessionProvider\unpersistSession(), and MediaWiki\Session\ImmutableSessionProviderWithCookie\unpersistSession().
WebRequest::setIP | ( | $ip | ) |
string | $ip |
Reimplemented in DerivativeRequest.
Definition at line 1366 of file WebRequest.php.
References $ip.
Referenced by RequestContext\importScopedSession().
WebRequest::setSessionData | ( | $key, | |
$data | |||
) |
string | $key | Name of key in the session |
mixed | $data |
Reimplemented in DerivativeRequest.
Definition at line 1159 of file WebRequest.php.
References $data, and getSession().
WebRequest::setSessionId | ( | SessionId | $sessionId | ) |
Set the session for this request.
Definition at line 837 of file WebRequest.php.
References $sessionId.
Referenced by MediaWiki\Session\SessionManager\getSessionFromInfo(), and MediaWiki\Session\Session\sessionWithRequest().
WebRequest::setVal | ( | $key, | |
$value | |||
) |
Set an arbitrary value into our get/post data.
string | $key | Key name to use |
mixed | $value | Value to set |
Definition at line 523 of file WebRequest.php.
WebRequest::unsetVal | ( | $key | ) |
Unset an arbitrary value from our get/post data.
string | $key | Key name to use |
Definition at line 535 of file WebRequest.php.
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.
Reimplemented in FauxRequest.
Definition at line 804 of file WebRequest.php.
References getMethod().
Referenced by getRawPostString(), and isSafeRequest().
|
protected |
The parameters from $_GET, $_POST and the path router.
Definition at line 47 of file WebRequest.php.
Referenced by FauxRequest\__construct(), DerivativeRequest\__construct(), getGPCVal(), FauxRequest\getQueryValues(), normalizeUnicode(), DerivativeRequest\setSessionData(), and setSessionData().
|
protected |
Lazy-initialized request headers indexed by upper-case header name.
Definition at line 66 of file WebRequest.php.
Referenced by getAllHeaders(), and FauxRequest\setHeaders().
|
private |
Cached client IP address.
Definition at line 90 of file WebRequest.php.
Referenced by canonicalizeIPv6LoopbackAddress(), getIP(), and setIP().
|
protected |
Whether this HTTP request is "safe" (even if it is an HTTP post)
Definition at line 115 of file WebRequest.php.
|
protected |
Cached URL protocol.
Definition at line 102 of file WebRequest.php.
Referenced by FauxRequest\__construct(), FauxRequest\getProtocol(), and getProtocol().
|
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().
|
protected |
The parameters from $_GET only.
Definition at line 60 of file WebRequest.php.
Referenced by getQueryValuesOnly().
|
staticprivate |
|
protected |
The timestamp of the start of the request, with microsecond precision.
Definition at line 96 of file WebRequest.php.
Referenced by getElapsedTime().
|
private |
|
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 112 of file WebRequest.php.
Referenced by getSessionId(), and setSessionId().
const WebRequest::GETHEADER_LIST = 1 |
Flag to make WebRequest::getHeader return an array of values.
Definition at line 72 of file WebRequest.php.
Referenced by ApiMain\checkConditionalRequestHeaders(), and ResourceLoader\tryRespondNotModified().