Merge "Replace wgShowExceptionDetails with wgShowDBErrorBacktrace on db errors"
[lhc/web/wiklou.git] / includes / exception / MWExceptionRenderer.php
index 8fdc417..c0f1e84 100644 (file)
@@ -61,8 +61,7 @@ class MWExceptionRenderer {
                                                "\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.";
+                                               self::getShowBacktraceError( $e );
                                }
                                $message .= "\n";
                        } else {
@@ -74,11 +73,7 @@ class MWExceptionRenderer {
                                        $message = MWExceptionHandler::getPublicLogMessage( $e );
                                }
                        }
-                       if ( self::isCommandLine() ) {
-                               self::printError( $message );
-                       } else {
-                               echo nl2br( htmlspecialchars( $message ) ) . "\n";
-                       }
+                       echo nl2br( htmlspecialchars( $message ) ) . "\n";
                }
        }
 
@@ -226,9 +221,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 +255,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 +272,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
         */