db = $db; parent::__construct( $error ); } /** * @param $html string * @return string */ protected function getContentMessage( $html ) { if ( $html ) { return nl2br( htmlspecialchars( $this->getMessage() ) ); } else { return $this->getMessage(); } } /** * @return string */ function getText() { global $wgShowDBErrorBacktrace; $s = $this->getContentMessage( false ) . "\n"; if ( $wgShowDBErrorBacktrace ) { $s .= "Backtrace:\n" . $this->getTraceAsString() . "\n"; } return $s; } /** * @return string */ function getHTML() { global $wgShowDBErrorBacktrace; $s = $this->getContentMessage( true ); if ( $wgShowDBErrorBacktrace ) { $s .= '
Backtrace:
' . nl2br( htmlspecialchars( $this->getTraceAsString() ) ); } return $s; } } /** * @ingroup Database */ class DBConnectionError extends DBError { public $error; function __construct( DatabaseBase &$db, $error = 'unknown error' ) { $msg = 'DB connection error'; if ( trim( $error ) != '' ) { $msg .= ": $error"; } $this->error = $error; parent::__construct( $db, $msg ); } /** * @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 bool */ function getLogMessage() { # Don't send to the exception log return false; } /** * @return string */ function getPageTitle() { global $wgSitename; return htmlspecialchars( $this->msg( 'dberr-header', "$wgSitename has a problem" ) ); } /** * @return string */ function getHTML() { global $wgShowDBErrorBacktrace; $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.' ) ); $info = htmlspecialchars( $this->msg( 'dberr-info', '(Can\'t contact the database server: $1)' ) ); # No database access MessageCache::singleton()->disable(); if ( trim( $this->error ) == '' ) { $this->error = $this->db->getProperty( 'mServer' ); } $this->error = Html::element( 'span', array( 'dir' => 'ltr' ), $this->error ); $noconnect = "
$again
$info
"; $text = str_replace( '$1', $this->error, $noconnect ); if ( $wgShowDBErrorBacktrace ) { $text .= 'Backtrace:
' . nl2br( htmlspecialchars( $this->getTraceAsString() ) ); } $extra = $this->searchForm(); return "$text