db = $db; parent::__construct( $error ); } } /** * Base class for the more common types of database errors. These are known to occur * frequently, so we try to give friendly error messages for them. * * @ingroup Database * @since 1.23 */ class DBExpectedError extends DBError { /** * @return string */ function getText() { global $wgShowDBErrorBacktrace; $s = $this->getTextContent() . "\n"; if ( $wgShowDBErrorBacktrace ) { $s .= "Backtrace:\n" . $this->getTraceAsString() . "\n"; } return $s; } /** * @return string */ function getHTML() { global $wgShowDBErrorBacktrace; $s = $this->getHTMLContent(); if ( $wgShowDBErrorBacktrace ) { $s .= '
Backtrace:
' . htmlspecialchars( $this->getTraceAsString() ) . ''; } return $s; } /** * @return string */ protected function getTextContent() { return $this->getMessage(); } /** * @return string */ protected function getHTMLContent() { return '
' . nl2br( htmlspecialchars( $this->getTextContent() ) ) . '
'; } } /** * @ingroup Database */ class DBConnectionError extends DBExpectedError { /** @var string Error text */ public $error; /** * @param DatabaseBase $db Object throwing the error * @param string $error Error text */ function __construct( DatabaseBase $db = null, $error = 'unknown error' ) { $msg = 'DB connection error'; if ( trim( $error ) != '' ) { $msg .= ": $error"; } elseif ( $db ) { $error = $this->db->getServer(); } parent::__construct( $db, $msg ); $this->error = $error; } /** * @return bool */ function useOutputPage() { // Not likely to work return false; } /** * @param string $key * @param string $fallback Unescaped alternative error text in case the * message cache cannot be used. Can contain parameters as in regular * messages, that should be passed as additional parameters. * @return string Unprocessed plain error text with parameters replaced */ function msg( $key, $fallback /*[, params...] */ ) { $args = array_slice( func_get_args(), 2 ); if ( $this->useMessageCache() ) { return wfMessage( $key, $args )->useDatabase( false )->text(); } else { return wfMsgReplaceArgs( $fallback, $args ); } } /** * @return bool */ function isLoggable() { // Don't send to the exception log, already in dberror log return false; } /** * @return string Safe HTML */ function getHTML() { global $wgShowDBErrorBacktrace, $wgShowHostnames, $wgShowSQLErrors; $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.' ) ); if ( $wgShowHostnames || $wgShowSQLErrors ) { $info = str_replace( '$1', Html::element( 'span', array( 'dir' => 'ltr' ), $this->error ), htmlspecialchars( $this->msg( 'dberr-info', '(Cannot access the database: $1)' ) ) ); } else { $info = htmlspecialchars( $this->msg( 'dberr-info-hidden', '(Cannot access the database)' ) ); } # No database access MessageCache::singleton()->disable(); $html = "$again
$info
"; if ( $wgShowDBErrorBacktrace ) { $html .= 'Backtrace:
' . htmlspecialchars( $this->getTraceAsString() ) . ''; } $html .= '