From 2e8e4478af5a66662b20d736149dc23273657c50 Mon Sep 17 00:00:00 2001 From: daniel Date: Wed, 30 Jan 2013 22:43:43 +0100 Subject: [PATCH] Add getters to HttpError, to use it in tests. Change-Id: I1165063ebdbcc29ae26998bd6ab74782dc0ecdc5 --- includes/Exception.php | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/includes/Exception.php b/includes/Exception.php index 700011934a..0499b3249f 100644 --- a/includes/Exception.php +++ b/includes/Exception.php @@ -567,14 +567,38 @@ class HttpError extends MWException { $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' ); + 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 ) { - $header = $httpMessage; + $header = HttpStatus::getMessage( $this->httpCode ); } elseif ( $this->header instanceof Message ) { $header = $this->header->escaped(); } else { @@ -587,7 +611,7 @@ class HttpError extends MWException { $content = htmlspecialchars( $this->content ); } - print "\n". + return "\n". "$header\n" . "

$header

$content

\n"; } -- 2.20.1