db = $db; parent::__construct( $error ); } /** * @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:
' . nl2br( htmlspecialchars( $this->getTraceAsString() ) ) . '
'; } return $s; } /** * @return string */ protected function getTextContent() { return $this->getMessage(); } /** * @return string */ protected function getHTMLContent() { return '' . nl2br( htmlspecialchars( $this->getMessage() ) ) . '
'; } } /** * @ingroup Database */ class DBConnectionError extends DBError { public $error; 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 $key * @param $fallback * @return string */ function msg( $key, $fallback /*[, params...] */ ) { global $wgLang; $args = array_slice( func_get_args(), 2 ); if ( $this->useMessageCache() ) { $message = $wgLang->getMessage( $key ); } else { $message = $fallback; } return wfMsgReplaceArgs( $message, $args ); } /** * @return boolean */ function isLoggable() { // Don't send to the exception log, already in dberror log return false; } /** * @return string */ function getPageTitle() { return $this->msg( 'dberr-header', 'This wiki has a problem' ); } /** * @return string */ function getHTML() { global $wgShowDBErrorBacktrace, $wgShowHostnames, $wgShowSQLErrors; $sorry = htmlspecialchars( $this->msg( 'dberr-problems', "Sorry!\nThis 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 contact the database server: $1)' ) ) ); } else { $info = htmlspecialchars( $this->msg( 'dberr-info-hidden', '(Cannot contact the database server)' ) ); } # No database access MessageCache::singleton()->disable(); $text = "$again
$info
"; if ( $wgShowDBErrorBacktrace ) { $text .= 'Backtrace:
' . nl2br( htmlspecialchars( $this->getTraceAsString() ) ) . '
'; } $text .= '