From 7e85ce3a030cd20d692548d9089195d5f1e0d95c Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Sun, 24 Apr 2011 20:14:43 +0000 Subject: [PATCH] In DBConnectionError: * Reimplement msg() instead of forcing useMessageCache() to false * Use that version of msg() instead of always checking for $wgLang * Simplify a bit fileCachedPage() --- includes/db/Database.php | 77 +++++++++++++++------------------------- 1 file changed, 28 insertions(+), 49 deletions(-) diff --git a/includes/db/Database.php b/includes/db/Database.php index 6b0dfa7560..4d2d3357ba 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -2930,9 +2930,17 @@ class DBConnectionError extends DBError { return false; } - function useMessageCache() { - // Not likely to work - return false; + function msg( $key, $fallback /*[, params...] */ ) { + global $wgLang; + + $args = array_slice( func_get_args(), 2 ); + + if ( $this->useMessageCache() ) { + $message = $wgLang->getMessage( $key ); + } else { + $message = $fallback; + } + return wfMsgReplaceArgs( $message, $args ); } function getLogMessage() { @@ -2941,29 +2949,16 @@ class DBConnectionError extends DBError { } function getPageTitle() { - global $wgSitename, $wgLang; - - $header = "$wgSitename has a problem"; - - if ( $wgLang instanceof Language ) { - $header = htmlspecialchars( $wgLang->getMessage( 'dberr-header' ) ); - } - - return $header; + global $wgSitename; + return htmlspecialchars( $this->msg( 'dberr-header', "$wgSitename has a problem" ) ); } function getHTML() { - global $wgLang, $wgUseFileCache, $wgShowDBErrorBacktrace; - - $sorry = 'Sorry! This site is experiencing technical difficulties.'; - $again = 'Try waiting a few minutes and reloading.'; - $info = '(Can\'t contact the database server: $1)'; + global $wgUseFileCache, $wgShowDBErrorBacktrace; - if ( $wgLang instanceof Language ) { - $sorry = htmlspecialchars( $wgLang->getMessage( 'dberr-problems' ) ); - $again = htmlspecialchars( $wgLang->getMessage( 'dberr-again' ) ); - $info = htmlspecialchars( $wgLang->getMessage( 'dberr-info' ) ); - } + $sorry = htmlspecialchars( $this->msg( 'dberr-problems', 'Sorry! This site is experiencing technical difficulties.' ) ); + $again = htmlspecialchars( $this->msg( 'dberr-again', 'Try waiting a few minutes and reloading.' ) ); + $info = htmlspecialchars( $this->msg( 'dberr-info', '(Can\'t contact the database server: $1)' ) ); # No database access MessageCache::singleton()->disable(); @@ -2991,17 +2986,13 @@ class DBConnectionError extends DBError { # 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
"; + $cache .= '
'. + htmlspecialchars( $this->msg( 'dberr-cachederror', + 'This is a cached copy of the requested page, and may not be up to date. ' ) ) . + '
'; # Output cached page with notices on bottom and re-close body - return "{$cache}{$warning}
$text
$extra"; + return "{$cache}
$text
$extra"; } } catch ( MWException $e ) { // Do nothing, just use the default page @@ -3013,17 +3004,11 @@ class DBConnectionError extends DBError { } function searchForm() { - global $wgSitename, $wgServer, $wgLang; + global $wgSitename, $wgServer; - $usegoogle = "You can try searching via Google in the meantime."; - $outofdate = "Note that their indexes of our content may be out of date."; - $googlesearch = "Search"; - - if ( $wgLang instanceof Language ) { - $usegoogle = htmlspecialchars( $wgLang->getMessage( 'dberr-usegoogle' ) ); - $outofdate = htmlspecialchars( $wgLang->getMessage( 'dberr-outofdate' ) ); - $googlesearch = htmlspecialchars( $wgLang->getMessage( 'searchbutton' ) ); - } + $usegoogle = htmlspecialchars( $this->msg( 'dberr-usegoogle', 'You can try searching via Google in the meantime.' ) ); + $outofdate = htmlspecialchars( $this->msg( 'dberr-outofdate', 'Note that their indexes of our content may be out of date.' ) ); + $googlesearch = htmlspecialchars( $this->msg( 'searchbutton', 'Search' ) ); $search = htmlspecialchars( @$_REQUEST['search'] ); @@ -3053,22 +3038,16 @@ EOT; } private function fileCachedPage() { - global $wgTitle, $wgLang, $wgOut; + global $wgTitle, $wgOut; if ( $wgOut->isDisabled() ) { return; // Done already? } - $mainpage = 'Main Page'; - - if ( $wgLang instanceof Language ) { - $mainpage = htmlspecialchars( $wgLang->getMessage( 'mainpage' ) ); - } - if ( $wgTitle ) { $t =& $wgTitle; } else { - $t = Title::newFromText( $mainpage ); + $t = Title::newFromText( $this->msg( 'mainpage', 'Main Page' ) ); } $cache = new HTMLFileCache( $t ); -- 2.20.1