fix some spacing
[lhc/web/wiklou.git] / includes / Exception.php
index f09e8f8..2764ea9 100644 (file)
@@ -83,7 +83,7 @@ class MWException extends Exception {
                $callargs = array_merge( array( $this ), $args );
 
                foreach ( $hooks as $hook ) {
-                       if ( is_string( $hook ) || ( is_array( $hook ) && count( $hook ) >= 2 && is_string( $hook[0] ) ) ) {    // 'function' or array( 'class', hook' )
+                       if ( is_string( $hook ) || ( is_array( $hook ) && count( $hook ) >= 2 && is_string( $hook[0] ) ) ) { // 'function' or array( 'class', hook' )
                                $result = call_user_func_array( $hook, $callargs );
                        } else {
                                $result = null;
@@ -262,7 +262,7 @@ class MWException extends Exception {
                if ( defined( 'MW_API' ) ) {
                        // Unhandled API exception, we can't be sure that format printer is alive
                        header( 'MediaWiki-API-Error: internal_api_error_' . get_class( $this ) );
-                       wfHttpError(500, 'Internal Server Error', $this->getText() );
+                       wfHttpError( 500, 'Internal Server Error', $this->getText() );
                } elseif ( self::isCommandLine() ) {
                        MWExceptionHandler::printError( $this->getText() );
                } else {
@@ -329,7 +329,7 @@ class ErrorPageError extends MWException {
                $this->msg = $msg;
                $this->params = $params;
 
-               if( $msg instanceof Message ){
+               if( $msg instanceof Message ) {
                        parent::__construct( $msg );
                } else {
                        parent::__construct( wfMessage( $msg )->text() );
@@ -423,7 +423,7 @@ class PermissionsError extends ErrorPageError {
  * @ingroup Exception
  */
 class ReadOnlyError extends ErrorPageError {
-       public function __construct(){
+       public function __construct() {
                parent::__construct(
                        'readonly',
                        'readonlytext',
@@ -439,14 +439,14 @@ class ReadOnlyError extends ErrorPageError {
  * @ingroup Exception
  */
 class ThrottledError extends ErrorPageError {
-       public function __construct(){
+       public function __construct() {
                parent::__construct(
                        'actionthrottled',
                        'actionthrottledtext'
                );
        }
 
-       public function report(){
+       public function report() {
                global $wgOut;
                $wgOut->setStatusCode( 503 );
                parent::report();
@@ -460,7 +460,7 @@ class ThrottledError extends ErrorPageError {
  * @ingroup Exception
  */
 class UserBlockedError extends ErrorPageError {
-       public function __construct( Block $block ){
+       public function __construct( Block $block ) {
                global $wgLang, $wgRequest;
 
                $blocker = $block->getBlocker();
@@ -536,7 +536,7 @@ class UserNotLoggedIn extends ErrorPageError {
         */
        public function __construct(
                $reasonMsg = 'exception-nologin-text',
-               $titleMsg  = 'exception-nologin',
+               $titleMsg = 'exception-nologin',
                $params = null
        ) {
                parent::__construct( $titleMsg, $reasonMsg, $params );
@@ -560,21 +560,45 @@ class HttpError extends MWException {
         * @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 ){
+       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}" );
+               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 "<!DOCTYPE html>\n".
+               return "<!DOCTYPE html>\n".
                        "<html><head><title>$header</title></head>\n" .
                        "<body><h1>$header</h1><p>$content</p></body></html>\n";
        }