+class UserBlockedError extends ErrorPageError {
+ public function __construct( Block $block ){
+ global $wgLang;
+
+ $blockerUserpage = $block->getBlocker()->getUserPage();
+ $link = "[[{$blockerUserpage->getPrefixedText()}|{$blockerUserpage->getText()}]]";
+
+ $reason = $block->mReason;
+ if( $reason == '' ) {
+ $reason = wfMsg( 'blockednoreason' );
+ }
+
+ /* $ip returns who *is* being blocked, $intended contains who was meant to be blocked.
+ * This could be a username, an IP range, or a single IP. */
+ $intended = $block->getTarget();
+
+ parent::__construct(
+ 'blockedtitle',
+ $block->mAuto ? 'autoblocketext' : 'blockedtext',
+ array(
+ $link,
+ $reason,
+ wfGetIP(),
+ $block->getBlocker()->getName(),
+ $block->getId(),
+ $wgLang->formatExpiry( $block->mExpiry ),
+ $intended,
+ $wgLang->timeanddate( wfTimestamp( TS_MW, $block->mTimestamp ), true )
+ )
+ );
+ }
+}
+
+/**
+ * Handler class for MWExceptions
+ * @ingroup Exception
+ */
+class MWExceptionHandler {
+ /**
+ * Install an exception handler for MediaWiki exception types.
+ */
+ public static function installHandler() {
+ set_exception_handler( array( 'MWExceptionHandler', 'handle' ) );
+ }
+
+ /**
+ * Report an exception to the user
+ */
+ protected static function report( Exception $e ) {
+ global $wgShowExceptionDetails;
+
+ $cmdLine = MWException::isCommandLine();
+
+ if ( $e instanceof MWException ) {
+ try {
+ // Try and show the exception prettily, with the normal skin infrastructure
+ $e->report();
+ } catch ( Exception $e2 ) {
+ // Exception occurred from within exception handler
+ // Show a simpler error message for the original exception,
+ // don't try to invoke report()
+ $message = "MediaWiki internal error.\n\n";
+
+ if ( $wgShowExceptionDetails ) {
+ $message .= 'Original exception: ' . $e->__toString() . "\n\n" .
+ 'Exception caught inside exception handler: ' . $e2->__toString();
+ } else {
+ $message .= "Exception caught inside exception handler.\n\n" .
+ "Set \$wgShowExceptionDetails = true; at the bottom of LocalSettings.php " .
+ "to show detailed debugging information.";
+ }
+
+ $message .= "\n";
+
+ if ( $cmdLine ) {
+ self::printError( $message );
+ } else {
+ self::escapeEchoAndDie( $message );
+ }
+ }
+ } else {
+ $message = "Unexpected non-MediaWiki exception encountered, of type \"" . get_class( $e ) . "\"\n" .
+ $e->__toString() . "\n";
+
+ if ( $wgShowExceptionDetails ) {
+ $message .= "\n" . $e->getTraceAsString() . "\n";
+ }
+
+ if ( $cmdLine ) {
+ self::printError( $message );
+ } else {
+ self::escapeEchoAndDie( $message );
+ }
+ }