Merge "resources: Register jquery.client as foreign resource and update to v2.0.1"
[lhc/web/wiklou.git] / includes / installer / MysqlInstaller.php
index d4dcdc2..1b0780b 100644 (file)
@@ -413,20 +413,6 @@ class MysqlInstaller extends DatabaseInstaller {
                        $this->setVar( '_MysqlCharset', reset( $charsets ) );
                }
 
-               // Do charset selector
-               if ( count( $charsets ) >= 2 ) {
-                       // getRadioSet() builds a set of labeled radio buttons.
-                       // For grep: The following messages are used as the item labels:
-                       // config-mysql-binary, config-mysql-utf8
-                       $s .= $this->getRadioSet( [
-                               'var' => '_MysqlCharset',
-                               'label' => 'config-mysql-charset',
-                               'itemLabelPrefix' => 'config-mysql-',
-                               'values' => $charsets
-                       ] );
-                       $s .= $this->parent->getHelpBox( 'config-mysql-charset-help' );
-               }
-
                return $s;
        }
 
@@ -499,18 +485,32 @@ class MysqlInstaller extends DatabaseInstaller {
                /** @var Database $conn */
                $conn = $status->value;
                $dbName = $this->getVar( 'wgDBname' );
-               if ( !$conn->selectDB( $dbName ) ) {
+               if ( !$this->databaseExists( $dbName ) ) {
                        $conn->query(
                                "CREATE DATABASE " . $conn->addIdentifierQuotes( $dbName ) . "CHARACTER SET utf8",
                                __METHOD__
                        );
-                       $conn->selectDB( $dbName );
                }
+               $conn->selectDB( $dbName );
                $this->setupSchemaVars();
 
                return $status;
        }
 
+       /**
+        * Try to see if a given database exists
+        * @param string $dbName Database name to check
+        * @return bool
+        */
+       private function databaseExists( $dbName ) {
+               $encDatabase = $this->db->addQuotes( $dbName );
+
+               return $this->db->query(
+                       "SELECT 1 FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = $encDatabase",
+                       __METHOD__
+               )->numRows() > 0;
+       }
+
        /**
         * @return Status
         */