3 * Classes used to send headers and cookies back to the user
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 * Allow programs to request this object from WebRequest::response()
25 * and handle all outputting (or lack of outputting) via it.
31 * Output a HTTP header, wrapper for PHP's
33 * @param $string String: header to output
34 * @param $replace Bool: replace current similar header
35 * @param $http_response_code null|int Forces the HTTP response code to the specified value.
37 public function header( $string, $replace = true, $http_response_code = null ) {
38 header( $string, $replace, $http_response_code );
42 * Set the browser cookie
43 * @param $name String: name of cookie
44 * @param $value String: value to give cookie
45 * @param $expire Int: number of seconds til cookie expires
46 * @param $prefix String: Prefix to use, if not $wgCookiePrefix (use '' for no prefix)
47 * @param @domain String: Cookie domain to use, if not $wgCookieDomain
49 public function setcookie( $name, $value, $expire = 0, $prefix = null, $domain = null ) {
50 global $wgCookiePath, $wgCookiePrefix, $wgCookieDomain;
51 global $wgCookieSecure,$wgCookieExpiration, $wgCookieHttpOnly;
53 $expire = time() +
$wgCookieExpiration;
55 if( $prefix === null ) {
56 $prefix = $wgCookiePrefix;
58 if( $domain === null ) {
59 $domain = $wgCookieDomain;
61 $httpOnlySafe = wfHttpOnlySafe() && $wgCookieHttpOnly;
63 'setcookie: "' . implode( '", "',
71 $httpOnlySafe ) ) . '"' );
72 setcookie( $prefix . $name,
85 class FauxResponse
extends WebResponse
{
91 * Stores a HTTP header
92 * @param $string String: header to output
93 * @param $replace Bool: replace current similar header
94 * @param $http_response_code null|int Forces the HTTP response code to the specified value.
96 public function header( $string, $replace = true, $http_response_code = null ) {
97 if ( substr( $string, 0, 5 ) == 'HTTP/' ) {
98 $parts = explode( ' ', $string, 3 );
99 $this->code
= intval( $parts[1] );
101 list( $key, $val ) = array_map( 'trim', explode( ":", $string, 2 ) );
103 if( $replace ||
!isset( $this->headers
[$key] ) ) {
104 $this->headers
[$key] = $val;
108 if ( $http_response_code !== null ) {
109 $this->code
= intval( $http_response_code );
117 public function getheader( $key ) {
118 if ( isset( $this->headers
[$key] ) ) {
119 return $this->headers
[$key];
125 * Get the HTTP response code, null if not set
127 * @return Int or null
129 public function getStatusCode() {
134 * @todo document. It just ignore optional parameters.
136 * @param $name String: name of cookie
137 * @param $value String: value to give cookie
138 * @param $expire Int: number of seconds til cookie expires (Default: 0)
139 * @param $prefix TODO DOCUMENT (Default: null)
140 * @param $domain TODO DOCUMENT (Default: null)
143 public function setcookie( $name, $value, $expire = 0, $prefix = null, $domain = null ) {
144 $this->cookies
[$name] = $value;
148 * @param $name string
151 public function getcookie( $name ) {
152 if ( isset( $this->cookies
[$name] ) ) {
153 return $this->cookies
[$name];