Localisation updates for core and extension messages from translatewiki.net (2010...
[lhc/web/wiklou.git] / includes / installer / MysqlInstaller.php
index 4e50fe0..d4af144 100644 (file)
@@ -1,5 +1,17 @@
 <?php
-
+/**
+ * MySQL-specific installer.
+ *
+ * @file
+ * @ingroup Deployment
+ */
+
+/**
+ * Class for setting up the MediaWiki database using MySQL.
+ * 
+ * @ingroup Deployment
+ * @since 1.17
+ */
 class MysqlInstaller extends DatabaseInstaller {
        
        protected $globalNames = array(
@@ -60,10 +72,10 @@ class MysqlInstaller extends DatabaseInstaller {
        }
 
        public function submitConnectForm() {
-               // Get variables from the request
+               // Get variables from the request.
                $newValues = $this->setVarsFromRequest( array( 'wgDBserver', 'wgDBname', 'wgDBprefix' ) );
 
-               // Validate them
+               // Validate them.
                $status = Status::newGood();
                if ( !strlen( $newValues['wgDBname'] ) ) {
                        $status->fatal( 'config-missing-db-name' );
@@ -112,25 +124,27 @@ class MysqlInstaller extends DatabaseInstaller {
                                $this->getVar( 'wgDBprefix' )
                        );
                        $status->value = $this->db;
-                       return $status;
                } catch ( DBConnectionError $e ) {
                        $status->fatal( 'config-connection-error', $e->getMessage() );
                }
                return $status;
        }
 
-       public function doUpgrade() {
+       public function preUpgrade() {
+               global $wgDBuser, $wgDBpassword;
+
                $status = $this->getConnection();
                if ( !$status->isOK() ) {
                        $this->parent->showStatusError( $status );
                        return;
                }
                $conn = $status->value;
+               $conn->selectDB( $this->getVar( 'wgDBname' ) );
 
                # Determine existing default character set
                if ( $conn->tableExists( "revision" ) ) {
                        $revision = $conn->escapeLike( $this->getVar( 'wgDBprefix' ) . 'revision' );
-                       $res = $conn->query( "SHOW TABLE STATUS LIKE '$revision'" );
+                       $res = $conn->query( "SHOW TABLE STATUS LIKE '$revision'", __METHOD__ );
                        $row = $conn->fetchObject( $res );
                        if ( !$row ) {
                                $this->parent->showMessage( 'config-show-table-status' );
@@ -153,9 +167,24 @@ class MysqlInstaller extends DatabaseInstaller {
                                        $existingEngine = $row->Type;
                                }
                        }
+               } else {
+                       $existingSchema = false;
+                       $existingEngine = false;
                }
-               
-               // TODO
+
+               if ( $existingSchema && $existingSchema != $this->getVar( '_MysqlCharset' ) ) {
+                       $this->parent->showMessage( 'config-mysql-charset-mismatch', $this->getVar( '_MysqlCharset' ), $existingSchema );
+                       $this->setVar( '_MysqlCharset', $existingSchema );
+               }
+               if ( $existingEngine && $existingEngine != $this->getVar( '_MysqlEngine' ) ) {
+                       $this->parent->showMessage( 'config-mysql-egine-mismatch', $this->getVar( '_MysqlEngine' ), $existingEngine );
+                       $this->setVar( '_MysqlEngine', $existingEngine );
+               }
+
+               # Normal user and password are selected after this step, so for now
+               # just copy these two
+               $wgDBuser = $this->getVar( '_InstallUser' );
+               $wgDBpassword = $this->getVar( '_InstallPassword' );
        }
 
        /**
@@ -176,7 +205,7 @@ class MysqlInstaller extends DatabaseInstaller {
                }
 
                $engines = array();
-               $res = $conn->query( 'SHOW ENGINES' );
+               $res = $conn->query( 'SHOW ENGINES', __METHOD__ );
                foreach ( $res as $row ) {
                        if ( $row->Support == 'YES' || $row->Support == 'DEFAULT' ) {
                                $engines[] = $row->Engine;
@@ -386,7 +415,7 @@ class MysqlInstaller extends DatabaseInstaller {
                $conn = $status->value;
                $dbName = $this->getVar( 'wgDBname' );
                if( !$conn->selectDB( $dbName ) ) {
-                       $conn->query( "CREATE DATABASE `$dbName`" );
+                       $conn->query( "CREATE DATABASE `$dbName`", __METHOD__ );
                        $conn->selectDB( $dbName );
                }
                return $status;
@@ -414,26 +443,6 @@ class MysqlInstaller extends DatabaseInstaller {
                return $status;
        }
 
-       public function createTables() {
-               global $IP;
-               $status = $this->getConnection();
-               if ( !$status->isOK() ) {
-                       return $status;
-               }
-               $this->db->selectDB( $this->getVar( 'wgDBname' ) );
-               
-               if( $this->db->tableExists( 'user' ) ) {
-                       $status->warning( 'config-install-tables-exist' );
-                       return $status;
-               } 
-               
-               $error = $this->db->sourceFile( "$IP/maintenance/tables.sql" );
-               if( $error !== true ) {
-                       $status->fatal( 'config-install-tables-failed', $error );
-               }
-               return $status;
-       }
-
        public function getTableOptions() {
                return array( 'engine' => $this->getVar( '_MysqlEngine' ),
                        'default charset' => $this->getVar( '_MysqlCharset' ) );