Add "chemical" major MIME type to the image tables
[lhc/web/wiklou.git] / includes / db / Database.php
index e13c053..a46ee1c 100644 (file)
@@ -710,19 +710,42 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
        }
 
        /**
-        * Return a path to the DBMS-specific schema file, otherwise default to tables.sql
+        * Return a path to the DBMS-specific SQL file if it exists,
+        * otherwise default SQL file
         *
+        * @param string $filename
         * @return string
         */
-       public function getSchemaPath() {
+       private function getSqlFilePath( $filename ) {
                global $IP;
-               if ( file_exists( "$IP/maintenance/" . $this->getType() . "/tables.sql" ) ) {
-                       return "$IP/maintenance/" . $this->getType() . "/tables.sql";
+               $dbmsSpecificFilePath = "$IP/maintenance/" . $this->getType() . "/$filename";
+               if ( file_exists( $dbmsSpecificFilePath ) ) {
+                       return $dbmsSpecificFilePath;
                } else {
-                       return "$IP/maintenance/tables.sql";
+                       return "$IP/maintenance/$filename";
                }
        }
 
+       /**
+        * Return a path to the DBMS-specific schema file,
+        * otherwise default to tables.sql
+        *
+        * @return string
+        */
+       public function getSchemaPath() {
+               return $this->getSqlFilePath( 'tables.sql' );
+       }
+
+       /**
+        * Return a path to the DBMS-specific update key file,
+        * otherwise default to update-keys.sql
+        *
+        * @return string
+        */
+       public function getUpdateKeysPath() {
+               return $this->getSqlFilePath( 'update-keys.sql' );
+       }
+
 # ------------------------------------------------------------------------------
 # Other functions
 # ------------------------------------------------------------------------------
@@ -1130,7 +1153,9 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
                        $this->mTrxIdleCallbacks = array(); // bug 65263
                        $this->mTrxPreCommitCallbacks = array(); // bug 65263
                        wfDebug( "Connection lost, reconnecting...\n" );
-
+                       # Stash the last error values since ping() might clear them
+                       $lastError = $this->lastError();
+                       $lastErrno = $this->lastErrno();
                        if ( $this->ping() ) {
                                global $wgRequestTime;
                                wfDebug( "Reconnected\n" );
@@ -1145,6 +1170,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
                                if ( $hadTrx ) {
                                        # Leave $ret as false and let an error be reported.
                                        # Callers may catch the exception and continue to use the DB.
+                                       $this->reportQueryError( $lastError, $lastErrno, $sql, $fname, $tempIgnore );
                                } else {
                                        # Should be safe to silently retry (no trx and thus no callbacks)
                                        $ret = $this->doQuery( $commentedSql );
@@ -1490,6 +1516,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
         * @param array $options Query options
         * @param array $join_conds Join conditions
         *
+        *
         * @param string|array $table
         *
         * May be either an array of table names, or a single string holding a table
@@ -1900,7 +1927,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
         *   DatabaseBase::tableName().
         * @param array $a Array of rows to insert
         * @param string $fname Calling function name (use __METHOD__) for logs/profiling
-        * @param array $options of options
+        * @param array $options Array of options
         *
         * @return bool
         */
@@ -2095,11 +2122,11 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
         * Build a partial where clause from a 2-d array such as used for LinkBatch.
         * The keys on each level may be either integers or strings.
         *
-        * @param array $data organized as 2-d
+        * @param array $data Organized as 2-d
         *    array(baseKeyVal => array(subKeyVal => [ignored], ...), ...)
         * @param string $baseKey Field name to match the base-level keys to (eg 'pl_namespace')
         * @param string $subKey Field name to match the sub-level keys to (eg 'pl_title')
-        * @return string|bool string SQL fragment, or false if no items in array.
+        * @return string|bool SQL fragment, or false if no items in array
         */
        public function makeWhereFrom2d( $data, $baseKey, $subKey ) {
                $conds = array();
@@ -2385,7 +2412,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
        /**
         * Gets an array of aliased table names
         *
-        * @param array $tables array( [alias] => table )
+        * @param array $tables Array( [alias] => table )
         * @return string[] See tableNameWithAlias()
         */
        public function tableNamesWithAlias( $tables ) {
@@ -2419,7 +2446,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
        /**
         * Gets an array of aliased field names
         *
-        * @param array $fields array( [alias] => field )
+        * @param array $fields Array( [alias] => field )
         * @return string[] See fieldNameWithAlias()
         */
        public function fieldNamesWithAlias( $fields ) {
@@ -2920,9 +2947,9 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
         * DELETE query wrapper.
         *
         * @param array $table Table name
-        * @param string|array $conds of conditions. See $conds in DatabaseBase::select()
+        * @param string|array $conds Array of conditions. See $conds in DatabaseBase::select()
         *   for the format. Use $conds == "*" to delete all rows
-        * @param string $fname name of the calling function
+        * @param string $fname Name of the calling function
         * @throws DBUnexpectedError
         * @return bool|ResultWrapper
         */
@@ -3211,7 +3238,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
         * @param DBMasterPos $pos
         * @param int $timeout The maximum number of seconds to wait for
         *   synchronisation
-        * @return int Zzero if the slave was past that position already,
+        * @return int Zero if the slave was past that position already,
         *   greater than zero if we waited for some period of time, less than
         *   zero if we timed out.
         */
@@ -3288,7 +3315,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
        protected function runOnTransactionIdleCallbacks() {
                $autoTrx = $this->getFlag( DBO_TRX ); // automatic begin() enabled?
 
-               $e = null; // last exception
+               $e = $ePrior = null; // last exception
                do { // callbacks may add callbacks :)
                        $callbacks = $this->mTrxIdleCallbacks;
                        $this->mTrxIdleCallbacks = array(); // recursion guard
@@ -3299,6 +3326,10 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
                                        call_user_func( $phpCallback );
                                        $this->setFlag( $autoTrx ? DBO_TRX : 0 ); // restore automatic begin()
                                } catch ( Exception $e ) {
+                                       if ( $ePrior ) {
+                                               MWExceptionHandler::logException( $ePrior );
+                                       }
+                                       $ePrior = $e;
                                }
                        }
                } while ( count( $this->mTrxIdleCallbacks ) );
@@ -3314,7 +3345,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
         * @since 1.22
         */
        protected function runOnTransactionPreCommitCallbacks() {
-               $e = null; // last exception
+               $e = $ePrior = null; // last exception
                do { // callbacks may add callbacks :)
                        $callbacks = $this->mTrxPreCommitCallbacks;
                        $this->mTrxPreCommitCallbacks = array(); // recursion guard
@@ -3323,6 +3354,10 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
                                        list( $phpCallback ) = $callback;
                                        call_user_func( $phpCallback );
                                } catch ( Exception $e ) {
+                                       if ( $ePrior ) {
+                                               MWExceptionHandler::logException( $ePrior );
+                                       }
+                                       $ePrior = $e;
                                }
                        }
                } while ( count( $this->mTrxPreCommitCallbacks ) );
@@ -4152,7 +4187,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
        /**
         * Encode an expiry time into the DBMS dependent format
         *
-        * @param string $expiry timestamp for expiry, or the 'infinity' string
+        * @param string $expiry Timestamp for expiry, or the 'infinity' string
         * @return string
         */
        public function encodeExpiry( $expiry ) {
@@ -4189,6 +4224,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
 
        /**
         * @since 1.19
+        * @return string
         */
        public function __toString() {
                return (string)$this->mConn;