From c1f9b1f7b1b77776192048005dcc66dcf3df2bfb Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 27 Dec 2014 15:41:37 +0100 Subject: Update to MediaWiki 1.24.1 --- includes/exception/HttpError.php | 93 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 includes/exception/HttpError.php (limited to 'includes/exception/HttpError.php') diff --git a/includes/exception/HttpError.php b/includes/exception/HttpError.php new file mode 100644 index 00000000..6ab6e039 --- /dev/null +++ b/includes/exception/HttpError.php @@ -0,0 +1,93 @@ + and \) + */ + public function __construct( $httpCode, $content, $header = null ) { + parent::__construct( $content ); + $this->httpCode = (int)$httpCode; + $this->header = $header; + $this->content = $content; + } + + /** + * Returns the HTTP status code supplied to the constructor. + * + * @return int + */ + public function getStatusCode() { + return $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 = HttpStatus::getMessage( $this->httpCode ); + } 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 ); + } + + return "\n" . + "$header\n" . + "

$header

$content

\n"; + } +} -- cgit v1.2.3-54-g00ecf