40 public static function output( Throwable $e, $mode, Throwable $eNew =
null ) {
43 if ( function_exists(
'apache_setenv' ) ) {
47 AtEase\AtEase::suppressWarnings();
48 apache_setenv(
'no-gzip',
'1' );
49 AtEase\AtEase::restoreWarnings();
52 if ( defined(
'MW_API' ) ) {
53 self::header(
'MediaWiki-API-Error: internal_api_error_' . get_class( $e ) );
56 if ( self::isCommandLine() ) {
58 } elseif ( $mode === self::AS_PRETTY ) {
60 self::header(
"Content-Type: $wgMimeType; charset=UTF-8" );
72 self::header(
"Content-Type: $wgMimeType; charset=UTF-8" );
74 $message =
"MediaWiki internal error.\n\n";
76 $message .=
'Original exception: ' .
77 MWExceptionHandler::getLogMessage( $e ) .
78 "\nBacktrace:\n" . MWExceptionHandler::getRedactedTraceAsString( $e ) .
79 "\n\nException caught inside exception handler: " .
80 MWExceptionHandler::getLogMessage( $eNew ) .
81 "\nBacktrace:\n" . MWExceptionHandler::getRedactedTraceAsString( $eNew );
83 $message .=
'Original exception: ' .
84 MWExceptionHandler::getPublicLogMessage( $e );
85 $message .=
"\n\nException caught inside exception handler.\n\n" .
90 $message = MWExceptionHandler::getLogMessage( $e ) .
92 MWExceptionHandler::getRedactedTraceAsString( $e ) .
"\n";
94 $message = MWExceptionHandler::getPublicLogMessage( $e );
96 print nl2br( htmlspecialchars( $message ) ) .
"\n";
108 foreach ( $e->getTrace() as $frame ) {
109 if ( isset( $frame[
'class'] ) && $frame[
'class'] === LocalisationCache::class ) {
119 !empty(
$GLOBALS[
'wgFullyInitialised'] ) &&
121 RequestContext::getMain()->
getTitle() &&
122 !defined(
'MEDIAWIKI_INSTALL' ) &&
136 if ( self::useOutputPage( $e ) ) {
138 $wgOut->prepareErrorPage( $e->getPageTitle() );
140 $wgOut->prepareErrorPage( self::msg(
'readonly',
'Database is locked' ) );
142 $wgOut->prepareErrorPage( self::msg(
'databaseerror',
'Database error' ) );
144 $wgOut->prepareErrorPage( self::msg(
'internalerror',
'Internal error' ) );
151 $wgOut->addHTML( self::getHTML( $e ) );
155 self::header(
'Content-Type: text/html; charset=utf-8' );
156 $pageTitle =
self::msg(
'internalerror',
'Internal error' );
157 echo
"<!DOCTYPE html>\n" .
161 htmlspecialchars( self::msg(
'pagetitle',
"$1 - $wgSitename", $pageTitle ) ) .
163 '<style>body { font-family: sans-serif; margin: 0; padding: 0.5em 2em; }</style>' .
168 echo
"</body></html>\n";
180 public static function getHTML( Throwable $e ) {
184 $html =
"<div class=\"errorbox mw-content-ltr\"><p>" .
185 nl2br( htmlspecialchars( MWExceptionHandler::getLogMessage( $e ) ) ) .
186 '</p><p>Backtrace:</p><p>' .
187 nl2br( htmlspecialchars( MWExceptionHandler::getRedactedTraceAsString( $e ) ) ) .
190 $logId = WebRequest::getRequestId();
191 $html =
"<div class=\"errorbox mw-content-ltr\">" .
193 '[' . $logId .
'] ' .
194 gmdate(
'Y-m-d H:i:s' ) .
": " .
195 self::msg(
"internalerror-fatal-exception",
196 "Fatal exception of type $1",
199 MWExceptionHandler::getURL()
201 "<!-- " . wordwrap( self::getShowBacktraceError( $e ), 50 ) .
" -->";
222 }
catch ( Exception $e ) {
237 private static function getText( Throwable $e ) {
241 return MWExceptionHandler::getLogMessage( $e ) .
243 MWExceptionHandler::getRedactedTraceAsString( $e ) .
"\n";
254 $var =
'$wgShowExceptionDetails = true;';
255 return "Set $var at the bottom of LocalSettings.php to show detailed debugging information.";
262 return !empty(
$GLOBALS[
'wgCommandLineMode'] );
269 if ( !headers_sent() ) {
278 if ( !headers_sent() ) {
279 HttpStatus::header( $code );
294 if ( defined(
'STDERR' ) ) {
295 fwrite( STDERR, $message );
307 $sorry = htmlspecialchars( self::msg(
309 'Sorry! This site is experiencing technical difficulties.'
311 $again = htmlspecialchars( self::msg(
313 'Try waiting a few minutes and reloading.'
319 Html::element(
'span', [
'dir' =>
'ltr' ], $e->getMessage() ),
320 htmlspecialchars( self::msg(
'dberr-info',
'($1)' ) )
323 $info = htmlspecialchars( self::msg(
325 '(Cannot access the database)'
329 MediaWikiServices::getInstance()->getMessageCache()->disable();
330 $html =
"<!DOCTYPE html>\n" .
335 '<style>body { font-family: sans-serif; margin: 0; padding: 0.5em 2em; }</style>' .
336 "</head><body><h1>$sorry</h1><p>$again</p><p><small>$info</small></p>";
339 $html .=
'<p>Backtrace:</p><pre>' .
340 htmlspecialchars( $e->getTraceAsString() ) .
'</pre>';
343 $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...
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 getText(Throwable $e)
static printError( $message)
Print a message, if possible to STDERR.
static reportOutageHTML(Throwable $e)
static statusHeader( $code)
static useOutputPage(Throwable $e)
static msg( $key, $fallback,... $params)
Get a message from i18n.
static getHTML(Throwable $e)
If $wgShowExceptionDetails is true, return a HTML message with a backtrace to the error,...
static output(Throwable $e, $mode, Throwable $eNew=null)
static getShowBacktraceError(Throwable $e)
static reportHTML(Throwable $e)
Output the throwable report using HTML.
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
while(( $__line=Maintenance::readconsole()) !==false) print