From: Chad Horohoe Date: Tue, 13 May 2014 19:15:06 +0000 (-0700) Subject: MWException: Don't send headers multiple times X-Git-Tag: 1.31.0-rc.0~15722^2 X-Git-Url: http://git.cyclocoop.org/%24self?a=commitdiff_plain;h=cfbeb437a3bf688f07681d8b900f3d0a13f25497;p=lhc%2Fweb%2Fwiklou.git MWException: Don't send headers multiple times Ideally we wouldn't have sent headers yet, but in some weird code paths where we output stuff raw (like Export) we might have already sent them. All depends on when the failure happened. Should silence all of the "headers already sent" being seen from exports. Change-Id: I12e0532e93d30b2255f73a9d0e017c73e30c3e28 --- diff --git a/includes/exception/MWException.php b/includes/exception/MWException.php index 82303b91f6..782a44bdf8 100644 --- a/includes/exception/MWException.php +++ b/includes/exception/MWException.php @@ -219,7 +219,7 @@ class MWException extends Exception { $wgOut->output(); } else { - header( 'Content-Type: text/html; charset=utf-8' ); + self::header( 'Content-Type: text/html; charset=utf-8' ); echo "\n" . '' . // Mimick OutputPage::setPageTitle behaviour @@ -251,14 +251,14 @@ class MWException extends Exception { if ( defined( 'MW_API' ) ) { // Unhandled API exception, we can't be sure that format printer is alive - header( 'MediaWiki-API-Error: internal_api_error_' . get_class( $this ) ); + self::header( 'MediaWiki-API-Error: internal_api_error_' . get_class( $this ) ); wfHttpError( 500, 'Internal Server Error', $this->getText() ); } elseif ( self::isCommandLine() ) { MWExceptionHandler::printError( $this->getText() ); } else { - header( 'HTTP/1.1 500 MediaWiki exception' ); - header( 'Status: 500 MediaWiki exception', true ); - header( "Content-Type: $wgMimeType; charset=utf-8", true ); + self::header( 'HTTP/1.1 500 MediaWiki exception' ); + self::header( 'Status: 500 MediaWiki exception' ); + self::header( "Content-Type: $wgMimeType; charset=utf-8" ); $this->reportHTML(); } @@ -273,4 +273,14 @@ class MWException extends Exception { public static function isCommandLine() { return !empty( $GLOBALS['wgCommandLineMode'] ); } + + /** + * Send a header, if we haven't already sent them. We shouldn't, + * but sometimes we might in a weird case like Export + */ + private static function header( $header ) { + if ( !headers_sent() ) { + header( $header ); + } + } }