MediaWiki  1.23.2
WebResponse.php
Go to the documentation of this file.
1 <?php
28 class WebResponse {
29 
36  public function header( $string, $replace = true, $http_response_code = null ) {
37  header( $string, $replace, $http_response_code );
38  }
39 
59  public function setcookie( $name, $value, $expire = 0, $options = null ) {
60  global $wgCookiePath, $wgCookiePrefix, $wgCookieDomain;
61  global $wgCookieSecure, $wgCookieExpiration, $wgCookieHttpOnly;
62 
63  if ( !is_array( $options ) ) {
64  // Backwards compatability
65  $options = array( 'prefix' => $options );
66  if ( func_num_args() >= 5 ) {
67  $options['domain'] = func_get_arg( 4 );
68  }
69  if ( func_num_args() >= 6 ) {
70  $options['secure'] = func_get_arg( 5 );
71  }
72  }
73  $options = array_filter( $options, function ( $a ) {
74  return $a !== null;
75  } ) + array(
76  'prefix' => $wgCookiePrefix,
77  'domain' => $wgCookieDomain,
78  'path' => $wgCookiePath,
79  'secure' => $wgCookieSecure,
80  'httpOnly' => $wgCookieHttpOnly,
81  'raw' => false,
82  );
83 
84  if ( $expire === null ) {
85  $expire = 0; // Session cookie
86  } elseif ( $expire == 0 && $wgCookieExpiration != 0 ) {
87  $expire = time() + $wgCookieExpiration;
88  }
89 
90  $func = $options['raw'] ? 'setrawcookie' : 'setcookie';
91 
92  if ( wfRunHooks( 'WebResponseSetCookie', array( &$name, &$value, &$expire, $options ) ) ) {
93  wfDebugLog( 'cookie',
94  $func . ': "' . implode( '", "',
95  array(
96  $options['prefix'] . $name,
97  $value,
98  $expire,
99  $options['path'],
100  $options['domain'],
101  $options['secure'],
102  $options['httpOnly'] ) ) . '"' );
103 
104  call_user_func( $func,
105  $options['prefix'] . $name,
106  $value,
107  $expire,
108  $options['path'],
109  $options['domain'],
110  $options['secure'],
111  $options['httpOnly'] );
112  }
113  }
114 }
115 
119 class FauxResponse extends WebResponse {
120  private $headers;
121  private $cookies;
122  private $code;
123 
130  public function header( $string, $replace = true, $http_response_code = null ) {
131  if ( substr( $string, 0, 5 ) == 'HTTP/' ) {
132  $parts = explode( ' ', $string, 3 );
133  $this->code = intval( $parts[1] );
134  } else {
135  list( $key, $val ) = array_map( 'trim', explode( ":", $string, 2 ) );
136 
137  $key = strtoupper( $key );
138 
139  if ( $replace || !isset( $this->headers[$key] ) ) {
140  $this->headers[$key] = $val;
141  }
142  }
143 
144  if ( $http_response_code !== null ) {
145  $this->code = intval( $http_response_code );
146  }
147  }
148 
153  public function getheader( $key ) {
154  $key = strtoupper( $key );
155 
156  if ( isset( $this->headers[$key] ) ) {
157  return $this->headers[$key];
158  }
159  return null;
160  }
161 
167  public function getStatusCode() {
168  return $this->code;
169  }
170 
179  public function setcookie( $name, $value, $expire = 0, $options = null ) {
180  $this->cookies[$name] = $value;
181  }
182 
187  public function getcookie( $name ) {
188  if ( isset( $this->cookies[$name] ) ) {
189  return $this->cookies[$name];
190  }
191  return null;
192  }
193 }
cookies
it sets a lot of them automatically from cookies
Definition: design.txt:93
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
FauxResponse\$code
$code
Definition: WebResponse.php:122
wfDebugLog
wfDebugLog( $logGroup, $text, $dest='all')
Send a line to a supplementary debug log file, if configured, or main debug log if not.
Definition: GlobalFunctions.php:1040
$wgCookiePrefix
if( $wgRCFilterByAge) if( $wgSkipSkin) if( $wgLocalInterwiki) if( $wgSharedPrefix===false) if(! $wgCookiePrefix) $wgCookiePrefix
Definition: Setup.php:286
WebResponse\header
header( $string, $replace=true, $http_response_code=null)
Output a HTTP header, wrapper for PHP's header()
Definition: WebResponse.php:36
WebResponse\setcookie
setcookie( $name, $value, $expire=0, $options=null)
Set the browser cookie.
Definition: WebResponse.php:59
FauxResponse\$headers
$headers
Definition: WebResponse.php:120
FauxResponse\header
header( $string, $replace=true, $http_response_code=null)
Stores a HTTP header.
Definition: WebResponse.php:130
wfRunHooks
wfRunHooks( $event, array $args=array(), $deprecatedVersion=null)
Call hook functions defined in $wgHooks.
Definition: GlobalFunctions.php:4001
FauxResponse\getheader
getheader( $key)
Definition: WebResponse.php:153
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
list
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
$options
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition: hooks.txt:1530
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
$value
$value
Definition: styleTest.css.php:45
FauxResponse
Definition: WebResponse.php:119
FauxResponse\getStatusCode
getStatusCode()
Get the HTTP response code, null if not set.
Definition: WebResponse.php:167
FauxResponse\setcookie
setcookie( $name, $value, $expire=0, $options=null)
Definition: WebResponse.php:179
code
and how to run hooks for an and one after Each event has a preferably in CamelCase For ArticleDelete hook A clump of code and data that should be run when an event happens This can be either a function and a chunk of or an object and a method hook function The function part of a third party developers and administrators to define code that will be run at certain points in the mainline code
Definition: hooks.txt:23
WebResponse
Allow programs to request this object from WebRequest::response() and handle all outputting (or lack ...
Definition: WebResponse.php:28
FauxResponse\$cookies
$cookies
Definition: WebResponse.php:121
FauxResponse\getcookie
getcookie( $name)
Definition: WebResponse.php:187
headers
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add headers
Definition: design.txt:12