Use HTML5 for formatted API output
[mediawiki.git] / includes / WebResponse.php
bloba0f7776618ebf320a2b53433d910adf95d3997a8
1 <?php
2 /**
3 * Classes used to send headers and cookies back to the user
5 * @file
6 */
8 /**
9 * Allow programs to request this object from WebRequest::response()
10 * and handle all outputting (or lack of outputting) via it.
11 * @ingroup HTTP
13 class WebResponse {
15 /**
16 * Output a HTTP header, wrapper for PHP's
17 * header()
18 * @param $string String: header to output
19 * @param $replace Bool: replace current similar header
21 public function header($string, $replace=true) {
22 header($string,$replace);
25 /** Set the browser cookie
26 * @param $name String: name of cookie
27 * @param $value String: value to give cookie
28 * @param $expire Int: number of seconds til cookie expires
30 public function setcookie( $name, $value, $expire = 0 ) {
31 global $wgCookiePath, $wgCookiePrefix, $wgCookieDomain;
32 global $wgCookieSecure,$wgCookieExpiration, $wgCookieHttpOnly;
33 if ( $expire == 0 ) {
34 $expire = time() + $wgCookieExpiration;
36 $httpOnlySafe = wfHttpOnlySafe() && $wgCookieHttpOnly;
37 wfDebugLog( 'cookie',
38 'setcookie: "' . implode( '", "',
39 array(
40 $wgCookiePrefix . $name,
41 $value,
42 $expire,
43 $wgCookiePath,
44 $wgCookieDomain,
45 $wgCookieSecure,
46 $httpOnlySafe ) ) . '"' );
47 setcookie( $wgCookiePrefix . $name,
48 $value,
49 $expire,
50 $wgCookiePath,
51 $wgCookieDomain,
52 $wgCookieSecure,
53 $httpOnlySafe );
58 class FauxResponse extends WebResponse {
59 private $headers;
60 private $cookies;
62 public function header($string, $replace=true) {
63 list($key, $val) = explode(":", $string, 2);
65 if($replace || !isset($this->headers[$key])) {
66 $this->headers[$key] = $val;
70 public function getheader($key) {
71 return $this->headers[$key];
74 public function setcookie( $name, $value, $expire = 0 ) {
75 $this->cookies[$name] = $value;
78 public function getcookie( $name ) {
79 if ( isset($this->cookies[$name]) ) {
80 return $this->cookies[$name];