From 3e86820e5f4287c2a212802ec3ba115fb1e52f3c Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Fri, 22 Apr 2011 18:57:01 +0000 Subject: [PATCH] Added DBError::getContentMessage() to factorise common code; DBUnexpectedError now displays shows like a DB error for consistency with CLI mode --- includes/db/Database.php | 58 ++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/includes/db/Database.php b/includes/db/Database.php index 53e358583d..6b0dfa7560 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -2874,10 +2874,18 @@ class DBError extends MWException { parent::__construct( $error ); } + protected function getContentMessage( $html ) { + if ( $html ) { + return nl2br( htmlspecialchars( $this->getMessage() ) ); + } else { + return $this->getMessage(); + } + } + function getText() { global $wgShowDBErrorBacktrace; - $s = $this->getMessage() . "\n"; + $s = $this->getContentMessage( false ) . "\n"; if ( $wgShowDBErrorBacktrace ) { $s .= "Backtrace:\n" . $this->getTraceAsString() . "\n"; @@ -2885,6 +2893,18 @@ class DBError extends MWException { return $s; } + + function getHTML() { + global $wgShowDBErrorBacktrace; + + $s = $this->getContentMessage( true ); + + if ( $wgShowDBErrorBacktrace ) { + $s .= '

Backtrace:

' . nl2br( htmlspecialchars( $this->getTraceAsString() ) ); + } + + return $s; + } } /** @@ -3084,20 +3104,17 @@ class DBQueryError extends DBError { $this->fname = $fname; } - function getText() { - global $wgShowDBErrorBacktrace; - + function getContentMessage( $html ) { if ( $this->useMessageCache() ) { - $s = wfMsg( 'dberrortextcl', htmlspecialchars( $this->getSQL() ), - htmlspecialchars( $this->fname ), $this->errno, htmlspecialchars( $this->error ) ) . "\n"; - - if ( $wgShowDBErrorBacktrace ) { - $s .= "Backtrace:\n" . $this->getTraceAsString() . "\n"; + $msg = $html ? 'dberrortext' : 'dberrortextcl'; + $ret = wfMsg( $msg, $this->getSQL(), + $this->fname, $this->errno, $this->error ); + if ( $html ) { + $ret = htmlspecialchars( $ret ); } - - return $s; + return $ret; } else { - return parent::getText(); + return parent::getContentMessage( $html ); } } @@ -3119,23 +3136,6 @@ class DBQueryError extends DBError { function getPageTitle() { return $this->msg( 'databaseerror', 'Database error' ); } - - function getHTML() { - global $wgShowDBErrorBacktrace; - - if ( $this->useMessageCache() ) { - $s = wfMsgNoDB( 'dberrortext', htmlspecialchars( $this->getSQL() ), - htmlspecialchars( $this->fname ), $this->errno, htmlspecialchars( $this->error ) ); - } else { - $s = nl2br( htmlspecialchars( $this->getMessage() ) ); - } - - if ( $wgShowDBErrorBacktrace ) { - $s .= '

Backtrace:

' . nl2br( htmlspecialchars( $this->getTraceAsString() ) ); - } - - return $s; - } } /** -- 2.20.1