*/
use Wikimedia\Rdbms\DBConnectionError;
-use Wikimedia\Rdbms\DBError;
use Wikimedia\Rdbms\DBReadOnlyError;
use Wikimedia\Rdbms\DBExpectedError;
* @param Exception|Throwable|null $eNew New exception from attempting to show the first
*/
public static function output( $e, $mode, $eNew = null ) {
- global $wgMimeType;
+ global $wgMimeType, $wgShowExceptionDetails;
if ( defined( 'MW_API' ) ) {
// Unhandled API exception, we can't be sure that format printer is alive
self::header( "Content-Type: $wgMimeType; charset=utf-8" );
if ( $eNew ) {
$message = "MediaWiki internal error.\n\n";
- if ( self::showBackTrace( $e ) ) {
+ if ( $wgShowExceptionDetails ) {
$message .= 'Original exception: ' .
MWExceptionHandler::getLogMessage( $e ) .
"\nBacktrace:\n" . MWExceptionHandler::getRedactedTraceAsString( $e ) .
}
$message .= "\n";
} else {
- if ( self::showBackTrace( $e ) ) {
+ if ( $wgShowExceptionDetails ) {
$message = MWExceptionHandler::getLogMessage( $e ) .
"\nBacktrace:\n" .
MWExceptionHandler::getRedactedTraceAsString( $e ) . "\n";
* @return string Html to output
*/
public static function getHTML( $e ) {
- if ( self::showBackTrace( $e ) ) {
+ global $wgShowExceptionDetails;
+
+ if ( $wgShowExceptionDetails ) {
$html = "<div class=\"errorbox mw-content-ltr\"><p>" .
nl2br( htmlspecialchars( MWExceptionHandler::getLogMessage( $e ) ) ) .
'</p><p>Backtrace:</p><p>' .
* @return string Message with arguments replaced
*/
private static function msg( $key, $fallback /*[, params...] */ ) {
+ global $wgSitename;
$args = array_slice( func_get_args(), 2 );
+
+ // FIXME: Keep logic in sync with MWException::msg.
try {
- return wfMessage( $key, $args )->text();
+ $res = wfMessage( $key, $args )->text();
} catch ( Exception $e ) {
- return wfMsgReplaceArgs( $fallback, $args );
+ $res = wfMsgReplaceArgs( $fallback, $args );
+ // If an exception happens inside message rendering,
+ // {{SITENAME}} sometimes won't be replaced.
+ $res = strtr( $res, [
+ '{{SITENAME}}' => $wgSitename,
+ ] );
}
+ return $res;
}
/**
* @return string
*/
private static function getText( $e ) {
- if ( self::showBackTrace( $e ) ) {
+ global $wgShowExceptionDetails;
+
+ if ( $wgShowExceptionDetails ) {
return MWExceptionHandler::getLogMessage( $e ) .
"\nBacktrace:\n" .
MWExceptionHandler::getRedactedTraceAsString( $e ) . "\n";
}
}
- /**
- * @param Exception|Throwable $e
- * @return bool
- */
- private static function showBackTrace( $e ) {
- global $wgShowExceptionDetails, $wgShowDBErrorBacktrace;
-
- return (
- $wgShowExceptionDetails &&
- ( !( $e instanceof DBError ) || $wgShowDBErrorBacktrace )
- );
- }
-
/**
* @param Exception|Throwable $e
* @return string
*/
private static function getShowBacktraceError( $e ) {
- global $wgShowExceptionDetails, $wgShowDBErrorBacktrace;
- $vars = [];
- if ( !$wgShowExceptionDetails ) {
- $vars[] = '$wgShowExceptionDetails = true;';
- }
- if ( $e instanceof DBError && !$wgShowDBErrorBacktrace ) {
- $vars[] = '$wgShowDBErrorBacktrace = true;';
- }
- $vars = implode( ' and ', $vars );
- return "Set $vars at the bottom of LocalSettings.php to show detailed debugging information.";
+ $var = '$wgShowExceptionDetails = true;';
+ return "Set $var at the bottom of LocalSettings.php to show detailed debugging information.";
}
/**
*/
private static function printError( $message ) {
// NOTE: STDERR may not be available, especially if php-cgi is used from the
- // command line (bug #15602). Try to produce meaningful output anyway. Using
+ // command line (T17602). Try to produce meaningful output anyway. Using
// echo may corrupt output to STDOUT though.
if ( defined( 'STDERR' ) ) {
fwrite( STDERR, $message );
* @param Exception|Throwable $e
*/
private static function reportOutageHTML( $e ) {
- global $wgShowDBErrorBacktrace, $wgShowHostnames, $wgShowSQLErrors, $wgSitename;
+ global $wgShowExceptionDetails, $wgShowHostnames, $wgSitename;
$sorry = htmlspecialchars( self::msg(
'dberr-problems',
'Try waiting a few minutes and reloading.'
) );
- if ( $wgShowHostnames || $wgShowSQLErrors ) {
+ if ( $wgShowHostnames ) {
$info = str_replace(
'$1',
Html::element( 'span', [ 'dir' => 'ltr' ], $e->getMessage() ),
'<style>body { font-family: sans-serif; margin: 0; padding: 0.5em 2em; }</style>' .
"</head><body><h1>$sorry</h1><p>$again</p><p><small>$info</small></p>";
- if ( $wgShowDBErrorBacktrace ) {
+ if ( $wgShowExceptionDetails ) {
$html .= '<p>Backtrace:</p><pre>' .
htmlspecialchars( $e->getTraceAsString() ) . '</pre>';
}