39 public static function output(
$e, $mode, $eNew =
null ) {
42 if ( defined(
'MW_API' ) ) {
44 self::header(
'MediaWiki-API-Error: internal_api_error_' . get_class(
$e ) );
45 wfHttpError( 500,
'Internal Server Error', self::getText(
$e ) );
46 } elseif ( self::isCommandLine() ) {
48 } elseif ( $mode === self::AS_PRETTY ) {
50 self::header(
"Content-Type: $wgMimeType; charset=utf-8" );
58 self::header(
"Content-Type: $wgMimeType; charset=utf-8" );
60 $message =
"MediaWiki internal error.\n\n";
61 if ( self::showBackTrace(
$e ) ) {
62 $message .=
'Original exception: ' .
63 MWExceptionHandler::getLogMessage(
$e ) .
64 "\nBacktrace:\n" . MWExceptionHandler::getRedactedTraceAsString(
$e ) .
65 "\n\nException caught inside exception handler: " .
66 MWExceptionHandler::getLogMessage( $eNew ) .
67 "\nBacktrace:\n" . MWExceptionHandler::getRedactedTraceAsString( $eNew );
69 $message .=
'Original exception: ' .
70 MWExceptionHandler::getPublicLogMessage(
$e );
71 $message .=
"\n\nException caught inside exception handler.\n\n" .
76 if ( self::showBackTrace(
$e ) ) {
77 $message = MWExceptionHandler::getLogMessage(
$e ) .
79 MWExceptionHandler::getRedactedTraceAsString(
$e ) .
"\n";
81 $message = MWExceptionHandler::getPublicLogMessage(
$e );
84 echo nl2br( htmlspecialchars( $message ) ) .
"\n";
94 foreach (
$e->getTrace() as $frame ) {
95 if ( isset( $frame[
'class'] ) && $frame[
'class'] === LocalisationCache::class ) {
105 !empty(
$GLOBALS[
'wgFullyInitialised'] ) &&
108 !defined(
'MEDIAWIKI_INSTALL' )
120 if ( self::useOutputPage(
$e ) ) {
122 $wgOut->prepareErrorPage(
$e->getPageTitle() );
124 $wgOut->prepareErrorPage( self::msg(
'readonly',
'Database is locked' ) );
126 $wgOut->prepareErrorPage( self::msg(
'databaseerror',
'Database error' ) );
128 $wgOut->prepareErrorPage( self::msg(
'internalerror',
'Internal error' ) );
133 $wgOut->addHTML( Html::element(
'p', [], Message::newFromSpecifier(
$e )->
text() ) );
135 $wgOut->addHTML( self::getHTML(
$e ) );
139 self::header(
'Content-Type: text/html; charset=utf-8' );
140 $pageTitle =
self::msg(
'internalerror',
'Internal error' );
141 echo
"<!DOCTYPE html>\n" .
145 htmlspecialchars( self::msg(
'pagetitle',
"$1 - $wgSitename", $pageTitle ) ) .
147 '<style>body { font-family: sans-serif; margin: 0; padding: 0.5em 2em; }</style>' .
152 echo
"</body></html>\n";
165 if ( self::showBackTrace(
$e ) ) {
166 $html =
"<div class=\"errorbox mw-content-ltr\"><p>" .
167 nl2br( htmlspecialchars( MWExceptionHandler::getLogMessage(
$e ) ) ) .
168 '</p><p>Backtrace:</p><p>' .
169 nl2br( htmlspecialchars( MWExceptionHandler::getRedactedTraceAsString(
$e ) ) ) .
172 $logId = WebRequest::getRequestId();
173 $html =
"<div class=\"errorbox mw-content-ltr\">" .
175 '[' . $logId .
'] ' .
176 gmdate(
'Y-m-d H:i:s' ) .
": " .
177 self::msg(
"internalerror-fatal-exception",
178 "Fatal exception of type $1",
181 MWExceptionHandler::getURL()
183 "<!-- " . wordwrap( self::getShowBacktraceError(
$e ), 50 ) .
" -->";
199 $args = array_slice( func_get_args(), 2 );
202 }
catch ( Exception
$e ) {
212 if ( self::showBackTrace(
$e ) ) {
213 return MWExceptionHandler::getLogMessage(
$e ) .
215 MWExceptionHandler::getRedactedTraceAsString(
$e ) .
"\n";
242 $vars[] =
'$wgShowExceptionDetails = true;';
245 $vars[] =
'$wgShowDBErrorBacktrace = true;';
248 return "Set $vars at the bottom of LocalSettings.php to show detailed debugging information.";
255 return !empty(
$GLOBALS[
'wgCommandLineMode'] );
262 if ( !headers_sent() ) {
271 if ( !headers_sent() ) {
286 if ( defined(
'STDERR' ) ) {
287 fwrite( STDERR, $message );
299 $sorry = htmlspecialchars( self::msg(
301 'Sorry! This site is experiencing technical difficulties.'
303 $again = htmlspecialchars( self::msg(
305 'Try waiting a few minutes and reloading.'
311 Html::element(
'span', [
'dir' =>
'ltr' ],
$e->getMessage() ),
312 htmlspecialchars( self::msg(
'dberr-info',
'($1)' ) )
315 $info = htmlspecialchars( self::msg(
317 '(Cannot access the database)'
322 $html =
"<!DOCTYPE html>\n" .
327 '<style>body { font-family: sans-serif; margin: 0; padding: 0.5em 2em; }</style>' .
328 "</head><body><h1>$sorry</h1><p>$again</p><p><small>$info</small></p>";
331 $html .=
'<p>Backtrace:</p><pre>' .
332 htmlspecialchars(
$e->getTraceAsString() ) .
'</pre>';
335 $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 a complete stack trace to output.
$wgShowDBErrorBacktrace
If true, show a backtrace for database errors.
$wgShowSQLErrors
Whether to show "we're sorry, but there has been a database error" pages.
wfHttpError( $code, $label, $desc)
Provide a simple HTTP error.
wfMsgReplaceArgs( $message, $args)
Replace message parameter keys on the given formatted output.
static header( $code)
Output an HTTP status code header.
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 msg( $key, $fallback)
Get a message from i18n.
static reportHTML( $e)
Output the exception report using HTML.
static statusHeader( $code)
static reportOutageHTML( $e)
static showBackTrace( $e)
static getHTML( $e)
If $wgShowExceptionDetails is true, return a HTML message with a backtrace to the error,...
static getShowBacktraceError( $e)
static singleton()
Get the signleton instance of this class.
static getMain()
Get the RequestContext object associated with the main request.
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable & $code
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "<div ...>$1</div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
returning false will NOT prevent logging $e