MediaWiki master
MediaWiki\Request\WebResponse Class Reference

Allow programs to request this object from WebRequest::response() and handle all outputting (or lack of outputting) via it. More...

Inherited by MediaWiki\Request\FauxResponse.

Public Member Functions

 clearCookie ( $name, $options=[])
 Unset a browser cookie.
 
 disableForPostSend ()
 Disable setters for post-send processing.
 
 getHeader ( $key)
 Get a response header.
 
 getStatusCode ()
 
 hasCookies ()
 Checks whether this request is performing cookie operations.
 
 header ( $string, $replace=true, $http_response_code=null)
 Output an HTTP header, wrapper for PHP's header()
 
 headersSent ()
 Test if headers have been sent.
 
 setCookie ( $name, $value, $expire=0, $options=[])
 Set the browser cookie.
 
 statusHeader ( $code)
 Output an HTTP status code header.
 

Protected Attributes

bool $disableForPostSend = false
 Used to disable setters before running jobs post-request (T191537)
 

Static Protected Attributes

static array $setCookies = []
 Used to record set cookies, because PHP's setcookie() will happily send an identical Set-Cookie to the client.
 

Detailed Description

Allow programs to request this object from WebRequest::response() and handle all outputting (or lack of outputting) via it.

Definition at line 36 of file WebResponse.php.

Member Function Documentation

◆ clearCookie()

MediaWiki\Request\WebResponse::clearCookie (   $name,
  $options = [] 
)

Unset a browser cookie.

This sets the cookie with an empty value and an expiry set to a time in the past, which will cause the browser to remove any cookie with the given name, domain and path from its cookie store. Options other than these (and prefix) have no effect.

Parameters
string$nameCookie name
array$optionsCookie options, see setCookie()
Since
1.27

Definition at line 264 of file WebResponse.php.

References MediaWiki\Request\WebResponse\setCookie().

Referenced by MediaWiki\Block\BlockManager\clearBlockCookie().

◆ disableForPostSend()

MediaWiki\Request\WebResponse::disableForPostSend ( )

Disable setters for post-send processing.

After this call, self::setCookie(), self::header(), and self::statusHeader() will log a warning and return without setting cookies or headers.

Since
1.32 (non-static since 1.42)

Definition at line 55 of file WebResponse.php.

References MediaWiki\Request\WebResponse\disableForPostSend().

Referenced by MediaWiki\Request\WebResponse\disableForPostSend(), MediaWiki\Request\FauxResponse\header(), MediaWiki\Request\WebResponse\header(), MediaWiki\Request\WebResponse\setCookie(), and MediaWiki\Request\WebResponse\statusHeader().

◆ getHeader()

MediaWiki\Request\WebResponse::getHeader (   $key)

Get a response header.

Parameters
string$keyThe name of the header to get (case insensitive).
Returns
string|null The header value (if set); null otherwise.
Since
1.25

Reimplemented in MediaWiki\Request\FauxResponse.

Definition at line 99 of file WebResponse.php.

References $header.

◆ getStatusCode()

MediaWiki\Request\WebResponse::getStatusCode ( )
See also
http_response_code
Returns
int|bool
Since
1.42

Reimplemented in MediaWiki\Request\FauxResponse.

Definition at line 89 of file WebResponse.php.

◆ hasCookies()

MediaWiki\Request\WebResponse::hasCookies ( )

Checks whether this request is performing cookie operations.

Returns
bool
Since
1.27

Reimplemented in MediaWiki\Request\FauxResponse.

Definition at line 274 of file WebResponse.php.

References MediaWiki\Request\WebResponse\$setCookies.

◆ header()

MediaWiki\Request\WebResponse::header (   $string,
  $replace = true,
  $http_response_code = null 
)

Output an HTTP header, wrapper for PHP's header()

Parameters
string$stringHeader to output
bool$replaceReplace current similar header
null | int$http_response_codeForces the HTTP response code to the specified value.

Reimplemented in MediaWiki\Request\FauxResponse.

Definition at line 65 of file WebResponse.php.

References MediaWiki\Request\WebResponse\disableForPostSend(), MediaWiki\Request\WebResponse\header(), and wfDebugLog().

Referenced by MediaWiki\Request\WebResponse\header().

◆ headersSent()

MediaWiki\Request\WebResponse::headersSent ( )

Test if headers have been sent.

Since
1.27
Returns
bool

Reimplemented in MediaWiki\Request\FauxResponse.

Definition at line 131 of file WebResponse.php.

Referenced by MediaWiki\Block\BlockManager\trackBlockWithCookie().

◆ setCookie()

MediaWiki\Request\WebResponse::setCookie (   $name,
  $value,
  $expire = 0,
  $options = [] 
)

Set the browser cookie.

Parameters
string$nameThe name of the cookie.
string$valueThe value to be stored in the cookie.
int | null$expireUnix timestamp (in seconds) when the cookie should expire.
  • 0 (the default) causes it to expire $wgCookieExpiration seconds from now.
  • null causes it to be a session cookie.
array$optionsAssoc of additional cookie options:
  • prefix: string, name prefix ($wgCookiePrefix)
  • domain: string, cookie domain ($wgCookieDomain)
  • path: string, cookie path ($wgCookiePath)
  • secure: bool, secure attribute ($wgCookieSecure)
  • httpOnly: bool, httpOnly attribute ($wgCookieHttpOnly)
  • raw: bool, true to suppress encoding of the value
  • sameSite: string|null, SameSite attribute. May be "strict", "lax", "none", or null or "" for no attribute. (default absent)
  • sameSiteLegacy: bool|null, this option is now ignored
Since
1.22 Replaced $prefix, $domain, and $forceSecure with $options

Reimplemented in MediaWiki\Request\FauxResponse.

Definition at line 155 of file WebResponse.php.

References MediaWiki\MainConfigNames\CookieDomain, MediaWiki\MainConfigNames\CookieExpiration, MediaWiki\MainConfigNames\CookieHttpOnly, MediaWiki\MainConfigNames\CookiePath, MediaWiki\MainConfigNames\CookiePrefix, MediaWiki\MainConfigNames\CookieSecure, MediaWiki\Request\WebResponse\disableForPostSend(), MediaWiki\MediaWikiServices\getInstance(), and wfDebugLog().

Referenced by MediaWiki\Request\WebResponse\clearCookie().

◆ statusHeader()

MediaWiki\Request\WebResponse::statusHeader (   $code)

Output an HTTP status code header.

Since
1.26
Parameters
int$codeStatus code

Reimplemented in MediaWiki\Request\FauxResponse.

Definition at line 114 of file WebResponse.php.

References MediaWiki\Request\WebResponse\disableForPostSend(), HttpStatus\header(), and wfDebugLog().

Member Data Documentation

◆ $disableForPostSend

bool MediaWiki\Request\WebResponse::$disableForPostSend = false
protected

Used to disable setters before running jobs post-request (T191537)

Definition at line 44 of file WebResponse.php.

◆ $setCookies

array MediaWiki\Request\WebResponse::$setCookies = []
staticprotected

Used to record set cookies, because PHP's setcookie() will happily send an identical Set-Cookie to the client.

Definition at line 41 of file WebResponse.php.

Referenced by MediaWiki\Request\WebResponse\hasCookies().


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