* @author Aaron Schulz
*/
+use Wikimedia\Rdbms\DBConnectionError;
+use Wikimedia\Rdbms\DBError;
+use Wikimedia\Rdbms\DBReadOnlyError;
+use Wikimedia\Rdbms\DBExpectedError;
+
/**
* Class to expose exceptions to the client (API bots, users, admins using CLI scripts)
* @since 1.28
} elseif ( self::isCommandLine() ) {
self::printError( self::getText( $e ) );
} elseif ( $mode === self::AS_PRETTY ) {
+ self::statusHeader( 500 );
if ( $e instanceof DBConnectionError ) {
self::reportOutageHTML( $e );
} else {
- self::statusHeader( 500 );
self::header( "Content-Type: $wgMimeType; charset=utf-8" );
self::reportHTML( $e );
}
}
}
- /**
- * 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?
$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( Message::newFromSpecifier( $e )->escaped() );
}
+ $wgOut->addHTML( self::getHTML( $e ) );
$wgOut->output();
} else {
'<style>body { font-family: sans-serif; margin: 0; padding: 0.5em 2em; }</style>' .
"</head><body>\n";
- $hookResult = self::runHooks( $e, get_class( $e ) . 'Raw' );
- if ( $hookResult ) {
- echo $hookResult;
- } else {
- echo self::getHTML( $e );
- }
+ echo self::getHTML( $e );
echo "</body></html>\n";
}
$vars[] = '$wgShowDBErrorBacktrace = true;';
}
$vars = implode( ' and ', $vars );
- return "Set $vars at the bottom of LocalSettings.php to show detailed debugging information";
+ return "Set $vars at the bottom of LocalSettings.php to show detailed debugging information\n";
}
/**