X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fexception%2FMWExceptionRenderer.php;h=1f1cabeae154d2f0e03729057d17dbc48db99dbc;hb=b7625d63a6f1f8867c911dbd6e93eebdaca3312f;hp=88b28df385df0cd30a39875664cb0db91e77e3f3;hpb=e554e9522693ceedd35684fd5be59d76ed5a2c65;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/exception/MWExceptionRenderer.php b/includes/exception/MWExceptionRenderer.php index 88b28df385..1f1cabeae1 100644 --- a/includes/exception/MWExceptionRenderer.php +++ b/includes/exception/MWExceptionRenderer.php @@ -19,7 +19,6 @@ */ use Wikimedia\Rdbms\DBConnectionError; -use Wikimedia\Rdbms\DBError; use Wikimedia\Rdbms\DBReadOnlyError; use Wikimedia\Rdbms\DBExpectedError; @@ -37,7 +36,7 @@ class MWExceptionRenderer { * @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 @@ -58,7 +57,7 @@ class MWExceptionRenderer { 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 ) . @@ -73,7 +72,7 @@ class MWExceptionRenderer { } $message .= "\n"; } else { - if ( self::showBackTrace( $e ) ) { + if ( $wgShowExceptionDetails ) { $message = MWExceptionHandler::getLogMessage( $e ) . "\nBacktrace:\n" . MWExceptionHandler::getRedactedTraceAsString( $e ) . "\n"; @@ -162,7 +161,9 @@ class MWExceptionRenderer { * @return string Html to output */ public static function getHTML( $e ) { - if ( self::showBackTrace( $e ) ) { + global $wgShowExceptionDetails; + + if ( $wgShowExceptionDetails ) { $html = "

" . nl2br( htmlspecialchars( MWExceptionHandler::getLogMessage( $e ) ) ) . '

Backtrace:

' . @@ -196,12 +197,17 @@ class MWExceptionRenderer { * @return string Message with arguments replaced */ private static function msg( $key, $fallback /*[, params...] */ ) { + global $wgSitename; $args = array_slice( func_get_args(), 2 ); 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 = preg_replace( '/\{\{SITENAME\}\}/', $wgSitename, $res ); } + return $res; } /** @@ -209,7 +215,9 @@ class MWExceptionRenderer { * @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"; @@ -218,34 +226,13 @@ class MWExceptionRenderer { } } - /** - * @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."; } /** @@ -294,7 +281,7 @@ class MWExceptionRenderer { * @param Exception|Throwable $e */ private static function reportOutageHTML( $e ) { - global $wgShowDBErrorBacktrace, $wgShowHostnames, $wgShowSQLErrors, $wgSitename; + global $wgShowExceptionDetails, $wgShowHostnames, $wgSitename; $sorry = htmlspecialchars( self::msg( 'dberr-problems', @@ -305,7 +292,7 @@ class MWExceptionRenderer { 'Try waiting a few minutes and reloading.' ) ); - if ( $wgShowHostnames || $wgShowSQLErrors ) { + if ( $wgShowHostnames ) { $info = str_replace( '$1', Html::element( 'span', [ 'dir' => 'ltr' ], $e->getMessage() ), @@ -327,7 +314,7 @@ class MWExceptionRenderer { '' . "

$sorry

$again

$info

"; - if ( $wgShowDBErrorBacktrace ) { + if ( $wgShowExceptionDetails ) { $html .= '

Backtrace:

' .
 				htmlspecialchars( $e->getTraceAsString() ) . '
'; }