$line = $this->getLine();
$message = $this->getMessage();
- if ( isset( $wgRequest ) ) {
+ if ( isset( $wgRequest ) && !$wgRequest instanceof FauxRequest ) {
$url = $wgRequest->getRequestURL();
if ( !$url ) {
$url = '[no URL]';
die( $hookResult );
}
- $html = $this->getHTML();
- if ( defined( 'MEDIAWIKI_INSTALL' ) ) {
- echo $html;
- } else {
- wfDie( $html );
- }
+ echo $this->getHTML();
+ die(1);
}
}
}
static function isCommandLine() {
- return !empty( $GLOBALS['wgCommandLineMode'] ) && !defined( 'MEDIAWIKI_INSTALL' );
+ return !empty( $GLOBALS['wgCommandLineMode'] );
}
}
function report() {
global $wgOut;
- if ( $wgOut->getTitle() ) {
- $wgOut->debug( 'Original title: ' . $wgOut->getTitle()->getPrefixedText() . "\n" );
- }
- $wgOut->setPageTitle( wfMsg( $this->title ) );
- $wgOut->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
- $wgOut->setRobotPolicy( 'noindex,nofollow' );
- $wgOut->setArticleRelated( false );
- $wgOut->enableClientCache( false );
- $wgOut->mRedirect = '';
- $wgOut->clearHTML();
-
- if( $this->msg instanceof Message ){
- $wgOut->addHTML( $this->msg->parse() );
- } else {
- $wgOut->addWikiMsgArray( $this->msg, $this->params );
- }
-
- $wgOut->returnToMain();
+ $wgOut->showErrorPage( $this->title, $this->msg, $this->params );
$wgOut->output();
}
}
*/
class UserBlockedError extends ErrorPageError {
public function __construct( Block $block ){
- global $wgLang;
+ global $wgLang, $wgRequest;
$blockerUserpage = $block->getBlocker()->getUserPage();
$link = "[[{$blockerUserpage->getPrefixedText()}|{$blockerUserpage->getText()}]]";
parent::__construct(
'blockedtitle',
- $block->mAuto ? 'autoblocketext' : 'blockedtext',
+ $block->mAuto ? 'autoblockedtext' : 'blockedtext',
array(
$link,
$reason,
- wfGetIP(),
+ $wgRequest->getIP(),
$block->getBlocker()->getName(),
$block->getId(),
$wgLang->formatExpiry( $block->mExpiry ),
}
}
+/**
+ * Show an error that looks like an HTTP server error.
+ * Replacement for wfHttpError().
+ *
+ * @ingroup Exception
+ */
+class HttpError extends MWException {
+ private $httpCode, $header, $content;
+
+ /**
+ * Constructor
+ *
+ * @param $httpCode Integer: HTTP status code to send to the client
+ * @param $content String|Message: content of the message
+ * @param $header String|Message: content of the header (\<title\> and \<h1\>)
+ */
+ public function __construct( $httpCode, $content, $header = null ){
+ parent::__construct( $content );
+ $this->httpCode = (int)$httpCode;
+ $this->header = $header;
+ $this->content = $content;
+ }
+
+ public function reportHTML() {
+ $httpMessage = HttpStatus::getMessage( $this->httpCode );
+
+ header( "Status: {$this->httpCode} {$httpMessage}" );
+ header( 'Content-type: text/html; charset=utf-8' );
+
+ if ( $this->header === null ) {
+ $header = $httpMessage;
+ } elseif ( $this->header instanceof Message ) {
+ $header = $this->header->escaped();
+ } else {
+ $header = htmlspecialchars( $this->header );
+ }
+
+ if ( $this->content instanceof Message ) {
+ $content = $this->content->escaped();
+ } else {
+ $content = htmlspecialchars( $this->content );
+ }
+
+ print "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n".
+ "<html><head><title>$header</title></head>\n" .
+ "<body><h1>$header</h1><p>$content</p></body></html>\n";
+ }
+}
+
/**
* Handler class for MWExceptions
* @ingroup Exception
if ( $cmdLine ) {
self::printError( $message );
} else {
- wfDie( nl2br( htmlspecialchars( $message ) ) ) . "\n";
+ self::escapeEchoAndDie( $message );
}
}
} else {
if ( $cmdLine ) {
self::printError( $message );
} else {
- wfDie( nl2br( htmlspecialchars( $message ) ) ) . "\n";
+ self::escapeEchoAndDie( $message );
}
}
}
/**
* Print a message, if possible to STDERR.
* Use this in command line mode only (see isCommandLine)
+ * @param $message String Failure text
*/
public static function printError( $message ) {
# NOTE: STDERR may not be available, especially if php-cgi is used from the command line (bug #15602).
}
}
+ /**
+ * Print a message after escaping it and converting newlines to <br>
+ * Use this for non-command line failures
+ * @param $message String Failure text
+ */
+ private static function escapeEchoAndDie( $message ) {
+ echo nl2br( htmlspecialchars( $message ) ) . "\n";
+ die(1);
+ }
+
/**
* Exception handler which simulates the appropriate catch() handling:
*