Localisation updates for core and extension messages from translatewiki.net (2010...
[lhc/web/wiklou.git] / includes / installer / MysqlInstaller.php
index 5db3af3..d4af144 100644 (file)
@@ -1,6 +1,19 @@
 <?php
-
-class MysqlInstaller extends InstallerDBType {
+/**
+ * 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(
                'wgDBserver',
                'wgDBname',
@@ -16,11 +29,11 @@ class MysqlInstaller extends InstallerDBType {
                '_MysqlCharset' => 'binary',
        );
 
-       var $supportedEngines = array( 'InnoDB', 'MyISAM' );
+       public $supportedEngines = array( 'InnoDB', 'MyISAM' );
 
-       var $minimumVersion = '4.0.14';
+       public $minimumVersion = '4.0.14';
 
-       var $webUserPrivs = array(
+       public $webUserPrivs = array(
                'DELETE',
                'INSERT',
                'SELECT',
@@ -28,11 +41,11 @@ class MysqlInstaller extends InstallerDBType {
                'CREATE TEMPORARY TABLES',
        );
 
-       function getName() {
+       public function getName() {
                return 'mysql';
        }
 
-       function __construct( $parent ) {
+       public function __construct( $parent ) {
                parent::__construct( $parent );
        }
 
@@ -40,11 +53,11 @@ class MysqlInstaller extends InstallerDBType {
                return self::checkExtension( 'mysql' );
        }
 
-       function getGlobalDefaults() {
+       public function getGlobalDefaults() {
                return array();
        }
 
-       function getConnectForm() {
+       public function getConnectForm() {
                return
                        $this->getTextBox( 'wgDBserver', 'config-db-host' ) .
                        $this->parent->getHelpBox( 'config-db-host-help' ) . 
@@ -58,11 +71,11 @@ class MysqlInstaller extends InstallerDBType {
                        $this->getInstallUserBox();
        }
 
-       function submitConnectForm() {
-               // Get variables from the request
+       public function submitConnectForm() {
+               // 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' );
@@ -98,7 +111,7 @@ class MysqlInstaller extends InstallerDBType {
                return $status;
        }
 
-       function getConnection() {
+       public function getConnection() {
                $status = Status::newGood();
                try {
                        $this->db = new DatabaseMysql(
@@ -111,25 +124,27 @@ class MysqlInstaller extends InstallerDBType {
                                $this->getVar( 'wgDBprefix' )
                        );
                        $status->value = $this->db;
-                       return $status;
                } catch ( DBConnectionError $e ) {
                        $status->fatal( 'config-connection-error', $e->getMessage() );
                }
                return $status;
        }
 
-       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' );
@@ -152,15 +167,30 @@ class MysqlInstaller extends InstallerDBType {
                                        $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' );
        }
 
        /**
         * Get a list of storage engines that are available and supported
         */
-       function getEngines() {
+       public function getEngines() {
                $engines = array( 'InnoDB', 'MyISAM' );
                $status = $this->getConnection();
                if ( !$status->isOK() ) {
@@ -175,7 +205,7 @@ class MysqlInstaller extends InstallerDBType {
                }
 
                $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;
@@ -188,7 +218,7 @@ class MysqlInstaller extends InstallerDBType {
        /**
         * Get a list of character sets that are available and supported
         */
-       function getCharsets() {
+       public function getCharsets() {
                $status = $this->getConnection();
                $mysql5 = array( 'binary', 'utf8' );
                $mysql4 = array( 'mysql4' );
@@ -204,7 +234,7 @@ class MysqlInstaller extends InstallerDBType {
        /**
         * Return true if the install user can create accounts
         */
-       function canCreateAccounts() {
+       public function canCreateAccounts() {
                $status = $this->getConnection();
                if ( !$status->isOK() ) {
                        return false;
@@ -276,7 +306,7 @@ class MysqlInstaller extends InstallerDBType {
                return true;
        }
 
-       function getSettingsForm() {
+       public function getSettingsForm() {
                if ( $this->canCreateAccounts() ) {
                        $noCreateMsg = false;
                } else {
@@ -320,7 +350,7 @@ class MysqlInstaller extends InstallerDBType {
                return $s;
        }
 
-       function submitSettingsForm() {
+       public function submitSettingsForm() {
                $newValues = $this->setVarsFromRequest( array( '_MysqlEngine', '_MysqlCharset' ) );
                $status = $this->submitWebUserBox();
                if ( !$status->isOK() ) {
@@ -377,7 +407,7 @@ class MysqlInstaller extends InstallerDBType {
                $this->parent->addInstallStepFollowing( "tables", $callback );
        }
 
-       function setupDatabase() {
+       public function setupDatabase() {
                $status = $this->getConnection();
                if ( !$status->isOK() ) {
                        return $status;
@@ -385,13 +415,13 @@ class MysqlInstaller extends InstallerDBType {
                $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;
        }
 
-       function setupUser() {
+       public function setupUser() {
                global $IP;
 
                if ( !$this->getVar( '_CreateDBAccount' ) ) {
@@ -413,32 +443,12 @@ class MysqlInstaller extends InstallerDBType {
                return $status;
        }
 
-       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;
-       }
-
-       function getTableOptions() {
+       public function getTableOptions() {
                return array( 'engine' => $this->getVar( '_MysqlEngine' ),
                        'default charset' => $this->getVar( '_MysqlCharset' ) );
        }
 
-       function getLocalSettings() {
+       public function getLocalSettings() {
                $dbmysql5 = wfBoolToStr( $this->getVar( 'wgDBmysql5', true ) );
                $prefix = $this->getVar( 'wgDBprefix' );
                $opts = $this->getTableOptions();