r86832 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86831‎ | r86832 | r86833 >
Date:20:14, 24 April 2011
Author:ialex
Status:ok (Comments)
Tags:
Comment:
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()
Modified paths:
  • /trunk/phase3/includes/db/Database.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/db/Database.php
@@ -2930,9 +2930,17 @@
29312931 return false;
29322932 }
29332933
2934 - function useMessageCache() {
2935 - // Not likely to work
2936 - return false;
 2934+ function msg( $key, $fallback /*[, params...] */ ) {
 2935+ global $wgLang;
 2936+
 2937+ $args = array_slice( func_get_args(), 2 );
 2938+
 2939+ if ( $this->useMessageCache() ) {
 2940+ $message = $wgLang->getMessage( $key );
 2941+ } else {
 2942+ $message = $fallback;
 2943+ }
 2944+ return wfMsgReplaceArgs( $message, $args );
29372945 }
29382946
29392947 function getLogMessage() {
@@ -2941,30 +2949,17 @@
29422950 }
29432951
29442952 function getPageTitle() {
2945 - global $wgSitename, $wgLang;
2946 -
2947 - $header = "$wgSitename has a problem";
2948 -
2949 - if ( $wgLang instanceof Language ) {
2950 - $header = htmlspecialchars( $wgLang->getMessage( 'dberr-header' ) );
2951 - }
2952 -
2953 - return $header;
 2953+ global $wgSitename;
 2954+ return htmlspecialchars( $this->msg( 'dberr-header', "$wgSitename has a problem" ) );
29542955 }
29552956
29562957 function getHTML() {
2957 - global $wgLang, $wgUseFileCache, $wgShowDBErrorBacktrace;
 2958+ global $wgUseFileCache, $wgShowDBErrorBacktrace;
29582959
2959 - $sorry = 'Sorry! This site is experiencing technical difficulties.';
2960 - $again = 'Try waiting a few minutes and reloading.';
2961 - $info = '(Can\'t contact the database server: $1)';
 2960+ $sorry = htmlspecialchars( $this->msg( 'dberr-problems', 'Sorry! This site is experiencing technical difficulties.' ) );
 2961+ $again = htmlspecialchars( $this->msg( 'dberr-again', 'Try waiting a few minutes and reloading.' ) );
 2962+ $info = htmlspecialchars( $this->msg( 'dberr-info', '(Can\'t contact the database server: $1)' ) );
29622963
2963 - if ( $wgLang instanceof Language ) {
2964 - $sorry = htmlspecialchars( $wgLang->getMessage( 'dberr-problems' ) );
2965 - $again = htmlspecialchars( $wgLang->getMessage( 'dberr-again' ) );
2966 - $info = htmlspecialchars( $wgLang->getMessage( 'dberr-info' ) );
2967 - }
2968 -
29692964 # No database access
29702965 MessageCache::singleton()->disable();
29712966
@@ -2991,17 +2986,13 @@
29922987 # Hack: extend the body for error messages
29932988 $cache = str_replace( array( '</html>', '</body>' ), '', $cache );
29942989 # Add cache notice...
2995 - $cachederror = "This is a cached copy of the requested page, and may not be up to date. ";
 2990+ $cache .= '<div style="color:red;font-size:150%;font-weight:bold;">'.
 2991+ htmlspecialchars( $this->msg( 'dberr-cachederror',
 2992+ 'This is a cached copy of the requested page, and may not be up to date. ' ) ) .
 2993+ '</div>';
29962994
2997 - # Localize it if possible...
2998 - if ( $wgLang instanceof Language ) {
2999 - $cachederror = htmlspecialchars( $wgLang->getMessage( 'dberr-cachederror' ) );
3000 - }
3001 -
3002 - $warning = "<div style='color:red;font-size:150%;font-weight:bold;'>$cachederror</div>";
3003 -
30042995 # Output cached page with notices on bottom and re-close body
3005 - return "{$cache}{$warning}<hr />$text<hr />$extra</body></html>";
 2996+ return "{$cache}<hr />$text<hr />$extra</body></html>";
30062997 }
30072998 } catch ( MWException $e ) {
30082999 // Do nothing, just use the default page
@@ -3013,18 +3004,12 @@
30143005 }
30153006
30163007 function searchForm() {
3017 - global $wgSitename, $wgServer, $wgLang;
 3008+ global $wgSitename, $wgServer;
30183009
3019 - $usegoogle = "You can try searching via Google in the meantime.";
3020 - $outofdate = "Note that their indexes of our content may be out of date.";
3021 - $googlesearch = "Search";
 3010+ $usegoogle = htmlspecialchars( $this->msg( 'dberr-usegoogle', 'You can try searching via Google in the meantime.' ) );
 3011+ $outofdate = htmlspecialchars( $this->msg( 'dberr-outofdate', 'Note that their indexes of our content may be out of date.' ) );
 3012+ $googlesearch = htmlspecialchars( $this->msg( 'searchbutton', 'Search' ) );
30223013
3023 - if ( $wgLang instanceof Language ) {
3024 - $usegoogle = htmlspecialchars( $wgLang->getMessage( 'dberr-usegoogle' ) );
3025 - $outofdate = htmlspecialchars( $wgLang->getMessage( 'dberr-outofdate' ) );
3026 - $googlesearch = htmlspecialchars( $wgLang->getMessage( 'searchbutton' ) );
3027 - }
3028 -
30293014 $search = htmlspecialchars( @$_REQUEST['search'] );
30303015
30313016 $server = htmlspecialchars( $wgServer );
@@ -3053,22 +3038,16 @@
30543039 }
30553040
30563041 private function fileCachedPage() {
3057 - global $wgTitle, $wgLang, $wgOut;
 3042+ global $wgTitle, $wgOut;
30583043
30593044 if ( $wgOut->isDisabled() ) {
30603045 return; // Done already?
30613046 }
30623047
3063 - $mainpage = 'Main Page';
3064 -
3065 - if ( $wgLang instanceof Language ) {
3066 - $mainpage = htmlspecialchars( $wgLang->getMessage( 'mainpage' ) );
3067 - }
3068 -
30693048 if ( $wgTitle ) {
30703049 $t =& $wgTitle;
30713050 } else {
3072 - $t = Title::newFromText( $mainpage );
 3051+ $t = Title::newFromText( $this->msg( 'mainpage', 'Main Page' ) );
30733052 }
30743053
30753054 $cache = new HTMLFileCache( $t );

Sign-offs

UserFlagDate
Platonidesinspected21:21, 17 May 2011

Comments

#Comment by Brion VIBBER (talk | contribs)   21:37, 14 June 2011

Looks ok; was worried that useMessageCache was removed, but the base class implementation on MWException does the same $wgLang check that was being used previously. Can't-connect-to-db message shows fine in current trunk.

Status & tagging log