Merge "(bug 47070) check content model namespace on import."
[lhc/web/wiklou.git] / includes / db / DatabaseError.php
index f14a502..b4c7365 100644 (file)
  * @ingroup Database
  */
 class DBError extends MWException {
-
-       /**
-        * @var DatabaseBase
-        */
+       /** @var DatabaseBase */
        public $db;
 
        /**
         * Construct a database error
-        * @param $db DatabaseBase object which threw the error
+        * @param DatabaseBase $db Object which threw the error
         * @param string $error A simple error message to be used for debugging
         */
        function __construct( DatabaseBase $db = null, $error ) {
@@ -91,8 +88,13 @@ class DBError extends MWException {
  * @ingroup Database
  */
 class DBConnectionError extends DBError {
+       /** @var string Error text */
        public $error;
 
+       /**
+        * @param DatabaseBase $db Object throwing the error
+        * @param string $error Error text
+        */
        function __construct( DatabaseBase $db = null, $error = 'unknown error' ) {
                $msg = 'DB connection error';
 
@@ -115,9 +117,11 @@ class DBConnectionError extends DBError {
        }
 
        /**
-        * @param $key
-        * @param $fallback
-        * @return string
+        * @param string $key
+        * @param string $fallback Unescaped alternative error text in case the
+        *   message cache cannot be used. Can contain parameters as in regular
+        *   messages, that should be passed as additional parameters.
+        * @return string Unprocessed plain error text with parameters replaced
         */
        function msg( $key, $fallback /*[, params...] */ ) {
                global $wgLang;
@@ -129,6 +133,7 @@ class DBConnectionError extends DBError {
                } else {
                        $message = $fallback;
                }
+
                return wfMsgReplaceArgs( $message, $args );
        }
 
@@ -141,13 +146,19 @@ class DBConnectionError extends DBError {
        }
 
        /**
-        * @return string
+        * @return string Safe HTML
         */
        function getHTML() {
                global $wgShowDBErrorBacktrace, $wgShowHostnames, $wgShowSQLErrors;
 
-               $sorry = htmlspecialchars( $this->msg( 'dberr-problems', 'Sorry! This site is experiencing technical difficulties.' ) );
-               $again = htmlspecialchars( $this->msg( 'dberr-again', 'Try waiting a few minutes and reloading.' ) );
+               $sorry = htmlspecialchars( $this->msg(
+                       'dberr-problems',
+                       'Sorry! This site is experiencing technical difficulties.'
+               ) );
+               $again = htmlspecialchars( $this->msg(
+                       'dberr-again',
+                       'Try waiting a few minutes and reloading.'
+               ) );
 
                if ( $wgShowHostnames || $wgShowSQLErrors ) {
                        $info = str_replace(
@@ -155,7 +166,10 @@ class DBConnectionError extends DBError {
                                htmlspecialchars( $this->msg( 'dberr-info', '(Cannot contact the database server: $1)' ) )
                        );
                } else {
-                       $info = htmlspecialchars( $this->msg( 'dberr-info-hidden', '(Cannot contact the database server)' ) );
+                       $info = htmlspecialchars( $this->msg(
+                               'dberr-info-hidden',
+                               '(Cannot contact the database server)'
+                       ) );
                }
 
                # No database access
@@ -183,6 +197,11 @@ class DBConnectionError extends DBError {
                }
        }
 
+       /**
+        * Output the exception report using HTML.
+        *
+        * @return void
+        */
        public function reportHTML() {
                global $wgUseFileCache;
 
@@ -202,6 +221,7 @@ class DBConnectionError extends DBError {
 
                                        // Output cached page with notices on bottom and re-close body
                                        echo "{$cache}<hr />{$this->getHTML()}</body></html>";
+
                                        return;
                                }
                        } catch ( MWException $e ) {
@@ -219,8 +239,14 @@ class DBConnectionError extends DBError {
        function searchForm() {
                global $wgSitename, $wgCanonicalServer, $wgRequest;
 
-               $usegoogle = htmlspecialchars( $this->msg( 'dberr-usegoogle', 'You can try searching via Google in the meantime.' ) );
-               $outofdate = htmlspecialchars( $this->msg( 'dberr-outofdate', 'Note that their indexes of our content may be out of date.' ) );
+               $usegoogle = htmlspecialchars( $this->msg(
+                       'dberr-usegoogle',
+                       'You can try searching via Google in the meantime.'
+               ) );
+               $outofdate = htmlspecialchars( $this->msg(
+                       'dberr-outofdate',
+                       'Note that their indexes of our content may be out of date.'
+               ) );
                $googlesearch = htmlspecialchars( $this->msg( 'searchbutton', 'Search' ) );
 
                $search = htmlspecialchars( $wgRequest->getVal( 'search' ) );
@@ -246,6 +272,7 @@ class DBConnectionError extends DBError {
        </p>
 </form>
 EOT;
+
                return $trygoogle;
        }
 
@@ -253,21 +280,21 @@ EOT;
         * @return string
         */
        private function fileCachedPage() {
-               global $wgTitle, $wgOut, $wgRequest;
+               $context = RequestContext::getMain();
 
-               if ( $wgOut->isDisabled() ) {
+               if ( $context->getOutput()->isDisabled() ) {
                        // Done already?
                        return '';
                }
 
-               if ( $wgTitle ) {
-                       // use $wgTitle if we managed to set it
-                       $t = $wgTitle->getPrefixedDBkey();
+               if ( $context->getTitle() ) {
+                       // Use the main context's title if we managed to set it
+                       $t = $context->getTitle()->getPrefixedDBkey();
                } else {
                        // Fallback to the raw title URL param. We can't use the Title
                        // class is it may hit the interwiki table and give a DB error.
                        // We may get a cache miss due to not sanitizing the title though.
-                       $t = str_replace( ' ', '_', $wgRequest->getVal( 'title' ) );
+                       $t = str_replace( ' ', '_', $context->getRequest()->getVal( 'title' ) );
                        if ( $t == '' ) { // fallback to main page
                                $t = Title::newFromText(
                                        $this->msg( 'mainpage', 'Main Page' ) )->getPrefixedDBkey();
@@ -290,14 +317,16 @@ class DBQueryError extends DBError {
        public $error, $errno, $sql, $fname;
 
        /**
-        * @param $db DatabaseBase
-        * @param $error string
-        * @param $errno int|string
-        * @param $sql string
-        * @param $fname string
+        * @param DatabaseBase $db
+        * @param string $error
+        * @param int|string $errno
+        * @param string $sql
+        * @param string $fname
         */
        function __construct( DatabaseBase $db, $error, $errno, $sql, $fname ) {
-               $message = "A database error has occurred. Did you forget to run maintenance/update.php after upgrading?  See: https://www.mediawiki.org/wiki/Manual:Upgrading#Run_the_update_script\n" .
+               $message = "A database error has occurred. Did you forget to run " .
+                       "maintenance/update.php after upgrading?  See: " .
+                       "https://www.mediawiki.org/wiki/Manual:Upgrading#Run_the_update_script\n" .
                        "Query: $sql\n" .
                        "Function: $fname\n" .
                        "Error: $errno $error\n";
@@ -310,7 +339,7 @@ class DBQueryError extends DBError {
        }
 
        /**
-        * @return boolean
+        * @return bool
         */
        function isLoggable() {
                // Don't send to the exception log, already in dberror log
@@ -372,7 +401,7 @@ class DBQueryError extends DBError {
         * sites using this option probably don't care much about "security by obscurity". Of course,
         * if $wgShowSQLErrors is true, the SQL query *is* shown.
         *
-        * @return array: Keys are message keys; values are arrays of arguments for Html::element().
+        * @return array Keys are message keys; values are arrays of arguments for Html::element().
         *   Array will be empty if users are not allowed to see any of these details at all.
         */
        protected function getTechnicalDetails() {
@@ -397,7 +426,7 @@ class DBQueryError extends DBError {
 
        /**
         * @param string $key Message key
-        * @return string: English message text
+        * @return string English message text
         */
        private function getFallbackMessage( $key ) {
                $messages = array(
@@ -408,12 +437,13 @@ This may indicate a bug in the software.',
                        'databaseerror-function' => 'Function: $1',
                        'databaseerror-error' => 'Error: $1',
                );
+
                return $messages[$key];
        }
-
 }
 
 /**
  * @ingroup Database
  */
-class DBUnexpectedError extends DBError {}
+class DBUnexpectedError extends DBError {
+}