Add getters to HttpError, to use it in tests.
authordaniel <daniel.kinzler@wikimedia.de>
Wed, 30 Jan 2013 21:43:43 +0000 (22:43 +0100)
committerdaniel <daniel.kinzler@wikimedia.de>
Wed, 30 Jan 2013 21:45:32 +0000 (22:45 +0100)
Change-Id: I1165063ebdbcc29ae26998bd6ab74782dc0ecdc5

includes/Exception.php

index 7000119..0499b32 100644 (file)
@@ -567,14 +567,38 @@ class HttpError extends MWException {
                $this->content = $content;
        }
 
                $this->content = $content;
        }
 
+       /**
+        * Returns the HTTP status code supplied to the constructor.
+        *
+        * @return int
+        */
+       public function getStatusCode() {
+               $this->httpCode;
+       }
+
+       /**
+        * Report the HTTP error.
+        * Sends the appropriate HTTP status code and outputs an
+        * HTML page with an error message.
+        */
        public function report() {
                $httpMessage = HttpStatus::getMessage( $this->httpCode );
 
                header( "Status: {$this->httpCode} {$httpMessage}", true, $this->httpCode );
                header( 'Content-type: text/html; charset=utf-8' );
 
        public function report() {
                $httpMessage = HttpStatus::getMessage( $this->httpCode );
 
                header( "Status: {$this->httpCode} {$httpMessage}", true, $this->httpCode );
                header( 'Content-type: text/html; charset=utf-8' );
 
+               print $this->getHTML();
+       }
+
+       /**
+        * Returns HTML for reporting the HTTP error.
+        * This will be a minimal but complete HTML document.
+        *
+        * @return string HTML
+        */
+       public function getHTML() {
                if ( $this->header === null ) {
                if ( $this->header === null ) {
-                       $header = $httpMessage;
+                       $header = HttpStatus::getMessage( $this->httpCode );
                } elseif ( $this->header instanceof Message ) {
                        $header = $this->header->escaped();
                } else {
                } elseif ( $this->header instanceof Message ) {
                        $header = $this->header->escaped();
                } else {
@@ -587,7 +611,7 @@ class HttpError extends MWException {
                        $content = htmlspecialchars( $this->content );
                }
 
                        $content = htmlspecialchars( $this->content );
                }
 
-               print "<!DOCTYPE html>\n".
+               return "<!DOCTYPE html>\n".
                        "<html><head><title>$header</title></head>\n" .
                        "<body><h1>$header</h1><p>$content</p></body></html>\n";
        }
                        "<html><head><title>$header</title></head>\n" .
                        "<body><h1>$header</h1><p>$content</p></body></html>\n";
        }