2010-05-07 12:25:01 +00:00
|
|
|
<?php
|
2010-08-21 18:20:09 +00:00
|
|
|
/**
|
|
|
|
|
* MySQL-specific installer.
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup Deployment
|
|
|
|
|
*/
|
2010-05-07 12:25:01 +00:00
|
|
|
|
2010-07-29 18:36:39 +00:00
|
|
|
/**
|
|
|
|
|
* Class for setting up the MediaWiki database using MySQL.
|
2010-12-06 20:04:28 +00:00
|
|
|
*
|
2010-07-29 18:36:39 +00:00
|
|
|
* @ingroup Deployment
|
|
|
|
|
* @since 1.17
|
|
|
|
|
*/
|
2010-07-20 09:30:33 +00:00
|
|
|
class MysqlInstaller extends DatabaseInstaller {
|
2010-12-16 11:20:39 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
protected $globalNames = array(
|
|
|
|
|
'wgDBserver',
|
|
|
|
|
'wgDBname',
|
|
|
|
|
'wgDBuser',
|
|
|
|
|
'wgDBpassword',
|
|
|
|
|
'wgDBprefix',
|
|
|
|
|
'wgDBTableOptions',
|
|
|
|
|
'wgDBmysql5',
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
protected $internalDefaults = array(
|
|
|
|
|
'_MysqlEngine' => 'InnoDB',
|
|
|
|
|
'_MysqlCharset' => 'binary',
|
|
|
|
|
);
|
|
|
|
|
|
2010-07-20 11:08:30 +00:00
|
|
|
public $supportedEngines = array( 'InnoDB', 'MyISAM' );
|
2010-05-07 12:25:01 +00:00
|
|
|
|
2010-07-20 11:08:30 +00:00
|
|
|
public $minimumVersion = '4.0.14';
|
2010-05-07 12:25:01 +00:00
|
|
|
|
2010-07-20 11:08:30 +00:00
|
|
|
public $webUserPrivs = array(
|
2010-05-07 12:25:01 +00:00
|
|
|
'DELETE',
|
|
|
|
|
'INSERT',
|
|
|
|
|
'SELECT',
|
|
|
|
|
'UPDATE',
|
|
|
|
|
'CREATE TEMPORARY TABLES',
|
|
|
|
|
);
|
|
|
|
|
|
2010-07-20 11:08:30 +00:00
|
|
|
public function getName() {
|
2010-05-07 12:25:01 +00:00
|
|
|
return 'mysql';
|
|
|
|
|
}
|
2010-07-04 21:25:16 +00:00
|
|
|
|
2010-07-20 11:08:30 +00:00
|
|
|
public function __construct( $parent ) {
|
2010-07-04 21:25:16 +00:00
|
|
|
parent::__construct( $parent );
|
|
|
|
|
}
|
2010-07-07 02:53:19 +00:00
|
|
|
|
2010-07-07 13:52:05 +00:00
|
|
|
public function isCompiled() {
|
2010-07-07 02:53:19 +00:00
|
|
|
return self::checkExtension( 'mysql' );
|
2010-05-07 12:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-20 11:08:30 +00:00
|
|
|
public function getGlobalDefaults() {
|
2010-05-07 12:25:01 +00:00
|
|
|
return array();
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-20 11:08:30 +00:00
|
|
|
public function getConnectForm() {
|
2010-05-07 12:25:01 +00:00
|
|
|
return
|
2010-12-06 20:04:28 +00:00
|
|
|
$this->getTextBox( 'wgDBserver', 'config-db-host', array(), $this->parent->getHelpBox( 'config-db-host-help' ) ) .
|
2010-11-04 23:21:24 +00:00
|
|
|
Html::openElement( 'fieldset' ) .
|
|
|
|
|
Html::element( 'legend', array(), wfMsg( 'config-db-wiki-settings' ) ) .
|
2010-12-06 20:04:28 +00:00
|
|
|
$this->getTextBox( 'wgDBname', 'config-db-name', array(), $this->parent->getHelpBox( 'config-db-name-help' ) ) .
|
|
|
|
|
$this->getTextBox( 'wgDBprefix', 'config-db-prefix', array(), $this->parent->getHelpBox( 'config-db-prefix-help' ) ) .
|
2010-11-04 23:21:24 +00:00
|
|
|
Html::closeElement( 'fieldset' ) .
|
2010-05-07 12:25:01 +00:00
|
|
|
$this->getInstallUserBox();
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-20 11:08:30 +00:00
|
|
|
public function submitConnectForm() {
|
2010-07-29 18:36:39 +00:00
|
|
|
// Get variables from the request.
|
2010-05-07 12:25:01 +00:00
|
|
|
$newValues = $this->setVarsFromRequest( array( 'wgDBserver', 'wgDBname', 'wgDBprefix' ) );
|
|
|
|
|
|
2010-07-29 18:36:39 +00:00
|
|
|
// Validate them.
|
2010-05-07 12:25:01 +00:00
|
|
|
$status = Status::newGood();
|
2011-01-12 09:59:55 +00:00
|
|
|
if ( !strlen( $newValues['wgDBserver'] ) ) {
|
|
|
|
|
$status->fatal( 'config-missing-db-host' );
|
|
|
|
|
}
|
2010-05-07 12:25:01 +00:00
|
|
|
if ( !strlen( $newValues['wgDBname'] ) ) {
|
|
|
|
|
$status->fatal( 'config-missing-db-name' );
|
2011-01-06 22:43:46 +00:00
|
|
|
} elseif ( !preg_match( '/^[a-z0-9_-]+$/i', $newValues['wgDBname'] ) ) {
|
2010-05-07 12:25:01 +00:00
|
|
|
$status->fatal( 'config-invalid-db-name', $newValues['wgDBname'] );
|
|
|
|
|
}
|
2011-01-06 22:43:46 +00:00
|
|
|
if ( !preg_match( '/^[a-z0-9_-]*$/i', $newValues['wgDBprefix'] ) ) {
|
2010-05-07 12:25:01 +00:00
|
|
|
$status->fatal( 'config-invalid-db-prefix', $newValues['wgDBprefix'] );
|
|
|
|
|
}
|
|
|
|
|
if ( !$status->isOK() ) {
|
|
|
|
|
return $status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Submit user box
|
|
|
|
|
$status = $this->submitInstallUserBox();
|
|
|
|
|
if ( !$status->isOK() ) {
|
|
|
|
|
return $status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Try to connect
|
|
|
|
|
$status = $this->getConnection();
|
|
|
|
|
if ( !$status->isOK() ) {
|
|
|
|
|
return $status;
|
|
|
|
|
}
|
|
|
|
|
$conn = $status->value;
|
|
|
|
|
|
|
|
|
|
// Check version
|
|
|
|
|
$version = $conn->getServerVersion();
|
|
|
|
|
if ( version_compare( $version, $this->minimumVersion ) < 0 ) {
|
|
|
|
|
return Status::newFatal( 'config-mysql-old', $this->minimumVersion, $version );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $status;
|
|
|
|
|
}
|
|
|
|
|
|
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database.
* Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade.
* Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this.
* Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used.
* Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes.
* Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database.
* In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary.
* On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added.
* Fixed several instances of inappropriate call-by-reference.
* Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler.
* Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892.
* In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString().
* Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging.
* MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
|
|
|
public function openConnection() {
|
2010-05-07 12:25:01 +00:00
|
|
|
$status = Status::newGood();
|
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database.
* Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade.
* Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this.
* Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used.
* Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes.
* Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database.
* In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary.
* On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added.
* Fixed several instances of inappropriate call-by-reference.
* Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler.
* Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892.
* In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString().
* Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging.
* MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
|
|
|
try {
|
|
|
|
|
$db = new DatabaseMysql(
|
|
|
|
|
$this->getVar( 'wgDBserver' ),
|
|
|
|
|
$this->getVar( '_InstallUser' ),
|
|
|
|
|
$this->getVar( '_InstallPassword' ),
|
|
|
|
|
false,
|
|
|
|
|
false,
|
|
|
|
|
0,
|
|
|
|
|
$this->getVar( 'wgDBprefix' )
|
|
|
|
|
);
|
|
|
|
|
$status->value = $db;
|
|
|
|
|
} catch ( DBConnectionError $e ) {
|
|
|
|
|
$status->fatal( 'config-connection-error', $e->getMessage() );
|
2010-05-07 12:25:01 +00:00
|
|
|
}
|
|
|
|
|
return $status;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-22 10:37:27 +00:00
|
|
|
public function preUpgrade() {
|
2010-09-07 20:57:53 +00:00
|
|
|
global $wgDBuser, $wgDBpassword;
|
|
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
$status = $this->getConnection();
|
|
|
|
|
if ( !$status->isOK() ) {
|
|
|
|
|
$this->parent->showStatusError( $status );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$conn = $status->value;
|
2010-08-22 10:37:27 +00:00
|
|
|
$conn->selectDB( $this->getVar( 'wgDBname' ) );
|
2010-05-07 12:25:01 +00:00
|
|
|
|
|
|
|
|
# Determine existing default character set
|
|
|
|
|
if ( $conn->tableExists( "revision" ) ) {
|
2010-12-21 16:09:32 +00:00
|
|
|
$revision = $conn->buildLike( $this->getVar( 'wgDBprefix' ) . 'revision' );
|
|
|
|
|
$res = $conn->query( "SHOW TABLE STATUS $revision", __METHOD__ );
|
2010-05-07 12:25:01 +00:00
|
|
|
$row = $conn->fetchObject( $res );
|
|
|
|
|
if ( !$row ) {
|
|
|
|
|
$this->parent->showMessage( 'config-show-table-status' );
|
|
|
|
|
$existingSchema = false;
|
|
|
|
|
$existingEngine = false;
|
|
|
|
|
} else {
|
|
|
|
|
if ( preg_match( '/^latin1/', $row->Collation ) ) {
|
|
|
|
|
$existingSchema = 'mysql4';
|
|
|
|
|
} elseif ( preg_match( '/^utf8/', $row->Collation ) ) {
|
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database.
* Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade.
* Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this.
* Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used.
* Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes.
* Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database.
* In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary.
* On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added.
* Fixed several instances of inappropriate call-by-reference.
* Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler.
* Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892.
* In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString().
* Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging.
* MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
|
|
|
$existingSchema = 'utf8';
|
2010-05-07 12:25:01 +00:00
|
|
|
} elseif ( preg_match( '/^binary/', $row->Collation ) ) {
|
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database.
* Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade.
* Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this.
* Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used.
* Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes.
* Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database.
* In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary.
* On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added.
* Fixed several instances of inappropriate call-by-reference.
* Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler.
* Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892.
* In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString().
* Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging.
* MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
|
|
|
$existingSchema = 'binary';
|
2010-05-07 12:25:01 +00:00
|
|
|
} else {
|
|
|
|
|
$existingSchema = false;
|
|
|
|
|
$this->parent->showMessage( 'config-unknown-collation' );
|
|
|
|
|
}
|
|
|
|
|
if ( isset( $row->Engine ) ) {
|
|
|
|
|
$existingEngine = $row->Engine;
|
|
|
|
|
} else {
|
|
|
|
|
$existingEngine = $row->Type;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-08-22 10:37:27 +00:00
|
|
|
} else {
|
|
|
|
|
$existingSchema = false;
|
|
|
|
|
$existingEngine = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $existingSchema && $existingSchema != $this->getVar( '_MysqlCharset' ) ) {
|
|
|
|
|
$this->setVar( '_MysqlCharset', $existingSchema );
|
|
|
|
|
}
|
|
|
|
|
if ( $existingEngine && $existingEngine != $this->getVar( '_MysqlEngine' ) ) {
|
|
|
|
|
$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' );
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
/**
|
|
|
|
|
* Get a list of storage engines that are available and supported
|
|
|
|
|
*/
|
2010-07-20 11:08:30 +00:00
|
|
|
public function getEngines() {
|
2010-05-07 12:25:01 +00:00
|
|
|
$engines = array( 'InnoDB', 'MyISAM' );
|
|
|
|
|
$status = $this->getConnection();
|
|
|
|
|
if ( !$status->isOK() ) {
|
|
|
|
|
return $engines;
|
|
|
|
|
}
|
|
|
|
|
$conn = $status->value;
|
|
|
|
|
|
|
|
|
|
$version = $conn->getServerVersion();
|
|
|
|
|
if ( version_compare( $version, "4.1.2", "<" ) ) {
|
|
|
|
|
// No SHOW ENGINES in this version
|
|
|
|
|
return $engines;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$engines = array();
|
2010-09-11 19:41:30 +00:00
|
|
|
$res = $conn->query( 'SHOW ENGINES', __METHOD__ );
|
2010-05-07 12:25:01 +00:00
|
|
|
foreach ( $res as $row ) {
|
|
|
|
|
if ( $row->Support == 'YES' || $row->Support == 'DEFAULT' ) {
|
|
|
|
|
$engines[] = $row->Engine;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$engines = array_intersect( $this->supportedEngines, $engines );
|
|
|
|
|
return $engines;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a list of character sets that are available and supported
|
|
|
|
|
*/
|
2010-07-20 11:08:30 +00:00
|
|
|
public function getCharsets() {
|
2010-05-07 12:25:01 +00:00
|
|
|
$status = $this->getConnection();
|
|
|
|
|
$mysql5 = array( 'binary', 'utf8' );
|
|
|
|
|
$mysql4 = array( 'mysql4' );
|
|
|
|
|
if ( !$status->isOK() ) {
|
|
|
|
|
return $mysql5;
|
|
|
|
|
}
|
|
|
|
|
if ( version_compare( $status->value->getServerVersion(), '4.1.0', '>=' ) ) {
|
|
|
|
|
return $mysql5;
|
|
|
|
|
}
|
|
|
|
|
return $mysql4;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return true if the install user can create accounts
|
|
|
|
|
*/
|
2010-07-20 11:08:30 +00:00
|
|
|
public function canCreateAccounts() {
|
2010-05-07 12:25:01 +00:00
|
|
|
$status = $this->getConnection();
|
|
|
|
|
if ( !$status->isOK() ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$conn = $status->value;
|
|
|
|
|
|
|
|
|
|
// Check version, need INFORMATION_SCHEMA and CREATE USER
|
|
|
|
|
if ( version_compare( $conn->getServerVersion(), '5.0.2', '<' ) ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get current account name
|
|
|
|
|
$currentName = $conn->selectField( '', 'CURRENT_USER()', '', __METHOD__ );
|
|
|
|
|
$parts = explode( '@', $currentName );
|
|
|
|
|
if ( count( $parts ) != 2 ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2010-12-06 20:04:28 +00:00
|
|
|
$quotedUser = $conn->addQuotes( $parts[0] ) .
|
2010-05-07 12:25:01 +00:00
|
|
|
'@' . $conn->addQuotes( $parts[1] );
|
|
|
|
|
|
|
|
|
|
// The user needs to have INSERT on mysql.* to be able to CREATE USER
|
|
|
|
|
// The grantee will be double-quoted in this query, as required
|
2010-12-06 20:04:28 +00:00
|
|
|
$res = $conn->select( 'INFORMATION_SCHEMA.USER_PRIVILEGES', '*',
|
2010-05-07 12:25:01 +00:00
|
|
|
array( 'GRANTEE' => $quotedUser ), __METHOD__ );
|
|
|
|
|
$insertMysql = false;
|
|
|
|
|
$grantOptions = array_flip( $this->webUserPrivs );
|
|
|
|
|
foreach ( $res as $row ) {
|
|
|
|
|
if ( $row->PRIVILEGE_TYPE == 'INSERT' ) {
|
|
|
|
|
$insertMysql = true;
|
|
|
|
|
}
|
|
|
|
|
if ( $row->IS_GRANTABLE ) {
|
|
|
|
|
unset( $grantOptions[$row->PRIVILEGE_TYPE] );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check for DB-specific privs for mysql.*
|
|
|
|
|
if ( !$insertMysql ) {
|
|
|
|
|
$row = $conn->selectRow( 'INFORMATION_SCHEMA.SCHEMA_PRIVILEGES', '*',
|
2010-12-06 20:04:28 +00:00
|
|
|
array(
|
2010-05-07 12:25:01 +00:00
|
|
|
'GRANTEE' => $quotedUser,
|
|
|
|
|
'TABLE_SCHEMA' => 'mysql',
|
|
|
|
|
'PRIVILEGE_TYPE' => 'INSERT',
|
|
|
|
|
), __METHOD__ );
|
|
|
|
|
if ( $row ) {
|
|
|
|
|
$insertMysql = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !$insertMysql ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check for DB-level grant options
|
2010-12-06 20:04:28 +00:00
|
|
|
$res = $conn->select( 'INFORMATION_SCHEMA.SCHEMA_PRIVILEGES', '*',
|
2010-05-07 12:25:01 +00:00
|
|
|
array(
|
|
|
|
|
'GRANTEE' => $quotedUser,
|
|
|
|
|
'IS_GRANTABLE' => 1,
|
|
|
|
|
), __METHOD__ );
|
|
|
|
|
foreach ( $res as $row ) {
|
|
|
|
|
$regex = $conn->likeToRegex( $row->TABLE_SCHEMA );
|
|
|
|
|
if ( preg_match( $regex, $this->getVar( 'wgDBname' ) ) ) {
|
|
|
|
|
unset( $grantOptions[$row->PRIVILEGE_TYPE] );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( count( $grantOptions ) ) {
|
|
|
|
|
// Can't grant everything
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-20 11:08:30 +00:00
|
|
|
public function getSettingsForm() {
|
2010-05-07 12:25:01 +00:00
|
|
|
if ( $this->canCreateAccounts() ) {
|
|
|
|
|
$noCreateMsg = false;
|
|
|
|
|
} else {
|
|
|
|
|
$noCreateMsg = 'config-db-web-no-create-privs';
|
|
|
|
|
}
|
|
|
|
|
$s = $this->getWebUserBox( $noCreateMsg );
|
|
|
|
|
|
|
|
|
|
// Do engine selector
|
|
|
|
|
$engines = $this->getEngines();
|
|
|
|
|
// If the current default engine is not supported, use an engine that is
|
|
|
|
|
if ( !in_array( $this->getVar( '_MysqlEngine' ), $engines ) ) {
|
|
|
|
|
$this->setVar( '_MysqlEngine', reset( $engines ) );
|
|
|
|
|
}
|
|
|
|
|
if ( count( $engines ) >= 2 ) {
|
|
|
|
|
$s .= $this->getRadioSet( array(
|
2010-12-06 20:04:28 +00:00
|
|
|
'var' => '_MysqlEngine',
|
|
|
|
|
'label' => 'config-mysql-engine',
|
|
|
|
|
'itemLabelPrefix' => 'config-mysql-',
|
2010-05-07 12:25:01 +00:00
|
|
|
'values' => $engines
|
|
|
|
|
));
|
|
|
|
|
$s .= $this->parent->getHelpBox( 'config-mysql-engine-help' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the current default charset is not supported, use a charset that is
|
|
|
|
|
$charsets = $this->getCharsets();
|
|
|
|
|
if ( !in_array( $this->getVar( '_MysqlCharset' ), $charsets ) ) {
|
|
|
|
|
$this->setVar( '_MysqlCharset', reset( $charsets ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Do charset selector
|
|
|
|
|
if ( count( $charsets ) >= 2 ) {
|
|
|
|
|
$s .= $this->getRadioSet( array(
|
|
|
|
|
'var' => '_MysqlCharset',
|
|
|
|
|
'label' => 'config-mysql-charset',
|
|
|
|
|
'itemLabelPrefix' => 'config-mysql-',
|
|
|
|
|
'values' => $charsets
|
|
|
|
|
));
|
|
|
|
|
$s .= $this->parent->getHelpBox( 'config-mysql-charset-help' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $s;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-20 11:08:30 +00:00
|
|
|
public function submitSettingsForm() {
|
2011-02-23 12:35:41 +00:00
|
|
|
$this->setVarsFromRequest( array( '_MysqlEngine', '_MysqlCharset' ) );
|
2010-05-07 12:25:01 +00:00
|
|
|
$status = $this->submitWebUserBox();
|
|
|
|
|
if ( !$status->isOK() ) {
|
|
|
|
|
return $status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Validate the create checkbox
|
|
|
|
|
$canCreate = $this->canCreateAccounts();
|
|
|
|
|
if ( !$canCreate ) {
|
|
|
|
|
$this->setVar( '_CreateDBAccount', false );
|
|
|
|
|
$create = false;
|
|
|
|
|
} else {
|
|
|
|
|
$create = $this->getVar( '_CreateDBAccount' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !$create ) {
|
|
|
|
|
// Test the web account
|
|
|
|
|
try {
|
2010-12-22 05:21:22 +00:00
|
|
|
new DatabaseMysql(
|
2010-05-07 12:25:01 +00:00
|
|
|
$this->getVar( 'wgDBserver' ),
|
|
|
|
|
$this->getVar( 'wgDBuser' ),
|
|
|
|
|
$this->getVar( 'wgDBpassword' ),
|
|
|
|
|
false,
|
|
|
|
|
false,
|
2010-12-06 20:04:28 +00:00
|
|
|
0,
|
2010-05-07 12:25:01 +00:00
|
|
|
$this->getVar( 'wgDBprefix' )
|
|
|
|
|
);
|
|
|
|
|
} catch ( DBConnectionError $e ) {
|
|
|
|
|
return Status::newFatal( 'config-connection-error', $e->getMessage() );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Validate engines and charsets
|
|
|
|
|
// This is done pre-submit already so it's just for security
|
|
|
|
|
$engines = $this->getEngines();
|
|
|
|
|
if ( !in_array( $this->getVar( '_MysqlEngine' ), $engines ) ) {
|
|
|
|
|
$this->setVar( '_MysqlEngine', reset( $engines ) );
|
|
|
|
|
}
|
|
|
|
|
$charsets = $this->getCharsets();
|
|
|
|
|
if ( !in_array( $this->getVar( '_MysqlCharset' ), $charsets ) ) {
|
|
|
|
|
$this->setVar( '_MysqlCharset', reset( $charsets ) );
|
|
|
|
|
}
|
|
|
|
|
return Status::newGood();
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-07 13:52:05 +00:00
|
|
|
public function preInstall() {
|
|
|
|
|
# Add our user callback to installSteps, right before the tables are created.
|
|
|
|
|
$callback = array(
|
2010-11-09 15:58:18 +00:00
|
|
|
'name' => 'user',
|
|
|
|
|
'callback' => array( $this, 'setupUser' ),
|
2010-07-07 13:52:05 +00:00
|
|
|
);
|
2010-12-22 05:21:22 +00:00
|
|
|
$this->parent->addInstallStep( $callback, 'tables' );
|
2010-07-07 13:52:05 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-20 11:08:30 +00:00
|
|
|
public function setupDatabase() {
|
2010-05-07 12:25:01 +00:00
|
|
|
$status = $this->getConnection();
|
|
|
|
|
if ( !$status->isOK() ) {
|
|
|
|
|
return $status;
|
|
|
|
|
}
|
|
|
|
|
$conn = $status->value;
|
|
|
|
|
$dbName = $this->getVar( 'wgDBname' );
|
|
|
|
|
if( !$conn->selectDB( $dbName ) ) {
|
2011-01-07 18:24:56 +00:00
|
|
|
$conn->query( "CREATE DATABASE " . $conn->addIdentifierQuotes( $dbName ), __METHOD__ );
|
2010-05-07 12:25:01 +00:00
|
|
|
$conn->selectDB( $dbName );
|
|
|
|
|
}
|
2011-01-27 08:25:48 +00:00
|
|
|
$this->setupSchemaVars();
|
2010-05-07 12:25:01 +00:00
|
|
|
return $status;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-20 11:08:30 +00:00
|
|
|
public function setupUser() {
|
2010-07-04 16:16:28 +00:00
|
|
|
$status = $this->getConnection();
|
|
|
|
|
if ( !$status->isOK() ) {
|
|
|
|
|
return $status;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-19 08:01:45 +00:00
|
|
|
$this->setupSchemaVars();
|
2011-03-01 18:46:16 +00:00
|
|
|
$dbName = $this->getVar( 'wgDBname' );
|
|
|
|
|
$this->db->selectDB( $dbName );
|
|
|
|
|
$server = $this->getVar( 'wgDBserver' );
|
|
|
|
|
$dbUser = $this->getVar( 'wgDBuser' );
|
|
|
|
|
$password = $this->getVar( 'wgDBpassword' );
|
|
|
|
|
$grantableNames = array();
|
|
|
|
|
|
2011-05-02 18:54:31 +00:00
|
|
|
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' )
|
|
|
|
|
);
|
|
|
|
|
$grantableNames[] = $this->buildFullUserName( $dbUser, $server );
|
|
|
|
|
$tryToCreate = false;
|
|
|
|
|
} catch ( DBConnectionError $e ) {
|
|
|
|
|
$tryToCreate = true;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2011-03-01 18:46:16 +00:00
|
|
|
$grantableNames[] = $this->buildFullUserName( $dbUser, $server );
|
|
|
|
|
$tryToCreate = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( $tryToCreate ) {
|
|
|
|
|
$createHostList = array($server,
|
|
|
|
|
'localhost',
|
|
|
|
|
'localhost.localdomain',
|
|
|
|
|
'%'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$createHostList = array_unique( $createHostList );
|
|
|
|
|
$escPass = $this->db->addQuotes( $password );
|
|
|
|
|
|
|
|
|
|
foreach( $createHostList as $host ) {
|
|
|
|
|
$fullName = $this->buildFullUserName( $dbUser, $host );
|
|
|
|
|
if( !$this->userDefinitelyExists( $dbUser, $host ) ) {
|
|
|
|
|
try{
|
|
|
|
|
$this->db->begin();
|
|
|
|
|
$this->db->query( "CREATE USER $fullName IDENTIFIED BY $escPass", __METHOD__ );
|
|
|
|
|
$this->db->commit();
|
|
|
|
|
$grantableNames[] = $fullName;
|
|
|
|
|
} catch( DBQueryError $dqe ) {
|
|
|
|
|
if( $this->db->lastErrno() == 1396 /* ER_CANNOT_USER */ ) {
|
|
|
|
|
// User (probably) already exists
|
|
|
|
|
$this->db->rollback();
|
|
|
|
|
$status->warning( 'config-install-user-alreadyexists', $dbUser );
|
|
|
|
|
$grantableNames[] = $fullName;
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
// If we couldn't create for some bizzare reason and the
|
|
|
|
|
// user probably doesn't exist, skip the grant
|
|
|
|
|
$this->db->rollback();
|
|
|
|
|
$status->warning( 'config-install-user-create-failed', $dbUser, $dqe->getText() );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$status->warning( 'config-install-user-alreadyexists', $dbUser );
|
|
|
|
|
$grantableNames[] = $fullName;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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 ) {
|
|
|
|
|
try {
|
|
|
|
|
$this->db->begin();
|
|
|
|
|
$this->db->query( "GRANT ALL PRIVILEGES ON $dbAllTables TO $name", __METHOD__ );
|
|
|
|
|
$this->db->commit();
|
|
|
|
|
} catch( DBQueryError $dqe ) {
|
|
|
|
|
$this->db->rollback();
|
|
|
|
|
$status->fatal( 'config-install-user-grant-failed', $dbUser, $dqe->getText() );
|
|
|
|
|
}
|
2010-07-04 16:16:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $status;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-01 18:46:16 +00:00
|
|
|
/**
|
|
|
|
|
* Return a formal 'User'@'Host' username for use in queries
|
|
|
|
|
* @param $name String Username, quotes will be added
|
|
|
|
|
* @param $host String Hostname, quotes will be added
|
|
|
|
|
* @return String
|
|
|
|
|
*/
|
|
|
|
|
private function buildFullUserName( $name, $host ) {
|
|
|
|
|
return $this->db->addQuotes( $name ) . '@' . $this->db->addQuotes( $host );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Try to see if the user account exists. Our "superuser" may not have
|
|
|
|
|
* access to mysql.user, so false means "no" or "maybe"
|
|
|
|
|
* @param $host String Hostname to check
|
|
|
|
|
* @param $user String Username to check
|
|
|
|
|
* @return boolean
|
|
|
|
|
*/
|
|
|
|
|
private function userDefinitelyExists( $host, $user ) {
|
|
|
|
|
try {
|
|
|
|
|
$res = $this->db->selectRow( 'mysql.user', array( 'Host', 'User' ),
|
|
|
|
|
array( 'Host' => $host, 'User' => $user ), __METHOD__ );
|
|
|
|
|
return (bool)$res;
|
|
|
|
|
} catch( DBQueryError $dqe ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database.
* Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade.
* Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this.
* Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used.
* Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes.
* Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database.
* In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary.
* On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added.
* Fixed several instances of inappropriate call-by-reference.
* Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler.
* Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892.
* In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString().
* Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging.
* MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
|
|
|
/**
|
|
|
|
|
* Return any table options to be applied to all tables that don't
|
|
|
|
|
* override them.
|
|
|
|
|
*
|
|
|
|
|
* @return String
|
|
|
|
|
*/
|
|
|
|
|
protected function getTableOptions() {
|
|
|
|
|
$options = array();
|
|
|
|
|
if ( $this->getVar( '_MysqlEngine' ) !== null ) {
|
|
|
|
|
$options[] = "ENGINE=" . $this->getVar( '_MysqlEngine' );
|
|
|
|
|
}
|
|
|
|
|
if ( $this->getVar( '_MysqlCharset' ) !== null ) {
|
|
|
|
|
$options[] = 'DEFAULT CHARSET=' . $this->getVar( '_MysqlCharset' );
|
|
|
|
|
}
|
|
|
|
|
return implode( ', ', $options );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get variables to substitute into tables.sql and the SQL patch files.
|
|
|
|
|
*/
|
|
|
|
|
public function getSchemaVars() {
|
|
|
|
|
return array(
|
|
|
|
|
'wgDBTableOptions' => $this->getTableOptions(),
|
2011-02-19 08:01:45 +00:00
|
|
|
'wgDBname' => $this->getVar( 'wgDBname' ),
|
|
|
|
|
'wgDBuser' => $this->getVar( 'wgDBuser' ),
|
|
|
|
|
'wgDBpassword' => $this->getVar( 'wgDBpassword' ),
|
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database.
* Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade.
* Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this.
* Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used.
* Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes.
* Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database.
* In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary.
* On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added.
* Fixed several instances of inappropriate call-by-reference.
* Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler.
* Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892.
* In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString().
* Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging.
* MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
|
|
|
);
|
2010-05-07 12:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-20 11:08:30 +00:00
|
|
|
public function getLocalSettings() {
|
2010-05-07 12:25:01 +00:00
|
|
|
$dbmysql5 = wfBoolToStr( $this->getVar( 'wgDBmysql5', true ) );
|
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database.
* Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade.
* Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this.
* Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used.
* Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes.
* Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database.
* In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary.
* On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added.
* Fixed several instances of inappropriate call-by-reference.
* Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler.
* Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892.
* In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString().
* Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging.
* MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
|
|
|
$prefix = LocalSettingsGenerator::escapePhpString( $this->getVar( 'wgDBprefix' ) );
|
|
|
|
|
$tblOpts = LocalSettingsGenerator::escapePhpString( $this->getTableOptions() );
|
2010-05-07 12:25:01 +00:00
|
|
|
return
|
|
|
|
|
"# MySQL specific settings
|
|
|
|
|
\$wgDBprefix = \"{$prefix}\";
|
|
|
|
|
|
|
|
|
|
# MySQL table options to use during installation or update
|
|
|
|
|
\$wgDBTableOptions = \"{$tblOpts}\";
|
|
|
|
|
|
|
|
|
|
# Experimental charset support for MySQL 4.1/5.0.
|
|
|
|
|
\$wgDBmysql5 = {$dbmysql5};";
|
|
|
|
|
}
|
|
|
|
|
}
|