Added $wgShowDBErrorBacktrace, to allow users to easily gather backtraces for databas...
authorTim Starling <tstarling@users.mediawiki.org>
Fri, 4 Sep 2009 01:49:34 +0000 (01:49 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Fri, 4 Sep 2009 01:49:34 +0000 (01:49 +0000)
RELEASE-NOTES
includes/DefaultSettings.php
includes/db/Database.php

index 8a20f61..83fd27d 100644 (file)
@@ -201,6 +201,8 @@ this. Was used when mwEmbed was going to be an extension.
   display-in-limit-form.
 * (bug 18880) LogEventsList::showLogExtract() can now take a string-by-reference
   and add its HTML to it, rather than having to go straight to $wgOut.
+* Added $wgShowDBErrorBacktrace, to allow users to easily gather backtraces for
+  database connection and query errors.
 
 === Bug fixes in 1.16 ===
 
index d5e0555..985a6e4 100644 (file)
@@ -1172,6 +1172,11 @@ $wgColorErrors          = true;
  */
 $wgShowExceptionDetails = false;
 
+/**
+ * If true, show a backtrace for database errors
+ */
+$wgShowDBErrorBacktrace = false;
+
 /**
  * Expose backend server host names through the API and various HTML comments
  */
index a8659b6..34e33db 100644 (file)
@@ -2420,6 +2420,15 @@ class DBError extends MWException {
                $this->db =& $db;
                parent::__construct( $error );
        }
+
+       function getText() {
+               global $wgShowDBErrorBacktrace;
+               $s = $this->getMessage() . "\n";
+               if ( $wgShowDBErrorBacktrace ) {
+                       $s .= "Backtrace:\n" . $this->getTraceAsString() . "\n";
+               }
+               return $s;
+       }
 }
 
 /**
@@ -2447,10 +2456,6 @@ class DBConnectionError extends DBError {
                return false;
        }
        
-       function getText() {
-               return $this->getMessage() . "\n";
-       }
-
        function getLogMessage() {
                # Don't send to the exception log
                return false;
@@ -2467,7 +2472,7 @@ class DBConnectionError extends DBError {
        }
 
        function getHTML() {
-               global $wgLang, $wgMessageCache, $wgUseFileCache;
+               global $wgLang, $wgMessageCache, $wgUseFileCache, $wgShowDBErrorBacktrace;
 
                $sorry = 'Sorry! This site is experiencing technical difficulties.';
                $again = 'Try waiting a few minutes and reloading.';
@@ -2491,12 +2496,9 @@ class DBConnectionError extends DBError {
                $noconnect = "<p><strong>$sorry</strong><br />$again</p><p><small>$info</small></p>";
                $text = str_replace( '$1', $this->error, $noconnect );
 
-               /*
-               if ( $GLOBALS['wgShowExceptionDetails'] ) {
-                       $text .= '</p><p>Backtrace:</p><p>' . 
-                               nl2br( htmlspecialchars( $this->getTraceAsString() ) ) . 
-                               "</p>\n";
-               }*/
+               if ( $wgShowDBErrorBacktrace ) {
+                       $text .= '<p>Backtrace:</p><p>' . nl2br( htmlspecialchars( $this->getTraceAsString() ) );
+               }
 
                $extra = $this->searchForm();
 
@@ -2613,11 +2615,16 @@ class DBQueryError extends DBError {
        }
 
        function getText() {
+               global $wgShowDBErrorBacktrace;
                if ( $this->useMessageCache() ) {
-                       return wfMsg( 'dberrortextcl', htmlspecialchars( $this->getSQL() ),
-                         htmlspecialchars( $this->fname ), $this->errno, htmlspecialchars( $this->error ) ) . "\n";
+                       $s = wfMsg( 'dberrortextcl', htmlspecialchars( $this->getSQL() ),
+                               htmlspecialchars( $this->fname ), $this->errno, htmlspecialchars( $this->error ) ) . "\n";
+                       if ( $wgShowDBErrorBacktrace ) {
+                               $s .= "Backtrace:\n" . $this->getTraceAsString() . "\n";
+                       }
+                       return $s;
                } else {
-                       return $this->getMessage();
+                       return parent::getText();
                }
        }
        
@@ -2640,12 +2647,17 @@ class DBQueryError extends DBError {
        }
 
        function getHTML() {
+               global $wgShowDBErrorBacktrace;
                if ( $this->useMessageCache() ) {
-                       return wfMsgNoDB( 'dberrortext', htmlspecialchars( $this->getSQL() ),
+                       $s = wfMsgNoDB( 'dberrortext', htmlspecialchars( $this->getSQL() ),
                          htmlspecialchars( $this->fname ), $this->errno, htmlspecialchars( $this->error ) );
                } else {
-                       return nl2br( htmlspecialchars( $this->getMessage() ) );
+                       $s = nl2br( htmlspecialchars( $this->getMessage() ) );
+               }
+               if ( $wgShowDBErrorBacktrace ) {
+                       $s .= '<p>Backtrace:</p><p>' . nl2br( htmlspecialchars( $this->getTraceAsString() ) );
                }
+               return $s;
        }
 }