Follow-up r85918:
authorHappy-melon <happy-melon@users.mediawiki.org>
Sat, 7 May 2011 14:01:49 +0000 (14:01 +0000)
committerHappy-melon <happy-melon@users.mediawiki.org>
Sat, 7 May 2011 14:01:49 +0000 (14:01 +0000)
* Clean up the ugly adding-then-removing-then-readding HTML <head> and <body> 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
includes/db/Database.php
index.php

index e801278..4c7fb6e 100644 (file)
@@ -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' );
        }
index 7ae7a34..1dac87b 100644 (file)
@@ -2970,6 +2970,13 @@ class DBConnectionError extends DBError {
 
                $extra = $this->searchForm();
 
+               return "$text<hr />$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 {
                                                '</div>';
 
                                        # Output cached page with notices on bottom and re-close body
-                                       return "{$cache}<hr />$text<hr />$extra</body></html>";
+                                       echo "{$cache}<hr />{$this->getHTML()}</body></html>";
+                                       return;
                                }
                        } catch ( MWException $e ) {
                                // Do nothing, just use the default page
                        }
                }
 
-               # Headers needed here - output is just the error message
-               return $this->htmlHeader() . "$text<hr />$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;
-       }
 }
 
 /**
index 249d2c6..ff50131 100644 (file)
--- 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' );
 
        ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">