Go to the documentation of this file.
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: ' .
79 "\n\nException caught inside exception handler: " .
83 $message .=
'Original exception: ' .
85 $message .=
"\n\nException caught inside exception handler.\n\n" .
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'] ) &&
120 !empty( $GLOBALS[
'wgOut'] ) &&
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>" .
186 '</p><p>Backtrace:</p><p>' .
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",
201 "<!-- " . wordwrap( self::getShowBacktraceError( $e ), 50 ) .
" -->";
222 }
catch ( Exception $e ) {
237 private static function getText( Throwable $e ) {
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() ) {
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>';
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
$wgMimeType
The default Content-Type header.
static getHTML(Throwable $e)
If $wgShowExceptionDetails is true, return a HTML message with a backtrace to the error,...
static getText(Throwable $e)
static msg( $key, $fallback,... $params)
Get a message from i18n.
static getPublicLogMessage(Throwable $e)
static reportOutageHTML(Throwable $e)
$wgShowHostnames
Expose backend server host names through the API and various HTML comments.
static reportHTML(Throwable $e)
Output the throwable report using HTML.
wfMsgReplaceArgs( $message, $args)
Replace message parameter keys on the given formatted output.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
static getRedactedTraceAsString(Throwable $e)
Generate a string representation of a throwable's stack trace.
static getURL()
If the exception occurred in the course of responding to a request, returns the requested URL.
static output(Throwable $e, $mode, Throwable $eNew=null)
static useOutputPage(Throwable $e)
$wgSitename
Name of the site.
static getShowBacktraceError(Throwable $e)
static printError( $message)
Print a message, if possible to STDERR.
static getMain()
Get the RequestContext object associated with the main request.
static header( $code)
Output an HTTP status code header.
static getRequestId()
Get the unique request ID.
$wgShowExceptionDetails
If set to true, uncaught exceptions will print the exception message and a complete stack trace to ou...
static statusHeader( $code)
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Class to expose exceptions to the client (API bots, users, admins using CLI scripts)
static getLogMessage(Throwable $e)
Get a message formatting the throwable message and its origin.