Merge "Removed 'Disable browser page caching" user preference"
[lhc/web/wiklou.git] / includes / installer / MysqlInstaller.php
index c0b5243..2d43324 100644 (file)
@@ -64,15 +64,11 @@ class MysqlInstaller extends DatabaseInstaller {
                return 'mysql';
        }
 
-       public function __construct( $parent ) {
-               parent::__construct( $parent );
-       }
-
        /**
         * @return Bool
         */
        public function isCompiled() {
-               return self::checkExtension( 'mysql' );
+               return self::checkExtension( 'mysql' ) || self::checkExtension( 'mysqli' );
        }
 
        /**
@@ -86,7 +82,12 @@ class MysqlInstaller extends DatabaseInstaller {
         * @return string
         */
        public function getConnectForm() {
-               return $this->getTextBox( 'wgDBserver', 'config-db-host', array(), $this->parent->getHelpBox( 'config-db-host-help' ) ) .
+               return $this->getTextBox(
+                       'wgDBserver',
+                       'config-db-host',
+                       array(),
+                       $this->parent->getHelpBox( 'config-db-host-help' )
+               ) .
                        Html::openElement( 'fieldset' ) .
                        Html::element( 'legend', array(), wfMessage( 'config-db-wiki-settings' )->text() ) .
                        $this->getTextBox( 'wgDBname', 'config-db-name', array( 'dir' => 'ltr' ),
@@ -149,18 +150,18 @@ class MysqlInstaller extends DatabaseInstaller {
        public function openConnection() {
                $status = Status::newGood();
                try {
-                       $db = new DatabaseMysql(
-                               $this->getVar( 'wgDBserver' ),
-                               $this->getVar( '_InstallUser' ),
-                               $this->getVar( '_InstallPassword' ),
-                               false,
-                               0,
-                               $this->getVar( 'wgDBprefix' )
-                       );
+                       $db = DatabaseBase::factory( 'mysql', array(
+                               'host' => $this->getVar( 'wgDBserver' ),
+                               'user' => $this->getVar( '_InstallUser' ),
+                               'password' => $this->getVar( '_InstallPassword' ),
+                               'dbname' => false,
+                               'flags' => 0,
+                               'tablePrefix' => $this->getVar( 'wgDBprefix' ) ) );
                        $status->value = $db;
                } catch ( DBConnectionError $e ) {
                        $status->fatal( 'config-connection-error', $e->getMessage() );
                }
+
                return $status;
        }
 
@@ -170,6 +171,7 @@ class MysqlInstaller extends DatabaseInstaller {
                $status = $this->getConnection();
                if ( !$status->isOK() ) {
                        $this->parent->showStatusError( $status );
+
                        return;
                }
                /**
@@ -243,6 +245,7 @@ class MysqlInstaller extends DatabaseInstaller {
                        }
                }
                $engines = array_intersect( $this->supportedEngines, $engines );
+
                return $engines;
        }
 
@@ -265,9 +268,7 @@ class MysqlInstaller extends DatabaseInstaller {
                if ( !$status->isOK() ) {
                        return false;
                }
-               /**
-                * @var $conn DatabaseBase
-                */
+               /** @var $conn DatabaseBase */
                $conn = $status->value;
 
                // Get current account name
@@ -327,6 +328,7 @@ class MysqlInstaller extends DatabaseInstaller {
                        // Can't grant everything
                        return false;
                }
+
                return true;
        }
 
@@ -350,7 +352,7 @@ class MysqlInstaller extends DatabaseInstaller {
 
                $s .= Xml::openElement( 'div', array(
                        'id' => 'dbMyisamWarning'
-               ));
+               ) );
                $myisamWarning = 'config-mysql-myisam-dep';
                if ( count( $engines ) === 1 ) {
                        $myisamWarning = 'config-mysql-only-myisam-dep';
@@ -382,7 +384,8 @@ class MysqlInstaller extends DatabaseInstaller {
                                                'class' => 'hideShowRadio',
                                                'rel' => 'dbMyisamWarning'
                                        )
-                       )));
+                               )
+                       ) );
                        $s .= $this->parent->getHelpBox( 'config-mysql-engine-help' );
                }
 
@@ -402,7 +405,7 @@ class MysqlInstaller extends DatabaseInstaller {
                                'label' => 'config-mysql-charset',
                                'itemLabelPrefix' => 'config-mysql-',
                                'values' => $charsets
-                       ));
+                       ) );
                        $s .= $this->parent->getHelpBox( 'config-mysql-charset-help' );
                }
 
