X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fexception%2FMWException.php;h=8c1f8dc9683e4ce6f5ca96ff3e5d8693aaab4876;hp=5496cb63d00d964197aa6011ed7df240b8b57b34;hb=ee56f00ddf0609082f8ae9a4dc3e6e1b6f54ddfd;hpb=1827c891f549e3163d9e87390c6c6e939e8cf36b diff --git a/includes/exception/MWException.php b/includes/exception/MWException.php index 5496cb63d0..16f226c78f 100644 --- a/includes/exception/MWException.php +++ b/includes/exception/MWException.php @@ -55,7 +55,7 @@ class MWException extends Exception { global $wgLang; foreach ( $this->getTrace() as $frame ) { - if ( isset( $frame['class'] ) && $frame['class'] === 'LocalisationCache' ) { + if ( isset( $frame['class'] ) && $frame['class'] === LocalisationCache::class ) { return false; } } @@ -63,17 +63,6 @@ class MWException extends Exception { return $wgLang instanceof Language; } - /** - * Run hook to allow extensions to modify the text of the exception - * - * @param string $name Class name of the exception - * @param array $args Arguments to pass to the callback functions - * @return string|null String to output or null if any hook has been called - */ - public function runHooks( $name, $args = [] ) { - return MWExceptionRenderer::runHooks( $this, $name, $args ); - } - /** * Get a message from i18n * @@ -112,16 +101,18 @@ class MWException extends Exception { "

\n"; } else { $logId = WebRequest::getRequestId(); - $type = get_class( $this ); - return "
" . - '[' . $logId . '] ' . - gmdate( 'Y-m-d H:i:s' ) . ": " . - $this->msg( "internalerror-fatal-exception", - "Fatal exception of type $1", - $type, - $logId, - MWExceptionHandler::getURL( $this ) - ) . "
\n" . + $type = static::class; + return Html::errorBox( + htmlspecialchars( + '[' . $logId . '] ' . + gmdate( 'Y-m-d H:i:s' ) . ": " . + $this->msg( "internalerror-fatal-exception", + "Fatal exception of type $1", + $type, + $logId, + MWExceptionHandler::getURL( $this ) + ) + ) ) . ""; @@ -164,12 +155,7 @@ class MWException extends Exception { if ( $this->useOutputPage() ) { $wgOut->prepareErrorPage( $this->getPageTitle() ); - $hookResult = $this->runHooks( get_class( $this ) ); - if ( $hookResult ) { - $wgOut->addHTML( $hookResult ); - } else { - $wgOut->addHTML( $this->getHTML() ); - } + $wgOut->addHTML( $this->getHTML() ); $wgOut->output(); } else { @@ -183,12 +169,7 @@ class MWException extends Exception { '' . "\n"; - $hookResult = $this->runHooks( get_class( $this ) . 'Raw' ); - if ( $hookResult ) { - echo $hookResult; - } else { - echo $this->getHTML(); - } + echo $this->getHTML(); echo "\n"; } @@ -199,7 +180,26 @@ class MWException extends Exception { * It will be either HTML or plain text based on isCommandLine(). */ public function report() { - MWExceptionRenderer::output( $this, MWExceptionRenderer::AS_PRETTY ); + global $wgMimeType; + + if ( defined( 'MW_API' ) ) { + // Unhandled API exception, we can't be sure that format printer is alive + self::header( 'MediaWiki-API-Error: internal_api_error_' . static::class ); + wfHttpError( 500, 'Internal Server Error', $this->getText() ); + } elseif ( self::isCommandLine() ) { + $message = $this->getText(); + // T17602: STDERR may not be available + if ( defined( 'STDERR' ) ) { + fwrite( STDERR, $message ); + } else { + echo $message; + } + } else { + self::statusHeader( 500 ); + self::header( "Content-Type: $wgMimeType; charset=utf-8" ); + + $this->reportHTML(); + } } /**