wfMessage( $msg2, $args )->inLanguage( 'en' )->text()
);
- header( 'HTTP/1.0 403 Forbidden' );
+ HttpStatus::header( 403 );
header( 'Cache-Control: no-cache' );
header( 'Content-Type: text/html; charset=utf-8' );
echo <<<ENDS
function sendHeaders() {
if ( $this->mResponseCode ) {
$n = preg_replace( '/^ *(\d+)/', '\1', $this->mResponseCode );
- header( "Status: " . $this->mResponseCode, true, (int)$n );
+ HttpStatus::header( $n );
}
header ( "Content-Type: " . $this->mContentType );
*/
function wfHttpError( $code, $label, $desc ) {
global $wgOut;
- header( "HTTP/1.0 $code $label" );
- header( "Status: $code $label" );
+ HttpStatus::header( $code );
if ( $wgOut ) {
$wgOut->disable();
$wgOut->sendCacheControl();
}
header( 'Content-type: text/html; charset=utf-8' );
- print "<!doctype html>" .
+ print '<!DOCTYPE html>' .
'<html><head><title>' .
htmlspecialchars( $label ) .
'</title></head><body><h1>' .
) {
if ( !is_array( $info ) ) {
if ( $sendErrors ) {
- header( 'HTTP/1.0 404 Not Found' );
+ HttpStatus::header( 404 );
header( 'Cache-Control: no-cache' );
header( 'Content-Type: text/html; charset=utf-8' );
$encFile = htmlspecialchars( $path );
$modsince = preg_replace( '/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE'] );
if ( wfTimestamp( TS_UNIX, $info['mtime'] ) <= strtotime( $modsince ) ) {
ini_set( 'zlib.output_compression', 0 );
- header( "HTTP/1.0 304 Not Modified" );
+ HttpStatus::header( 304 );
return self::NOT_MODIFIED; // ok
}
}
public function report() {
$this->doLog();
- $httpMessage = HttpStatus::getMessage( $this->httpCode );
-
- header( "Status: {$this->httpCode} {$httpMessage}", true, $this->httpCode );
+ HttpStatus::header( $this->httpCode );
header( 'Content-type: text/html; charset=utf-8' );
print $this->getHTML();
} elseif ( self::isCommandLine() ) {
MWExceptionHandler::printError( $this->getText() );
} else {
- self::header( 'HTTP/1.1 500 Internal Server Error' );
- self::header( 'Status: 500 Internal Server Error' );
+ self::statusHeader( 500 );
self::header( "Content-Type: $wgMimeType; charset=utf-8" );
$this->reportHTML();
header( $header );
}
}
+ private static function statusHeader( $code ) {
+ if ( !headers_sent() ) {
+ HttpStatus::header( $code );
+ }
+ }
}
// sending the 304.
wfResetOutputBuffers( /* $resetGzipEncoding = */ true );
- header( 'HTTP/1.0 304 Not Modified' );
- header( 'Status: 304 Not Modified' );
+ HttpStatus::header( 304 );
$this->sendResponseHeaders( $context, $etag, false );
return true;
$this->getOutput()->disable();
if ( wfReadOnly() ) {
- header( "HTTP/1.0 423 Locked" );
+ // HTTP 423 Locked
+ HttpStatus::header( 423 );
print 'Wiki is in read-only mode';
return;
} elseif ( !$this->getRequest()->wasPosted() ) {
- header( "HTTP/1.0 400 Bad Request" );
+ HttpStatus::header( 400 );
print 'Request must be POSTed';
-
return;
}
$params = array_intersect_key( $this->getRequest()->getValues(), $required + $optional );
$missing = array_diff_key( $required, $params );
if ( count( $missing ) ) {
- header( "HTTP/1.0 400 Bad Request" );
+ HttpStatus::header( 400 );
print 'Missing parameters: ' . implode( ', ', array_keys( $missing ) );
-
return;
}
$verified = is_string( $providedSignature )
&& hash_equals( $correctSignature, $providedSignature );
if ( !$verified || $params['sigexpiry'] < time() ) {
- header( "HTTP/1.0 400 Bad Request" );
+ HttpStatus::header( 400 );
print 'Invalid or stale signature provided';
-
return;
}
// but it needs to know when it is safe to disconnect. Until this
// reaches ignore_user_abort(), it is not safe as the jobs won't run.
ignore_user_abort( true ); // jobs may take a bit of time
- header( "HTTP/1.0 202 Accepted" );
+ // HTTP 202 Accepted
+ HttpStatus::header( 202 );
ob_flush();
flush();
// Once the client receives this response, it can disconnect
$imsUnix = strtotime( $imsString );
wfRestoreWarnings();
if ( wfTimestamp( TS_UNIX, $img->getTimestamp() ) <= $imsUnix ) {
- header( 'HTTP/1.1 304 Not Modified' );
+ HttpStatus::header( 304 );
return;
}
}
header( 'Cache-Control: no-cache' );
header( 'Content-Type: text/html; charset=utf-8' );
if ( $status == 400 ) {
- header( 'HTTP/1.1 400 Bad request' );
+ HttpStatus::header( 400 );
} elseif ( $status == 404 ) {
- header( 'HTTP/1.1 404 Not found' );
+ HttpStatus::header( 404 );
} elseif ( $status == 403 ) {
- header( 'HTTP/1.1 403 Forbidden' );
+ HttpStatus::header( 403 );
header( 'Vary: Cookie' );
} else {
- header( 'HTTP/1.1 500 Internal server error' );
+ HttpStatus::header( 500 );
}
if ( $wgShowHostnames ) {
header( 'X-MW-Thumbnail-Renderer: ' . wfHostname() );