Merge "Remove some ancient upgrade information from release notes"
[lhc/web/wiklou.git] / includes / exception / MWExceptionRenderer.php
index 8fdc417..a569bcd 100644 (file)
@@ -60,9 +60,10 @@ class MWExceptionRenderer {
                                                        MWExceptionHandler::getLogMessage( $eNew ) .
                                                "\nBacktrace:\n" . MWExceptionHandler::getRedactedTraceAsString( $eNew );
                                } else {
-                                       $message .= "Exception caught inside exception handler.\n\n" .
-                                               "Set \$wgShowExceptionDetails = true; at the bottom of LocalSettings.php " .
-                                               "to show detailed debugging information.";
+                                       $message .= 'Original exception: ' .
+                                               MWExceptionHandler::getPublicLogMessage( $e );
+                                       $message .= "\n\nException caught inside exception handler.\n\n" .
+                                               self::getShowBacktraceError( $e );
                                }
                                $message .= "\n";
                        } else {
@@ -74,11 +75,7 @@ class MWExceptionRenderer {
                                        $message = MWExceptionHandler::getPublicLogMessage( $e );
                                }
                        }
-                       if ( self::isCommandLine() ) {
-                               self::printError( $message );
-                       } else {
-                               echo nl2br( htmlspecialchars( $message ) ) . "\n";
-                       }
+                       echo nl2br( htmlspecialchars( $message ) ) . "\n";
                }
        }
 
@@ -210,14 +207,14 @@ class MWExceptionRenderer {
         */
        public static function getHTML( $e ) {
                if ( self::showBackTrace( $e ) ) {
-                       $html = "<div class=\"errorbox\"><p>" .
+                       $html = "<div class=\"errorbox mw-content-ltr\"><p>" .
                                nl2br( htmlspecialchars( MWExceptionHandler::getLogMessage( $e ) ) ) .
                                '</p><p>Backtrace:</p><p>' .
                                nl2br( htmlspecialchars( MWExceptionHandler::getRedactedTraceAsString( $e ) ) ) .
                                "</p></div>\n";
                } else {
                        $logId = WebRequest::getRequestId();
-                       $html = "<div class=\"errorbox\">" .
+                       $html = "<div class=\"errorbox mw-content-ltr\">" .
                                '[' . $logId . '] ' .
                                gmdate( 'Y-m-d H:i:s' ) . ": " .
                                self::msg( "internalerror-fatal-exception",
@@ -226,9 +223,7 @@ class MWExceptionRenderer {
                                        $logId,
                                        MWExceptionHandler::getURL()
                                ) . "</div>\n" .
-                       "<!-- Set \$wgShowExceptionDetails = true; " .
-                       "at the bottom of LocalSettings.php to show detailed " .
-                       "debugging information. -->";
+                               "<!-- " . wordwrap( self::getShowBacktraceError( $e ), 50 ) . " -->";
                }
 
                return $html;
@@ -262,8 +257,7 @@ class MWExceptionRenderer {
                                "\nBacktrace:\n" .
                                MWExceptionHandler::getRedactedTraceAsString( $e ) . "\n";
                } else {
-                       return "Set \$wgShowExceptionDetails = true; " .
-                               "in LocalSettings.php to show detailed debugging information.\n";
+                       return self::getShowBacktraceError( $e );
                }
        }
 
@@ -280,6 +274,23 @@ class MWExceptionRenderer {
                );
        }
 
+       /**
+        * @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";
+       }
+
        /**
         * @return bool
         */