@@ -431,14 +434,14 @@ class MysqlInstaller extends DatabaseInstaller {
                if ( !$create ) {
                        // Test the web account
                        try {
-                               new DatabaseMysql(
-                                       $this->getVar( 'wgDBserver' ),
-                                       $this->getVar( 'wgDBuser' ),
-                                       $this->getVar( 'wgDBpassword' ),
-                                       false,
-                                       0,
-                                       $this->getVar( 'wgDBprefix' )
-                               );
+                               DatabaseBase::factory( 'mysql', array(
+                                       'host' => $this->getVar( 'wgDBserver' ),
+                                       'user' => $this->getVar( 'wgDBuser' ),
+                                       'password' => $this->getVar( 'wgDBpassword' ),
+                                       'dbname' => false,
+                                       'flags' => 0,
+                                       'tablePrefix' => $this->getVar( 'wgDBprefix' )
+                               ) );
                        } catch ( DBConnectionError $e ) {
                                return Status::newFatal( 'config-connection-error', $e->getMessage() );
                        }
@@ -454,6 +457,7 @@ class MysqlInstaller extends DatabaseInstaller {
                if ( !in_array( $this->getVar( '_MysqlCharset' ), $charsets ) ) {
                        $this->setVar( '_MysqlCharset', reset( $charsets ) );
                }
+
                return Status::newGood();
        }
 
@@ -474,13 +478,18 @@ class MysqlInstaller extends DatabaseInstaller {
                if ( !$status->isOK() ) {
                        return $status;
                }
+               /** @var DatabaseBase $conn */
                $conn = $status->value;
                $dbName = $this->getVar( 'wgDBname' );
                if ( !$conn->selectDB( $dbName ) ) {
-                       $conn->query( "CREATE DATABASE " . $conn->addIdentifierQuotes( $dbName ) . "CHARACTER SET utf8", __METHOD__ );
+                       $conn->query(
+                               "CREATE DATABASE " . $conn->addIdentifierQuotes( $dbName ) . "CHARACTER SET utf8",
+                               __METHOD__
+                       );
                        $conn->selectDB( $dbName );
                }
                $this->setupSchemaVars();
+
                return $status;
        }
 
@@ -507,14 +516,14 @@ class MysqlInstaller extends DatabaseInstaller {
                if ( $this->getVar( '_CreateDBAccount' ) ) {
                        // Before we blindly try to create a user that already has access,
                        try { // first attempt to connect to the database
-                               new DatabaseMysql(
-                                       $server,
-                                       $dbUser,
-                                       $password,
-                                       false,
-                                       0,
-                                       $this->getVar( 'wgDBprefix' )
-                               );
+                               DatabaseBase::factory( 'mysql', array(
+                                       'host' => $server,
+                                       'user' => $dbUser,
+                                       'password' => $password,
+                                       'dbname' => false,
+                                       'flags' => 0,
+                                       'tablePrefix' => $this->getVar( 'wgDBprefix' )
+                               ) );
                                $grantableNames[] = $this->buildFullUserName( $dbUser, $server );
                                $tryToCreate = false;
                        } catch ( DBConnectionError $e ) {
@@ -603,11 +612,11 @@ class MysqlInstaller extends DatabaseInstaller {
                try {
                        $res = $this->db->selectRow( 'mysql.user', array( 'Host', 'User' ),
                                array( 'Host' => $host, 'User' => $user ), __METHOD__ );
+
                        return (bool)$res;
                } catch ( DBQueryError $dqe ) {
                        return false;
                }
-
        }
 
        /**
@@ -624,6 +633,7 @@ class MysqlInstaller extends DatabaseInstaller {
                if ( $this->getVar( '_MysqlCharset' ) !== null ) {
                        $options[] = 'DEFAULT CHARSET=' . $this->getVar( '_MysqlCharset' );
                }
+
                return implode( ', ', $options );
        }
 
@@ -645,8 +655,8 @@ class MysqlInstaller extends DatabaseInstaller {
                $dbmysql5 = wfBoolToStr( $this->getVar( 'wgDBmysql5', true ) );
                $prefix = LocalSettingsGenerator::escapePhpString( $this->getVar( 'wgDBprefix' ) );
                $tblOpts = LocalSettingsGenerator::escapePhpString( $this->getTableOptions() );
-               return
-"# MySQL specific settings
+
+               return "# MySQL specific settings
 \$wgDBprefix = \"{$prefix}\";
 
 # MySQL table options to use during installation or update