3 * Classes used to send headers and cookies back to the user
9 * Allow programs to request this object from WebRequest::response()
10 * and handle all outputting (or lack of outputting) via it.
16 * Output a HTTP header, wrapper for PHP's
18 * @param $string String: header to output
19 * @param $replace Bool: replace current similar header
20 * @param $http_response_code null|int Forces the HTTP response code to the specified value.
22 public function header( $string, $replace = true, $http_response_code = null ) {
23 header( $string, $replace, $http_response_code );
27 * Set the browser cookie
28 * @param $name String: name of cookie
29 * @param $value String: value to give cookie
30 * @param $expire Int: number of seconds til cookie expires
32 public function setcookie( $name, $value, $expire = 0 ) {
33 global $wgCookiePath, $wgCookiePrefix, $wgCookieDomain;
34 global $wgCookieSecure,$wgCookieExpiration, $wgCookieHttpOnly;
36 $expire = time() +
$wgCookieExpiration;
38 $httpOnlySafe = wfHttpOnlySafe() && $wgCookieHttpOnly;
40 'setcookie: "' . implode( '", "',
42 $wgCookiePrefix . $name,
48 $httpOnlySafe ) ) . '"' );
49 setcookie( $wgCookiePrefix . $name,
62 class FauxResponse
extends WebResponse
{
67 * Stores a HTTP header
68 * @param $string String: header to output
69 * @param $replace Bool: replace current similar header
70 * @param $http_response_code null|int Forces the HTTP response code to the specified value.
72 public function header( $string, $replace = true, $http_response_code = null ) {
73 list( $key, $val ) = explode( ":", $string, 2 );
75 if( $replace ||
!isset( $this->headers
[$key] ) ) {
76 $this->headers
[$key] = $val;
84 public function getheader( $key ) {
85 return $this->headers
[$key];
89 * @param $name String: name of cookie
90 * @param $value String: value to give cookie
91 * @param $expire Int: number of seconds til cookie expires
93 public function setcookie( $name, $value, $expire = 0 ) {
94 $this->cookies
[$name] = $value;
101 public function getcookie( $name ) {
102 if ( isset( $this->cookies
[$name] ) ) {
103 return $this->cookies
[$name];