From fcd22b9a848f9b996c0057ff280e6a6b7f088da9 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sat, 14 Mar 2009 03:16:05 +0000 Subject: [PATCH] More visual and xhtml fixes for file cache failback --- includes/Exception.php | 9 ++++++++- includes/db/Database.php | 30 ++++++++++++++++++++++-------- languages/messages/MessagesEn.php | 2 +- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/includes/Exception.php b/includes/Exception.php index 10765bd7a7..5f808b2043 100644 --- a/includes/Exception.php +++ b/includes/Exception.php @@ -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 ""; } + + /** + * 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 8d25b2b2af..abd8f201fd 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -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('',''), '', $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 = "
$cachederror
"; + # Output cached page with notices on bottom and re-close body + return "{$cache}{$warning}
$text
$extra"; + } } - - return $text . '
' . $extra; + # Headers needed here - output is just the error message + return $this->htmlHeader()."$text
$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 = "
$cachederror
"; - return $warning . $cache->fetchPageText(); + return $cache->fetchPageText(); } else { return ''; } } + + function htmlBodyOnly() { + return true; + } } diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 18dacab6c9..bdc139f5d3 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -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.', ); -- 2.20.1