MediaWiki
REL1_24
|
00001 <?php 00028 class HttpError extends MWException { 00029 private $httpCode, $header, $content; 00030 00038 public function __construct( $httpCode, $content, $header = null ) { 00039 parent::__construct( $content ); 00040 $this->httpCode = (int)$httpCode; 00041 $this->header = $header; 00042 $this->content = $content; 00043 } 00044 00050 public function getStatusCode() { 00051 return $this->httpCode; 00052 } 00053 00059 public function report() { 00060 $httpMessage = HttpStatus::getMessage( $this->httpCode ); 00061 00062 header( "Status: {$this->httpCode} {$httpMessage}", true, $this->httpCode ); 00063 header( 'Content-type: text/html; charset=utf-8' ); 00064 00065 print $this->getHTML(); 00066 } 00067 00074 public function getHTML() { 00075 if ( $this->header === null ) { 00076 $header = HttpStatus::getMessage( $this->httpCode ); 00077 } elseif ( $this->header instanceof Message ) { 00078 $header = $this->header->escaped(); 00079 } else { 00080 $header = htmlspecialchars( $this->header ); 00081 } 00082 00083 if ( $this->content instanceof Message ) { 00084 $content = $this->content->escaped(); 00085 } else { 00086 $content = htmlspecialchars( $this->content ); 00087 } 00088 00089 return "<!DOCTYPE html>\n" . 00090 "<html><head><title>$header</title></head>\n" . 00091 "<body><h1>$header</h1><p>$content</p></body></html>\n"; 00092 } 00093 }