MediaWiki r55797 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r55796‎ | r55797 (on ViewVC)‎ | r55798 >
Date:01:49, 4 September 2009
Author:tstarling
Status:ok
Tags:
Comment:
Added $wgShowDBErrorBacktrace, to allow users to easily gather backtraces for database connection and query errors. We've had a few LocalisationCache bugs that required backtraces to track down.
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/db/Database.php
@@ -2420,6 +2420,15 @@
24212421 $this->db =& $db;
24222422 parent::__construct( $error );
24232423 }
 2424+
 2425+ function getText() {
 2426+ global $wgShowDBErrorBacktrace;
 2427+ $s = $this->getMessage() . "\n";
 2428+ if ( $wgShowDBErrorBacktrace ) {
 2429+ $s .= "Backtrace:\n" . $this->getTraceAsString() . "\n";
 2430+ }
 2431+ return $s;
 2432+ }
24242433 }
24252434
24262435 /**
@@ -2447,10 +2456,6 @@
24482457 return false;
24492458 }
24502459
2451 - function getText() {
2452 - return $this->getMessage() . "\n";
2453 - }
2454 -
24552460 function getLogMessage() {
24562461 # Don't send to the exception log
24572462 return false;
@@ -2467,7 +2472,7 @@
24682473 }
24692474
24702475 function getHTML() {
2471 - global $wgLang, $wgMessageCache, $wgUseFileCache;
 2476+ global $wgLang, $wgMessageCache, $wgUseFileCache, $wgShowDBErrorBacktrace;
24722477
24732478 $sorry = 'Sorry! This site is experiencing technical difficulties.';
24742479 $again = 'Try waiting a few minutes and reloading.';
@@ -2491,12 +2496,9 @@
24922497 $noconnect = "<p><strong>$sorry</strong><br />$again</p><p><small>$info</small></p>";
24932498 $text = str_replace( '$1', $this->error, $noconnect );
24942499
2495 - /*
2496 - if ( $GLOBALS['wgShowExceptionDetails'] ) {
2497 - $text .= '</p><p>Backtrace:</p><p>' .
2498 - nl2br( htmlspecialchars( $this->getTraceAsString() ) ) .
2499 - "</p>\n";
2500 - }*/
 2500+ if ( $wgShowDBErrorBacktrace ) {
 2501+ $text .= '<p>Backtrace:</p><p>' . nl2br( htmlspecialchars( $this->getTraceAsString() ) );
 2502+ }
25012503
25022504 $extra = $this->searchForm();
25032505
@@ -2613,11 +2615,16 @@
26142616 }
26152617
26162618 function getText() {
 2619+ global $wgShowDBErrorBacktrace;
26172620 if ( $this->useMessageCache() ) {
2618 - return wfMsg( 'dberrortextcl', htmlspecialchars( $this->getSQL() ),
2619 - htmlspecialchars( $this->fname ), $this->errno, htmlspecialchars( $this->error ) ) . "\n";
 2621+ $s = wfMsg( 'dberrortextcl', htmlspecialchars( $this->getSQL() ),
 2622+ htmlspecialchars( $this->fname ), $this->errno, htmlspecialchars( $this->error ) ) . "\n";
 2623+ if ( $wgShowDBErrorBacktrace ) {
 2624+ $s .= "Backtrace:\n" . $this->getTraceAsString() . "\n";
 2625+ }
 2626+ return $s;
26202627 } else {
2621 - return $this->getMessage();
 2628+ return parent::getText();
26222629 }
26232630 }
26242631
@@ -2640,12 +2647,17 @@
26412648 }
26422649
26432650 function getHTML() {
 2651+ global $wgShowDBErrorBacktrace;
26442652 if ( $this->useMessageCache() ) {
2645 - return wfMsgNoDB( 'dberrortext', htmlspecialchars( $this->getSQL() ),
 2653+ $s = wfMsgNoDB( 'dberrortext', htmlspecialchars( $this->getSQL() ),
26462654 htmlspecialchars( $this->fname ), $this->errno, htmlspecialchars( $this->error ) );
26472655 } else {
2648 - return nl2br( htmlspecialchars( $this->getMessage() ) );
 2656+ $s = nl2br( htmlspecialchars( $this->getMessage() ) );
26492657 }
 2658+ if ( $wgShowDBErrorBacktrace ) {
 2659+ $s .= '<p>Backtrace:</p><p>' . nl2br( htmlspecialchars( $this->getTraceAsString() ) );
 2660+ }
 2661+ return $s;
26502662 }
26512663 }
26522664
Index: trunk/phase3/includes/DefaultSettings.php
@@ -1173,6 +1173,11 @@
11741174 $wgShowExceptionDetails = false;
11751175
11761176 /**
 1177+ * If true, show a backtrace for database errors
 1178+ */
 1179+$wgShowDBErrorBacktrace = false;
 1180+
 1181+/**
11771182 * Expose backend server host names through the API and various HTML comments
11781183 */
11791184 $wgShowHostnames = false;
Index: trunk/phase3/RELEASE-NOTES
@@ -201,6 +201,8 @@
202202 display-in-limit-form.
203203 * (bug 18880) LogEventsList::showLogExtract() can now take a string-by-reference
204204 and add its HTML to it, rather than having to go straight to $wgOut.
 205+* Added $wgShowDBErrorBacktrace, to allow users to easily gather backtraces for
 206+ database connection and query errors.
205207
206208 === Bug fixes in 1.16 ===
207209

Status & tagging log