X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fexception%2FMWExceptionRenderer.php;h=bd4393445ba481b2d288e067c818cd088a1a071d;hb=ee56f00ddf0609082f8ae9a4dc3e6e1b6f54ddfd;hp=435fde3427bb210ec1d242fd622825a8b807ac18;hpb=efafb74daf6a3be5353cc06ce4b8574daa6c9aef;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/exception/MWExceptionRenderer.php b/includes/exception/MWExceptionRenderer.php index 435fde3427..dc8dfd0b3e 100644 --- a/includes/exception/MWExceptionRenderer.php +++ b/includes/exception/MWExceptionRenderer.php @@ -16,7 +16,6 @@ * http://www.gnu.org/copyleft/gpl.html * * @file - * @author Aaron Schulz */ use Wikimedia\Rdbms\DBConnectionError; @@ -34,7 +33,7 @@ class MWExceptionRenderer { /** * @param Exception|Throwable $e Original exception - * @param integer $mode MWExceptionExposer::AS_* constant + * @param int $mode MWExceptionExposer::AS_* constant * @param Exception|Throwable|null $eNew New exception from attempting to show the first */ public static function output( $e, $mode, $eNew = null ) { @@ -84,51 +83,6 @@ class MWExceptionRenderer { } } - /** - * Run hook to allow extensions to modify the text of the exception - * - * Called by MWException for b/c - * - * @param Exception|Throwable $e - * @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 static function runHooks( $e, $name, $args = [] ) { - global $wgExceptionHooks; - - if ( !isset( $wgExceptionHooks ) || !is_array( $wgExceptionHooks ) ) { - return null; // Just silently ignore - } - - if ( !array_key_exists( $name, $wgExceptionHooks ) || - !is_array( $wgExceptionHooks[$name] ) - ) { - return null; - } - - $hooks = $wgExceptionHooks[$name]; - $callargs = array_merge( [ $e ], $args ); - - foreach ( $hooks as $hook ) { - if ( - is_string( $hook ) || - ( is_array( $hook ) && count( $hook ) >= 2 && is_string( $hook[0] ) ) - ) { - // 'function' or [ 'class', 'hook' ] - $result = call_user_func_array( $hook, $callargs ); - } else { - $result = null; - } - - if ( is_string( $result ) ) { - return $result; - } - } - - return null; - } - /** * @param Exception|Throwable $e * @return bool Should the exception use $wgOut to output the error? @@ -136,14 +90,19 @@ class MWExceptionRenderer { private static function useOutputPage( $e ) { // Can the extension use the Message class/wfMessage to get i18n-ed messages? foreach ( $e->getTrace() as $frame ) { - if ( isset( $frame['class'] ) && $frame['class'] === 'LocalisationCache' ) { + 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' ) ); } @@ -167,16 +126,11 @@ class MWExceptionRenderer { $wgOut->prepareErrorPage( self::msg( 'internalerror', 'Internal error' ) ); } - $hookResult = self::runHooks( $e, get_class( $e ) ); - if ( $hookResult ) { - $wgOut->addHTML( $hookResult ); - } else { - // Show any custom GUI message before the details - if ( $e instanceof MessageSpecifier ) { - $wgOut->addHTML( Message::newFromSpecifier( $e )->escaped() ); - } - $wgOut->addHTML( self::getHTML( $e ) ); + // 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 { @@ -191,12 +145,7 @@ class MWExceptionRenderer { '' . "\n"; - $hookResult = self::runHooks( $e, get_class( $e ) . 'Raw' ); - if ( $hookResult ) { - echo $hookResult; - } else { - echo self::getHTML( $e ); - } + echo self::getHTML( $e ); echo "\n"; } @@ -220,14 +169,15 @@ class MWExceptionRenderer { } else { $logId = WebRequest::getRequestId(); $html = "
" . - '[' . $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" . + 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" . ""; } @@ -262,7 +212,7 @@ class MWExceptionRenderer { "\nBacktrace:\n" . MWExceptionHandler::getRedactedTraceAsString( $e ) . "\n"; } else { - return self::getShowBacktraceError( $e ); + return self::getShowBacktraceError( $e ) . "\n"; } } @@ -293,7 +243,7 @@ class MWExceptionRenderer { $vars[] = '$wgShowDBErrorBacktrace = true;'; } $vars = implode( ' and ', $vars ); - return "Set $vars at the bottom of LocalSettings.php to show detailed debugging information\n"; + return "Set $vars at the bottom of LocalSettings.php to show detailed debugging information."; } /** @@ -313,7 +263,7 @@ class MWExceptionRenderer { } /** - * @param integer $code + * @param int $code */ private static function statusHeader( $code ) { if ( !headers_sent() ) { @@ -356,7 +306,7 @@ class MWExceptionRenderer { if ( $wgShowHostnames || $wgShowSQLErrors ) { $info = str_replace( '$1', - Html::element( 'span', [ 'dir' => 'ltr' ], htmlspecialchars( $e->getMessage() ) ), + Html::element( 'span', [ 'dir' => 'ltr' ], $e->getMessage() ), htmlspecialchars( self::msg( 'dberr-info', '($1)' ) ) ); } else {