getTrace() as $frame ) { if ( isset( $frame['class'] ) && $frame['class'] === LocalisationCache::class ) { return false; } } // Don't even bother with OutputPage if there's no Title context set, // (e.g. we're in RL code on load.php) - the Skin system (and probably // most of MediaWiki) won't work. return ( !empty( $GLOBALS['wgFullyInitialised'] ) && !empty( $GLOBALS['wgOut'] ) && RequestContext::getMain()->getTitle() && !defined( 'MEDIAWIKI_INSTALL' ) ); } /** * Output the exception report using HTML * * @param Exception|Throwable $e */ private static function reportHTML( $e ) { global $wgOut, $wgSitename; if ( self::useOutputPage( $e ) ) { if ( $e instanceof MWException ) { $wgOut->prepareErrorPage( $e->getPageTitle() ); } elseif ( $e instanceof DBReadOnlyError ) { $wgOut->prepareErrorPage( self::msg( 'readonly', 'Database is locked' ) ); } elseif ( $e instanceof DBExpectedError ) { $wgOut->prepareErrorPage( self::msg( 'databaseerror', 'Database error' ) ); } else { $wgOut->prepareErrorPage( self::msg( 'internalerror', 'Internal error' ) ); } // Show any custom GUI message before the details if ( $e instanceof MessageSpecifier ) { $wgOut->addHTML( Html::element( 'p', [], Message::newFromSpecifier( $e )->text() ) ); } $wgOut->addHTML( self::getHTML( $e ) ); $wgOut->output(); } else { self::header( 'Content-Type: text/html; charset=utf-8' ); $pageTitle = self::msg( 'internalerror', 'Internal error' ); echo "\n" . '' . // Mimick OutputPage::setPageTitle behaviour '' . htmlspecialchars( self::msg( 'pagetitle', "$1 - $wgSitename", $pageTitle ) ) . '' . '' . "\n"; echo self::getHTML( $e ); echo "\n"; } } /** * If $wgShowExceptionDetails is true, return a HTML message with a * backtrace to the error, otherwise show a message to ask to set it to true * to show that information. * * @param Exception|Throwable $e * @return string Html to output */ public static function getHTML( $e ) { if ( self::showBackTrace( $e ) ) { $html = "

" . nl2br( htmlspecialchars( MWExceptionHandler::getLogMessage( $e ) ) ) . '

Backtrace:

' . nl2br( htmlspecialchars( MWExceptionHandler::getRedactedTraceAsString( $e ) ) ) . "

\n"; } else { $logId = WebRequest::getRequestId(); $html = "
" . htmlspecialchars( '[' . $logId . '] ' . gmdate( 'Y-m-d H:i:s' ) . ": " . self::msg( "internalerror-fatal-exception", "Fatal exception of type $1", get_class( $e ), $logId, MWExceptionHandler::getURL() ) ) . "
\n" . ""; } return $html; } /** * Get a message from i18n * * @param string $key Message name * @param string $fallback Default message if the message cache can't be * called by the exception * The function also has other parameters that are arguments for the message * @return string Message with arguments replaced */ private static function msg( $key, $fallback /*[, params...] */ ) { $args = array_slice( func_get_args(), 2 ); try { return wfMessage( $key, $args )->text(); } catch ( Exception $e ) { return wfMsgReplaceArgs( $fallback, $args ); } } /** * @param Exception|Throwable $e * @return string */ private static function getText( $e ) { if ( self::showBackTrace( $e ) ) { return MWExceptionHandler::getLogMessage( $e ) . "\nBacktrace:\n" . MWExceptionHandler::getRedactedTraceAsString( $e ) . "\n"; } else { return self::getShowBacktraceError( $e ) . "\n"; } } /** * @param Exception|Throwable $e * @return bool */ private static function showBackTrace( $e ) { global $wgShowExceptionDetails, $wgShowDBErrorBacktrace; return ( $wgShowExceptionDetails && ( !( $e instanceof DBError ) || $wgShowDBErrorBacktrace ) ); } /** * @param Exception|Throwable $e * @return string */ private static function getShowBacktraceError( $e ) { global $wgShowExceptionDetails, $wgShowDBErrorBacktrace; $vars = []; if ( !$wgShowExceptionDetails ) { $vars[] = '$wgShowExceptionDetails = true;'; } if ( $e instanceof DBError && !$wgShowDBErrorBacktrace ) { $vars[] = '$wgShowDBErrorBacktrace = true;'; } $vars = implode( ' and ', $vars ); return "Set $vars at the bottom of LocalSettings.php to show detailed debugging information."; } /** * @return bool */ private static function isCommandLine() { return !empty( $GLOBALS['wgCommandLineMode'] ); } /** * @param string $header */ private static function header( $header ) { if ( !headers_sent() ) { header( $header ); } } /** * @param int $code */ private static function statusHeader( $code ) { if ( !headers_sent() ) { HttpStatus::header( $code ); } } /** * Print a message, if possible to STDERR. * Use this in command line mode only (see isCommandLine) * * @param string $message Failure text */ private static function printError( $message ) { // NOTE: STDERR may not be available, especially if php-cgi is used from the // command line (bug #15602). Try to produce meaningful output anyway. Using // echo may corrupt output to STDOUT though. if ( defined( 'STDERR' ) ) { fwrite( STDERR, $message ); } else { echo $message; } } /** * @param Exception|Throwable $e */ private static function reportOutageHTML( $e ) { global $wgShowDBErrorBacktrace, $wgShowHostnames, $wgShowSQLErrors, $wgSitename; $sorry = htmlspecialchars( self::msg( 'dberr-problems', 'Sorry! This site is experiencing technical difficulties.' ) ); $again = htmlspecialchars( self::msg( 'dberr-again', 'Try waiting a few minutes and reloading.' ) ); if ( $wgShowHostnames || $wgShowSQLErrors ) { $info = str_replace( '$1', Html::element( 'span', [ 'dir' => 'ltr' ], $e->getMessage() ), htmlspecialchars( self::msg( 'dberr-info', '($1)' ) ) ); } else { $info = htmlspecialchars( self::msg( 'dberr-info-hidden', '(Cannot access the database)' ) ); } MessageCache::singleton()->disable(); // no DB access $html = "\n" . '' . '' . htmlspecialchars( $wgSitename ) . '' . '' . "

$sorry

$again

$info

"; if ( $wgShowDBErrorBacktrace ) { $html .= '

Backtrace:

' .
				htmlspecialchars( $e->getTraceAsString() ) . '
'; } $html .= ''; echo $html; } }