Add support for Number grouping(commafy) based on CLDR number grouping patterns like...
[lhc/web/wiklou.git] / includes / Exception.php
index 5a972ca..432b768 100644 (file)
@@ -150,7 +150,7 @@ class MWException extends Exception {
                $line = $this->getLine();
                $message = $this->getMessage();
 
-               if ( isset( $wgRequest ) ) {
+               if ( isset( $wgRequest ) && !$wgRequest instanceof FauxRequest ) {
                        $url = $wgRequest->getRequestURL();
                        if ( !$url ) {
                                $url = '[no URL]';
@@ -255,24 +255,7 @@ class ErrorPageError extends MWException {
        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();
        }
 }
@@ -352,7 +335,7 @@ class ThrottledError extends ErrorPageError {
  */
 class UserBlockedError extends ErrorPageError {
        public function __construct( Block $block ){
-               global $wgLang;
+               global $wgLang, $wgRequest;
 
                $blockerUserpage = $block->getBlocker()->getUserPage();
                $link = "[[{$blockerUserpage->getPrefixedText()}|{$blockerUserpage->getText()}]]";
@@ -372,7 +355,7 @@ class UserBlockedError extends ErrorPageError {
                        array(
                                $link,
                                $reason,
-                               wfGetIP(),
+                               $wgRequest->getIP(),
                                $block->getBlocker()->getName(),
                                $block->getId(),
                                $wgLang->formatExpiry( $block->mExpiry ),
@@ -383,6 +366,55 @@ class UserBlockedError extends ErrorPageError {
        }
 }
 
+/**
+ * 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