* header()
* @param $string String: header to output
* @param $replace Bool: replace current similar header
+ * @param $http_response_code null|int Forces the HTTP response code to the specified value.
*/
- public function header($string, $replace=true) {
- header($string,$replace);
+ public function header( $string, $replace = true, $http_response_code = null ) {
+ header( $string, $replace, $http_response_code );
}
- /** Set the browser cookie
+ /**
+ * 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
private $headers;
private $cookies;
- public function header($string, $replace=true) {
- list($key, $val) = explode(":", $string, 2);
+ public function header( $string, $replace = true, $http_response_code = null ) {
+ list( $key, $val ) = explode( ":", $string, 2 );
- if($replace || !isset($this->headers[$key])) {
+ if( $replace || !isset( $this->headers[$key] ) ) {
$this->headers[$key] = $val;
}
}
- public function getheader($key) {
+ public function getheader( $key ) {
return $this->headers[$key];
}
}
public function getcookie( $name ) {
- if ( isset($this->cookies[$name]) ) {
+ if ( isset( $this->cookies[$name] ) ) {
return $this->cookies[$name];
}
}
// Error results should not be cached
$this->setCacheMode( 'private' );
+ global $wgRequest;
+ $response = $wgRequest->response();
$headerStr = 'MediaWiki-API-Error: ' . $errCode;
if ( $e->getCode() === 0 ) {
- header( $headerStr );
+ $response->header( $headerStr );
} else {
- header( $headerStr, true, $e->getCode() );
+ $response->header( $headerStr, true, $e->getCode() );
}
// Reset and print just the error message
}
protected function sendCacheHeaders() {
+ global $wgRequest;
+ $response = $wgRequest->response();
+
if ( $this->mCacheMode == 'private' ) {
- header( 'Cache-Control: private' );
+ $response->header( 'Cache-Control: private' );
return;
}
if ( $this->mCacheMode == 'anon-public-user-private' ) {
global $wgUseXVO, $wgOut;
- header( 'Vary: Accept-Encoding, Cookie' );
+ $response->header( 'Vary: Accept-Encoding, Cookie' );
if ( $wgUseXVO ) {
- header( $wgOut->getXVO() );
+ $response->header( $wgOut->getXVO() );
if ( $wgOut->haveCacheVaryCookies() ) {
// Logged in, mark this request private
- header( 'Cache-Control: private' );
+ $response->header( 'Cache-Control: private' );
return;
}
// Logged out, send normal public headers below
} elseif ( session_id() != '' ) {
// Logged in or otherwise has session (e.g. anonymous users who have edited)
// Mark request private
- header( 'Cache-Control: private' );
+ $response->header( 'Cache-Control: private' );
return;
} // else no XVO and anonymous, send public headers below
}
// Public cache not requested
// Sending a Vary header in this case is harmless, and protects us
// against conditional calls of setCacheMaxAge().
- header( 'Cache-Control: private' );
+ $response->header( 'Cache-Control: private' );
return;
}
// Send an Expires header
$maxAge = min( $this->mCacheControl['s-maxage'], $this->mCacheControl['max-age'] );
$expiryUnixTime = ( $maxAge == 0 ? 1 : time() + $maxAge );
- header( 'Expires: ' . wfTimestamp( TS_RFC2822, $expiryUnixTime ) );
+ $response->header( 'Expires: ' . wfTimestamp( TS_RFC2822, $expiryUnixTime ) );
// Construct the Cache-Control header
$ccHeader = '';
}
}
- header( "Cache-Control: $ccHeader" );
+ $response->header( "Cache-Control: $ccHeader" );
}
/**
$maxLag = $params['maxlag'];
list( $host, $lag ) = wfGetLB()->getMaxLag();
if ( $lag > $maxLag ) {
- header( 'Retry-After: ' . max( intval( $maxLag ), 5 ) );
- header( 'X-Database-Lag: ' . intval( $lag ) );
+ global $wgRequest;
+ $response = $wgRequest->response();
+
+ $response->header( 'Retry-After: ' . max( intval( $maxLag ), 5 ) );
+ $response->header( 'X-Database-Lag: ' . intval( $lag ) );
+
if ( $wgShowHostnames ) {
$this->dieUsage( "Waiting for $host: $lag seconds lagged", 'maxlag' );
} else {