26use Wikimedia\RequestTimeout\RequestTimeoutException;
41 public static function output( Throwable $e, $mode, Throwable $eNew =
null ) {
44 if ( $e instanceof RequestTimeoutException && headers_sent() ) {
55 if ( function_exists(
'apache_setenv' ) ) {
59 AtEase\AtEase::suppressWarnings();
60 apache_setenv(
'no-gzip',
'1' );
61 AtEase\AtEase::restoreWarnings();
64 if ( defined(
'MW_API' ) ) {
65 self::header(
'MediaWiki-API-Error: internal_api_error_' . get_class( $e ) );
68 if ( self::isCommandLine() ) {
70 } elseif ( $mode === self::AS_PRETTY ) {
72 self::header(
"Content-Type: $wgMimeType; charset=UTF-8" );
84 self::header(
"Content-Type: $wgMimeType; charset=UTF-8" );
86 $message =
"MediaWiki internal error.\n\n";
88 $message .=
'Original exception: ' .
89 MWExceptionHandler::getLogMessage( $e ) .
90 "\nBacktrace:\n" . MWExceptionHandler::getRedactedTraceAsString( $e ) .
91 "\n\nException caught inside exception handler: " .
92 MWExceptionHandler::getLogMessage( $eNew ) .
93 "\nBacktrace:\n" . MWExceptionHandler::getRedactedTraceAsString( $eNew );
95 $message .=
'Original exception: ' .
96 MWExceptionHandler::getPublicLogMessage( $e );
97 $message .=
"\n\nException caught inside exception handler.\n\n" .
102 $message = MWExceptionHandler::getLogMessage( $e ) .
104 MWExceptionHandler::getRedactedTraceAsString( $e ) .
"\n";
106 $message = MWExceptionHandler::getPublicLogMessage( $e );
108 print nl2br( htmlspecialchars( $message ) ) .
"\n";
120 foreach ( $e->getTrace() as $frame ) {
121 if ( isset( $frame[
'class'] ) && $frame[
'class'] === LocalisationCache::class ) {
131 !empty( $GLOBALS[
'wgFullyInitialised'] ) &&
132 !empty( $GLOBALS[
'wgOut'] ) &&
133 RequestContext::getMain()->
getTitle() &&
134 !defined(
'MEDIAWIKI_INSTALL' ) &&
148 if ( self::useOutputPage( $e ) ) {
149 $wgOut->prepareErrorPage( self::getExceptionTitle( $e ) );
153 if ( $customMessage !==
null ) {
154 $wgOut->addHTML( Html::element(
'p', [], $customMessage ) );
156 $wgOut->addHTML( self::getHTML( $e ) );
160 self::header(
'Content-Type: text/html; charset=utf-8' );
161 $pageTitle =
self::msg(
'internalerror',
'Internal error' );
162 echo
"<!DOCTYPE html>\n" .
166 htmlspecialchars( self::msg(
'pagetitle',
"$1 - $wgSitename", $pageTitle ) ) .
168 '<style>body { font-family: sans-serif; margin: 0; padding: 0.5em 2em; }</style>' .
173 echo
"</body></html>\n";
185 public static function getHTML( Throwable $e ) {
189 $html =
"<div class=\"errorbox mw-content-ltr\"><p>" .
190 nl2br( htmlspecialchars( MWExceptionHandler::getLogMessage( $e ) ) ) .
191 '</p><p>Backtrace:</p><p>' .
192 nl2br( htmlspecialchars( MWExceptionHandler::getRedactedTraceAsString( $e ) ) ) .
195 $logId = WebRequest::getRequestId();
196 $html =
"<div class=\"errorbox mw-content-ltr\">" .
198 '[' . $logId .
'] ' .
199 gmdate(
'Y-m-d H:i:s' ) .
": " .
200 self::msg(
"internalerror-fatal-exception",
201 "Fatal exception of type $1",
204 MWExceptionHandler::getURL()
206 "<!-- " . wordwrap( self::getShowBacktraceError( $e ), 50 ) .
" -->";
227 }
catch ( Exception $e ) {
242 private static function getText( Throwable $e ) {
246 return MWExceptionHandler::getLogMessage( $e ) .
248 MWExceptionHandler::getRedactedTraceAsString( $e ) .
"\n";
259 $var =
'$wgShowExceptionDetails = true;';
260 return "Set $var at the bottom of LocalSettings.php to show detailed debugging information.";
271 return $e->getPageTitle();
273 return self::msg(
'readonly',
'Database is locked' );
275 return self::msg(
'databaseerror',
'Database error' );
276 } elseif ( $e instanceof RequestTimeoutException ) {
277 return self::msg(
'timeouterror',
'Request timeout' );
279 return self::msg(
'internalerror',
'Internal error' );
294 } elseif ( $e instanceof RequestTimeoutException ) {
295 $msg =
wfMessage(
'timeouterror-text', $e->getLimit() );
299 $text = $msg->text();
300 }
catch ( Exception $e2 ) {
310 return !empty( $GLOBALS[
'wgCommandLineMode'] );
317 if ( !headers_sent() ) {
326 if ( !headers_sent() ) {
327 HttpStatus::header( $code );
342 if ( defined(
'STDERR' ) ) {
343 fwrite( STDERR, $message );
355 $sorry = htmlspecialchars( self::msg(
357 'Sorry! This site is experiencing technical difficulties.'
359 $again = htmlspecialchars( self::msg(
361 'Try waiting a few minutes and reloading.'
367 Html::element(
'span', [
'dir' =>
'ltr' ], $e->getMessage() ),
368 htmlspecialchars( self::msg(
'dberr-info',
'($1)' ) )
371 $info = htmlspecialchars( self::msg(
373 '(Cannot access the database)'
377 MediaWikiServices::getInstance()->getMessageCache()->disable();
378 $html =
"<!DOCTYPE html>\n" .
383 '<style>body { font-family: sans-serif; margin: 0; padding: 0.5em 2em; }</style>' .
384 "</head><body><h1>$sorry</h1><p>$again</p><p><small>$info</small></p>";
387 $html .=
'<p>Backtrace:</p><pre>' .
388 htmlspecialchars( $e->getTraceAsString() ) .
'</pre>';
391 $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 getCustomMessage(Throwable $e)
Extract an additional user-visible message from an exception, or null if it has none.
static getExceptionTitle(Throwable $e)
Get the page title to be used for a given exception.
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