1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
<?php
/**
* Allow programs to request this object from WebRequest::response()
* and handle all outputting (or lack of outputting) via it.
* @ingroup HTTP
*/
class WebResponse {
/**
* Output a HTTP header, wrapper for PHP's
* header()
* @param $string String: header to output
* @param $replace Bool: replace current similar header
*/
public function header($string, $replace=true) {
header($string,$replace);
}
/** Set the browser cookie
* @param $name String: name of cookie
* @param $value String: value to give cookie
* @param $expire Int: number of seconds til cookie expires
*/
public function setcookie( $name, $value, $expire = 0 ) {
global $wgCookiePath, $wgCookiePrefix, $wgCookieDomain;
global $wgCookieSecure,$wgCookieExpiration, $wgCookieHttpOnly;
if ( $expire == 0 ) {
$expire = time() + $wgCookieExpiration;
}
$httpOnlySafe = wfHttpOnlySafe();
wfDebugLog( 'cookie',
'setcookie: "' . implode( '", "',
array(
$wgCookiePrefix . $name,
$value,
$expire,
$wgCookiePath,
$wgCookieDomain,
$wgCookieSecure,
$httpOnlySafe && $wgCookieHttpOnly ) ) . '"' );
if( $httpOnlySafe && isset( $wgCookieHttpOnly ) ) {
setcookie( $wgCookiePrefix . $name,
$value,
$expire,
$wgCookiePath,
$wgCookieDomain,
$wgCookieSecure,
$wgCookieHttpOnly );
} else {
// setcookie() fails on PHP 5.1 if you give it future-compat paramters.
// stab stab!
setcookie( $wgCookiePrefix . $name,
$value,
$expire,
$wgCookiePath,
$wgCookieDomain,
$wgCookieSecure );
}
}
}
class FauxResponse extends WebResponse {
private $headers;
private $cookies;
public function header($string, $replace=true) {
list($key, $val) = explode(":", $string, 2);
if($replace || !isset($this->headers[$key])) {
$this->headers[$key] = $val;
}
}
public function getheader($key) {
return $this->headers[$key];
}
public function setcookie( $name, $value, $expire = 0 ) {
$this->cookies[$name] = $value;
}
public function getcookie( $name ) {
if ( isset($this->cookies[$name]) ) {
return $this->cookies[$name];
}
}
}
|