summaryrefslogtreecommitdiff
path: root/includes/installer/MysqlInstaller.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/installer/MysqlInstaller.php')
-rw-r--r--includes/installer/MysqlInstaller.php135
1 files changed, 77 insertions, 58 deletions
diff --git a/includes/installer/MysqlInstaller.php b/includes/installer/MysqlInstaller.php
index f9a8ce75..5f76972c 100644
--- a/includes/installer/MysqlInstaller.php
+++ b/includes/installer/MysqlInstaller.php
@@ -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,12 +82,18 @@ 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' ), $this->parent->getHelpBox( 'config-db-name-help' ) ) .
- $this->getTextBox( 'wgDBprefix', 'config-db-prefix', array( 'dir' => 'ltr' ), $this->parent->getHelpBox( 'config-db-prefix-help' ) ) .
+ $this->getTextBox( 'wgDBname', 'config-db-name', array( 'dir' => 'ltr' ),
+ $this->parent->getHelpBox( 'config-db-name-help' ) ) .
+ $this->getTextBox( 'wgDBprefix', 'config-db-prefix', array( 'dir' => 'ltr' ),
+ $this->parent->getHelpBox( 'config-db-prefix-help' ) ) .
Html::closeElement( 'fieldset' ) .
$this->getInstallUserBox();
}
@@ -148,19 +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,
- 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;
}
@@ -327,6 +330,7 @@ class MysqlInstaller extends DatabaseInstaller {
// Can't grant everything
return false;
}
+
return true;
}
@@ -350,17 +354,24 @@ class MysqlInstaller extends DatabaseInstaller {
$s .= Xml::openElement( 'div', array(
'id' => 'dbMyisamWarning'
- ));
- $s .= $this->parent->getWarningBox( wfMessage( 'config-mysql-myisam-dep' )->text() );
+ ) );
+ $myisamWarning = 'config-mysql-myisam-dep';
+ if ( count( $engines ) === 1 ) {
+ $myisamWarning = 'config-mysql-only-myisam-dep';
+ }
+ $s .= $this->parent->getWarningBox( wfMessage( $myisamWarning )->text() );
$s .= Xml::closeElement( 'div' );
- if( $this->getVar( '_MysqlEngine' ) != 'MyISAM' ) {
+ if ( $this->getVar( '_MysqlEngine' ) != 'MyISAM' ) {
$s .= Xml::openElement( 'script', array( 'type' => 'text/javascript' ) );
$s .= '$(\'#dbMyisamWarning\').hide();';
$s .= Xml::closeElement( 'script' );
}
if ( count( $engines ) >= 2 ) {
+ // getRadioSet() builds a set of labeled radio buttons.
+ // For grep: The following messages are used as the item labels:
+ // config-mysql-innodb, config-mysql-myisam
$s .= $this->getRadioSet( array(
'var' => '_MysqlEngine',
'label' => 'config-mysql-engine',
@@ -369,11 +380,14 @@ class MysqlInstaller extends DatabaseInstaller {
'itemAttribs' => array(
'MyISAM' => array(
'class' => 'showHideRadio',
- 'rel' => 'dbMyisamWarning'),
+ 'rel' => 'dbMyisamWarning'
+ ),
'InnoDB' => array(
'class' => 'hideShowRadio',
- 'rel' => 'dbMyisamWarning')
- )));
+ 'rel' => 'dbMyisamWarning'
+ )
+ )
+ ) );
$s .= $this->parent->getHelpBox( 'config-mysql-engine-help' );
}
@@ -385,12 +399,15 @@ class MysqlInstaller extends DatabaseInstaller {
// 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( array(
'var' => '_MysqlCharset',
'label' => 'config-mysql-charset',
'itemLabelPrefix' => 'config-mysql-',
'values' => $charsets
- ));
+ ) );
$s .= $this->parent->getHelpBox( 'config-mysql-charset-help' );
}
@@ -419,15 +436,13 @@ class MysqlInstaller extends DatabaseInstaller {
if ( !$create ) {
// Test the web account
try {
- new DatabaseMysql(
- $this->getVar( 'wgDBserver' ),
- $this->getVar( 'wgDBuser' ),
- $this->getVar( 'wgDBpassword' ),
- false,
- false,
- 0,
- $this->getVar( 'wgDBprefix' )
- );
+ $db = 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() );
}
@@ -443,6 +458,7 @@ class MysqlInstaller extends DatabaseInstaller {
if ( !in_array( $this->getVar( '_MysqlCharset' ), $charsets ) ) {
$this->setVar( '_MysqlCharset', reset( $charsets ) );
}
+
return Status::newGood();
}
@@ -465,11 +481,15 @@ class MysqlInstaller extends DatabaseInstaller {
}
$conn = $status->value;
$dbName = $this->getVar( 'wgDBname' );
- if( !$conn->selectDB( $dbName ) ) {
- $conn->query( "CREATE DATABASE " . $conn->addIdentifierQuotes( $dbName ), __METHOD__ );
+ if ( !$conn->selectDB( $dbName ) ) {
+ $conn->query(
+ "CREATE DATABASE " . $conn->addIdentifierQuotes( $dbName ) . "CHARACTER SET utf8",
+ __METHOD__
+ );
$conn->selectDB( $dbName );
}
$this->setupSchemaVars();
+
return $status;
}
@@ -478,7 +498,7 @@ class MysqlInstaller extends DatabaseInstaller {
*/
public function setupUser() {
$dbUser = $this->getVar( 'wgDBuser' );
- if( $dbUser == $this->getVar( '_InstallUser' ) ) {
+ if ( $dbUser == $this->getVar( '_InstallUser' ) ) {
return Status::newGood();
}
$status = $this->getConnection();
@@ -496,15 +516,13 @@ 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,
- false,
- 0,
- $this->getVar( 'wgDBprefix' )
- );
+ $db = 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 ) {
@@ -515,7 +533,7 @@ class MysqlInstaller extends DatabaseInstaller {
$tryToCreate = false;
}
- if( $tryToCreate ) {
+ if ( $tryToCreate ) {
$createHostList = array(
$server,
'localhost',
@@ -526,16 +544,16 @@ class MysqlInstaller extends DatabaseInstaller {
$createHostList = array_unique( $createHostList );
$escPass = $this->db->addQuotes( $password );
- foreach( $createHostList as $host ) {
+ foreach ( $createHostList as $host ) {
$fullName = $this->buildFullUserName( $dbUser, $host );
- if( !$this->userDefinitelyExists( $dbUser, $host ) ) {
- try{
+ if ( !$this->userDefinitelyExists( $dbUser, $host ) ) {
+ try {
$this->db->begin( __METHOD__ );
$this->db->query( "CREATE USER $fullName IDENTIFIED BY $escPass", __METHOD__ );
$this->db->commit( __METHOD__ );
$grantableNames[] = $fullName;
- } catch( DBQueryError $dqe ) {
- if( $this->db->lastErrno() == 1396 /* ER_CANNOT_USER */ ) {
+ } catch ( DBQueryError $dqe ) {
+ if ( $this->db->lastErrno() == 1396 /* ER_CANNOT_USER */ ) {
// User (probably) already exists
$this->db->rollback( __METHOD__ );
$status->warning( 'config-install-user-alreadyexists', $dbUser );
@@ -558,12 +576,12 @@ class MysqlInstaller extends DatabaseInstaller {
// Try to grant to all the users we know exist or we were able to create
$dbAllTables = $this->db->addIdentifierQuotes( $dbName ) . '.*';
- foreach( $grantableNames as $name ) {
+ foreach ( $grantableNames as $name ) {
try {
$this->db->begin( __METHOD__ );
$this->db->query( "GRANT ALL PRIVILEGES ON $dbAllTables TO $name", __METHOD__ );
$this->db->commit( __METHOD__ );
- } catch( DBQueryError $dqe ) {
+ } catch ( DBQueryError $dqe ) {
$this->db->rollback( __METHOD__ );
$status->fatal( 'config-install-user-grant-failed', $dbUser, $dqe->getText() );
}
@@ -593,11 +611,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 ) {
+ } catch ( DBQueryError $dqe ) {
return false;
}
-
}
/**
@@ -614,6 +632,7 @@ class MysqlInstaller extends DatabaseInstaller {
if ( $this->getVar( '_MysqlCharset' ) !== null ) {
$options[] = 'DEFAULT CHARSET=' . $this->getVar( '_MysqlCharset' );
}
+
return implode( ', ', $options );
}
@@ -635,8 +654,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