From 068f89d1088e1b15a5447794353118958843782a Mon Sep 17 00:00:00 2001 From: Happy-melon Date: Sat, 7 May 2011 14:01:49 +0000 Subject: [PATCH] Follow-up r85918: * Clean up the ugly adding-then-removing-then-readding HTML and tags in DBConnectionError, deprecates MWException::htmlBodyOnly() * Also deprecates MWException::htmlHeader(), removes code duplication since MWException::reportHTML() can safely call wfDie() and get an output format appropriate for the entry point * Copy a couple of HTML headers (Cache-control, Pragma and Content-type) to the wfDie() implementation. --- includes/Exception.php | 18 ++++++------------ includes/db/Database.php | 18 +++++++++++------- index.php | 4 ++++ 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/includes/Exception.php b/includes/Exception.php index e8012782af..4c7fb6e441 100644 --- a/includes/Exception.php +++ b/includes/Exception.php @@ -188,12 +188,11 @@ class MWException extends Exception { die( $hookResult ); } - if ( defined( 'MEDIAWIKI_INSTALL' ) || $this->htmlBodyOnly() ) { - echo $this->getHTML(); + $html = $this->getHTML(); + if ( defined( 'MEDIAWIKI_INSTALL' ) ) { + echo $html; } else { - echo $this->htmlHeader(); - echo $this->getHTML(); - echo $this->htmlFooter(); + wfDie( $html ); } } } @@ -219,6 +218,7 @@ class MWException extends Exception { /** * Send headers and output the beginning of the html page if not using * $wgOut to output the exception. + * @deprecated since 1.18 call wfDie() if you need to die immediately */ function htmlHeader() { global $wgLogo, $wgLang; @@ -273,18 +273,12 @@ ENDL /** * print the end of the html page if not using $wgOut. + * @deprecated since 1.18 */ function htmlFooter() { return Html::closeElement( 'body' ) . Html::closeElement( 'html' ); } - /** - * headers handled by subclass? - */ - function htmlBodyOnly() { - return false; - } - static function isCommandLine() { return !empty( $GLOBALS['wgCommandLineMode'] ) && !defined( 'MEDIAWIKI_INSTALL' ); } diff --git a/includes/db/Database.php b/includes/db/Database.php index 7ae7a34b13..1dac87bbc4 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -2970,6 +2970,13 @@ class DBConnectionError extends DBError { $extra = $this->searchForm(); + return "$text
$extra"; + } + + public function reportHTML(){ + global $wgUseFileCache; + + # Check whether we can serve a file-cached copy of the page with the error underneath if ( $wgUseFileCache ) { try { $cache = $this->fileCachedPage(); @@ -2984,15 +2991,16 @@ class DBConnectionError extends DBError { ''; # Output cached page with notices on bottom and re-close body - return "{$cache}
$text
$extra"; + echo "{$cache}
{$this->getHTML()}"; + return; } } catch ( MWException $e ) { // Do nothing, just use the default page } } - # Headers needed here - output is just the error message - return $this->htmlHeader() . "$text
$extra" . $this->htmlFooter(); + # We can't, cough and die in the usual fashion + return parent::reportHTML(); } function searchForm() { @@ -3049,10 +3057,6 @@ EOT; return ''; } } - - function htmlBodyOnly() { - return true; - } } /** diff --git a/index.php b/index.php index 249d2c6359..ff50131e3d 100644 --- a/index.php +++ b/index.php @@ -170,6 +170,10 @@ function wfDie( $errorMsg ){ : 'http://upload.wikimedia.org/wikipedia/commons/1/1c/MediaWiki_logo.png'; header( $_SERVER['SERVER_PROTOCOL'] . ' 500 MediaWiki configuration Error', true, 500 ); + header( 'Content-type: text/html; charset=UTF-8' ); + // Don't cache error pages! They cause no end of trouble... + header( 'Cache-control: none' ); + header( 'Pragma: nocache' ); ?> -- 2.20.1