More visual and xhtml fixes for file cache failback
authorAaron Schulz <aaron@users.mediawiki.org>
Sat, 14 Mar 2009 03:16:05 +0000 (03:16 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Sat, 14 Mar 2009 03:16:05 +0000 (03:16 +0000)
includes/Exception.php
includes/db/Database.php
languages/messages/MessagesEn.php

index 10765bd..5f808b2 100644 (file)
@@ -161,7 +161,7 @@ class MWException extends Exception {
                        if( $hookResult = $this->runHooks( get_class( $this ) . "Raw" ) ) {
                                die( $hookResult );
                        }
-                       if ( defined( 'MEDIAWIKI_INSTALL' ) ) {
+                       if ( defined( 'MEDIAWIKI_INSTALL' ) || $this->htmlBodyOnly() ) {
                                echo $this->getHTML();
                        } else {
                                echo $this->htmlHeader();
@@ -217,6 +217,13 @@ class MWException extends Exception {
        function htmlFooter() {
                echo "</body></html>";
        }
+       
+       /**
+        * headers handled by subclass?
+        */
+       function htmlBodyOnly() {
+               return false;
+       }
 
        static function isCommandLine() {
                return !empty( $GLOBALS['wgCommandLineMode'] ) && !defined( 'MEDIAWIKI_INSTALL' );
index 8d25b2b..abd8f20 100644 (file)
@@ -2586,12 +2586,25 @@ class DBConnectionError extends DBError {
 
                $extra = $this->searchForm();
 
-               if($wgUseFileCache) {
+               if( $wgUseFileCache ) {
                        $cache = $this->fileCachedPage();
-                       if ( $cache !== null ) $extra = $cache;
+                       # Cached version on file system?
+                       if( $cache !== null ) {
+                               # Hack: extend the body for error messages
+                               $cache = str_replace( array('</html>','</body>'), '', $cache );
+                               # Add cache notice...
+                               $cachederror = "This is a cached copy of the requested page, and may not be up to date. ";
+                               # Localize it if possible...
+                               if( $wgLang instanceof Language ) {
+                                       $cachederror = htmlspecialchars( $wgLang->getMessage( 'dberr-cachederror' ) );
+                               }
+                               $warning = "<div style='color:red;font-size:150%;font-weight:bold;'>$cachederror</div>";
+                               # Output cached page with notices on bottom and re-close body
+                               return "{$cache}{$warning}<hr />$text<hr />$extra</body></html>";
+                       }
                }
-
-               return $text . '<hr />' . $extra;
+               # Headers needed here - output is just the error message
+               return $this->htmlHeader()."$text<hr />$extra".$this->htmlFooter();
        }
 
        function searchForm() {
@@ -2635,10 +2648,8 @@ EOT;
        function fileCachedPage() {
                global $wgTitle, $title, $wgLang, $wgOut;
                if( $wgOut->isDisabled() ) return; // Done already?
-               $cachederror = "The following is a cached copy of the requested page, and may not be up to date. ";
                $mainpage = 'Main Page';
                if ( $wgLang instanceof Language ) {
-                       $cachederror = htmlspecialchars( $wgLang->getMessage( 'dberr-cachederror' ) );
                        $mainpage    = htmlspecialchars( $wgLang->getMessage( 'mainpage' ) );
                }
 
@@ -2652,12 +2663,15 @@ EOT;
 
                $cache = new HTMLFileCache( $t );
                if( $cache->isFileCached() ) {
-                       $warning = "<div style='color:red;font-size:150%;font-weight:bold;'>$cachederror</div>";
-                       return $warning . $cache->fetchPageText();
+                       return $cache->fetchPageText();
                } else {
                        return '';
                }
        }
+       
+       function htmlBodyOnly() {
+               return true;
+       }
 
 }
 
index 18dacab..bdc139f 100644 (file)
@@ -3871,6 +3871,6 @@ Enter the filename without the "{{ns:file}}:" prefix.',
 'dberr-info'        => '(Cannot contact the database server: $1)',
 'dberr-usegoogle'   => 'You can try searching via Google in the meantime.',
 'dberr-outofdate'   => 'Note that their indexes of our content may be out of date.',
-'dberr-cachederror' => 'The following is a cached copy of the requested page, and may not be up to date.',
+'dberr-cachederror' => 'This is a cached copy of the requested page, and may not be up to date.',
 
 );