38 public static function output( $e, $mode, $eNew =
null ) {
41 if ( defined(
'MW_API' ) ) {
43 self::header(
'MediaWiki-API-Error: internal_api_error_' . get_class( $e ) );
44 wfHttpError( 500,
'Internal Server Error', self::getText( $e ) );
45 } elseif ( self::isCommandLine() ) {
47 } elseif ( $mode === self::AS_PRETTY ) {
49 self::header(
"Content-Type: $wgMimeType; charset=utf-8" );
57 self::header(
"Content-Type: $wgMimeType; charset=utf-8" );
59 $message =
"MediaWiki internal error.\n\n";
61 $message .=
'Original exception: ' .
62 MWExceptionHandler::getLogMessage( $e ) .
63 "\nBacktrace:\n" . MWExceptionHandler::getRedactedTraceAsString( $e ) .
64 "\n\nException caught inside exception handler: " .
65 MWExceptionHandler::getLogMessage( $eNew ) .
66 "\nBacktrace:\n" . MWExceptionHandler::getRedactedTraceAsString( $eNew );
68 $message .=
'Original exception: ' .
69 MWExceptionHandler::getPublicLogMessage( $e );
70 $message .=
"\n\nException caught inside exception handler.\n\n" .
75 $message = MWExceptionHandler::getLogMessage( $e ) .
77 MWExceptionHandler::getRedactedTraceAsString( $e ) .
"\n";
79 $message = MWExceptionHandler::getPublicLogMessage( $e );
81 echo nl2br( htmlspecialchars( $message ) ) .
"\n";
91 foreach ( $e->getTrace() as $frame ) {
92 if ( isset( $frame[
'class'] ) && $frame[
'class'] === LocalisationCache::class ) {
102 !empty(
$GLOBALS[
'wgFullyInitialised'] ) &&
104 RequestContext::getMain()->
getTitle() &&
105 !defined(
'MEDIAWIKI_INSTALL' )
117 if ( self::useOutputPage( $e ) ) {
119 $wgOut->prepareErrorPage( $e->getPageTitle() );
121 $wgOut->prepareErrorPage( self::msg(
'readonly',
'Database is locked' ) );
123 $wgOut->prepareErrorPage( self::msg(
'databaseerror',
'Database error' ) );
125 $wgOut->prepareErrorPage( self::msg(
'internalerror',
'Internal error' ) );
132 $wgOut->addHTML( self::getHTML( $e ) );
136 self::header(
'Content-Type: text/html; charset=utf-8' );
137 $pageTitle =
self::msg(
'internalerror',
'Internal error' );
138 echo
"<!DOCTYPE html>\n" .
142 htmlspecialchars( self::msg(
'pagetitle',
"$1 - $wgSitename", $pageTitle ) ) .
144 '<style>body { font-family: sans-serif; margin: 0; padding: 0.5em 2em; }</style>' .
149 echo
"</body></html>\n";
165 $html =
"<div class=\"errorbox mw-content-ltr\"><p>" .
166 nl2br( htmlspecialchars( MWExceptionHandler::getLogMessage( $e ) ) ) .
167 '</p><p>Backtrace:</p><p>' .
168 nl2br( htmlspecialchars( MWExceptionHandler::getRedactedTraceAsString( $e ) ) ) .
171 $logId = WebRequest::getRequestId();
172 $html =
"<div class=\"errorbox mw-content-ltr\">" .
174 '[' . $logId .
'] ' .
175 gmdate(
'Y-m-d H:i:s' ) .
": " .
176 self::msg(
"internalerror-fatal-exception",
177 "Fatal exception of type $1",
180 MWExceptionHandler::getURL()
182 "<!-- " . wordwrap( self::getShowBacktraceError( $e ), 50 ) .
" -->";
203 }
catch ( Exception $e ) {
222 return MWExceptionHandler::getLogMessage( $e ) .
224 MWExceptionHandler::getRedactedTraceAsString( $e ) .
"\n";
235 $var =
'$wgShowExceptionDetails = true;';
236 return "Set $var at the bottom of LocalSettings.php to show detailed debugging information.";
243 return !empty(
$GLOBALS[
'wgCommandLineMode'] );
250 if ( !headers_sent() ) {
259 if ( !headers_sent() ) {
260 HttpStatus::header( $code );
275 if ( defined(
'STDERR' ) ) {
276 fwrite( STDERR, $message );
288 $sorry = htmlspecialchars( self::msg(
290 'Sorry! This site is experiencing technical difficulties.'
292 $again = htmlspecialchars( self::msg(
294 'Try waiting a few minutes and reloading.'
300 Html::element(
'span', [
'dir' =>
'ltr' ], $e->getMessage() ),
301 htmlspecialchars( self::msg(
'dberr-info',
'($1)' ) )
304 $info = htmlspecialchars( self::msg(
306 '(Cannot access the database)'
310 MessageCache::singleton()->disable();
311 $html =
"<!DOCTYPE html>\n" .
316 '<style>body { font-family: sans-serif; margin: 0; padding: 0.5em 2em; }</style>' .
317 "</head><body><h1>$sorry</h1><p>$again</p><p><small>$info</small></p>";
320 $html .=
'<p>Backtrace:</p><pre>' .
321 htmlspecialchars( $e->getTraceAsString() ) .
'</pre>';
324 $html .=
'</body></html>';
$wgMimeType
The default Content-Type header.
$wgShowHostnames
Expose backend server host names through the API and various HTML comments.
$wgSitename
Name of the site.
$wgShowExceptionDetails
If set to true, uncaught exceptions will print the exception message and a complete stack trace to ou...
wfHttpError( $code, $label, $desc)
Provide a simple HTTP error.
wfMsgReplaceArgs( $message, $args)
Replace message parameter keys on the given formatted output.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Class to expose exceptions to the client (API bots, users, admins using CLI scripts)
static printError( $message)
Print a message, if possible to STDERR.
static useOutputPage( $e)
static output( $e, $mode, $eNew=null)
static reportHTML( $e)
Output the exception report using HTML.
static statusHeader( $code)
static msg( $key, $fallback,... $params)
Get a message from i18n.
static reportOutageHTML( $e)
static getHTML( $e)
If $wgShowExceptionDetails is true, return a HTML message with a backtrace to the error,...
static getShowBacktraceError( $e)
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...