Reverted r113177 per CR
[lhc/web/wiklou.git] / includes / Exception.php
index 8c4e0a7..e7700b5 100644 (file)
@@ -181,6 +181,7 @@ class MWException extends Exception {
 
                        $wgOut->output();
                } else {
+                       header( "Content-Type: text/html; charset=utf-8" );
                        $hookResult = $this->runHooks( get_class( $this ) . "Raw" );
                        if ( $hookResult ) {
                                die( $hookResult );
@@ -202,7 +203,11 @@ class MWException extends Exception {
                        wfDebugLog( 'exception', $log );
                }
 
-               if ( self::isCommandLine() ) {
+               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() );
+               } elseif ( self::isCommandLine() ) {
                        MWExceptionHandler::printError( $this->getText() );
                } else {
                        $this->reportHTML();
@@ -265,11 +270,42 @@ class ErrorPageError extends MWException {
        function report() {
                global $wgOut;
 
+
                $wgOut->showErrorPage( $this->title, $this->msg, $this->params );
                $wgOut->output();
        }
 }
 
+/**
+ * Show an error page on a badtitle.
+ * Similar to ErrorPage, but emit a 400 HTTP error code to let mobile
+ * browser it is not really a valid content.
+ */
+class BadTitleError extends ErrorPageError {
+
+       /**
+        * @param $msg string A message key (default: 'badtitletext')
+        * @param $params Array parameter to wfMsg()
+        */
+       function __construct( $msg = 'badtitletext', $params = null ) {
+               parent::__construct( 'badtitle', $msg, $params );
+       }
+
+       /**
+        * Just like ErrorPageError::report() but additionally set
+        * a 400 HTTP status code (bug 33646).
+        */
+       function report() {
+               global $wgOut;
+
+               // bug 33646: a badtitle error page need to return an error code
+               // to let mobile browser now that it is not a normal page.
+               $wgOut->setStatusCode( 400 );
+               parent::report();
+       }
+
+}
+
 /**
  * Show an error when a user tries to do something they do not have the necessary
  * permissions for.