Use HttpStatus::header instead of manually crafting header()
Also: * Update wfHttpError() to use uppercase DOCTYPE, to match other code such as Html.php, wfThumbError(), HttpError.php, etc. Change-Id: I4027e7fe1a138b03f78797b6d1bfe7bd1064d360
This commit is contained in:
parent
f57b6af45b
commit
70429dc8a2
9 changed files with 26 additions and 27 deletions
|
|
@ -195,7 +195,7 @@ function wfForbidden( $msg1, $msg2 ) {
|
|||
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
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@ class AjaxResponse {
|
|||
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 );
|
||||
|
|
|
|||
|
|
@ -2129,15 +2129,14 @@ function wfVarDump( $var ) {
|
|||
*/
|
||||
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>' .
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ class StreamFile {
|
|||
) {
|
||||
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 );
|
||||
|
|
@ -126,7 +126,7 @@ class StreamFile {
|
|||
$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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,9 +74,7 @@ class HttpError extends MWException {
|
|||
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();
|
||||
|
|
|
|||
|
|
@ -238,8 +238,7 @@ class MWException extends Exception {
|
|||
} 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();
|
||||
|
|
@ -266,4 +265,9 @@ class MWException extends Exception {
|
|||
header( $header );
|
||||
}
|
||||
}
|
||||
private static function statusHeader( $code ) {
|
||||
if ( !headers_sent() ) {
|
||||
HttpStatus::header( $code );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -804,8 +804,7 @@ class ResourceLoader {
|
|||
// 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;
|
||||
|
|
|
|||
|
|
@ -38,14 +38,14 @@ class SpecialRunJobs extends UnlistedSpecialPage {
|
|||
$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;
|
||||
}
|
||||
|
||||
|
|
@ -55,9 +55,8 @@ class SpecialRunJobs extends UnlistedSpecialPage {
|
|||
$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;
|
||||
}
|
||||
|
||||
|
|
@ -69,9 +68,8 @@ class SpecialRunJobs extends UnlistedSpecialPage {
|
|||
$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;
|
||||
}
|
||||
|
||||
|
|
@ -83,7 +81,8 @@ class SpecialRunJobs extends UnlistedSpecialPage {
|
|||
// 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
|
||||
|
|
|
|||
10
thumb.php
10
thumb.php
|
|
@ -235,7 +235,7 @@ function wfStreamThumb( array $params ) {
|
|||
$imsUnix = strtotime( $imsString );
|
||||
wfRestoreWarnings();
|
||||
if ( wfTimestamp( TS_UNIX, $img->getTimestamp() ) <= $imsUnix ) {
|
||||
header( 'HTTP/1.1 304 Not Modified' );
|
||||
HttpStatus::header( 304 );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -554,14 +554,14 @@ function wfThumbError( $status, $msg ) {
|
|||
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() );
|
||||
|
|
|
|||
Loading…
Reference in a new issue