2010-05-07 12:25:01 +00:00
|
|
|
<?php
|
2024-01-05 18:52:59 +00:00
|
|
|
|
2010-08-21 18:20:09 +00:00
|
|
|
/**
|
|
|
|
|
* MySQL-specific installer.
|
|
|
|
|
*
|
2012-05-06 05:50:15 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
2010-08-21 18:20:09 +00:00
|
|
|
* @file
|
2019-11-25 23:24:49 +00:00
|
|
|
* @ingroup Installer
|
2010-08-21 18:20:09 +00:00
|
|
|
*/
|
2010-05-07 12:25:01 +00:00
|
|
|
|
2024-01-05 18:52:59 +00:00
|
|
|
namespace MediaWiki\Installer;
|
|
|
|
|
|
2023-08-25 12:29:41 +00:00
|
|
|
use MediaWiki\Status\Status;
|
2023-02-23 17:56:12 +00:00
|
|
|
use Wikimedia\Rdbms\DatabaseFactory;
|
2023-09-13 07:23:02 +00:00
|
|
|
use Wikimedia\Rdbms\DatabaseMySQL;
|
2017-02-24 16:17:16 +00:00
|
|
|
use Wikimedia\Rdbms\DBConnectionError;
|
2020-01-10 00:00:51 +00:00
|
|
|
use Wikimedia\Rdbms\DBQueryError;
|
2023-07-22 20:59:55 +00:00
|
|
|
use Wikimedia\Rdbms\IDatabase;
|
2017-02-07 04:49:57 +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
|
|
|
*
|
2019-11-25 23:24:49 +00:00
|
|
|
* @ingroup Installer
|
2010-07-29 18:36:39 +00:00
|
|
|
* @since 1.17
|
|
|
|
|
*/
|
2010-07-20 09:30:33 +00:00
|
|
|
class MysqlInstaller extends DatabaseInstaller {
|
2010-12-16 11:20:39 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
protected $globalNames = [
|
2010-05-07 12:25:01 +00:00
|
|
|
'wgDBserver',
|
|
|
|
|
'wgDBname',
|
|
|
|
|
'wgDBuser',
|
|
|
|
|
'wgDBpassword',
|
2023-05-03 17:43:43 +00:00
|
|
|
'wgDBssl',
|
2010-05-07 12:25:01 +00:00
|
|
|
'wgDBprefix',
|
|
|
|
|
'wgDBTableOptions',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2010-05-07 12:25:01 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
protected $internalDefaults = [
|
2010-05-07 12:25:01 +00:00
|
|
|
'_MysqlEngine' => 'InnoDB',
|
|
|
|
|
'_MysqlCharset' => 'binary',
|
PostgreSQL install fixes:
* Made PG throw a DBQueryError when it gets a query error, instead of DBUnexpectedError. Apparently this mistake goes back to r14625, when exceptions were first introduced. Did it by removing reportQueryError(), the DatabaseBase version works fine.
* Fixed several places where there was an attempt to check for a query error by checking if the result of query() was false. This never worked. Used try/catch instead.
* Made the DBConnectionError messages go on one line so that they don't mess up the formatting in the installer.
* In DatabasePostgres::selectDB(), only disconnect and reconnect if the DB name is actually changing.
* Made DatabasePostgres::schemaExists() less weird and scary.
* Added DatabasePostgres::roleExists() for use by the installer.
* Removed the PostgreSQL-specific hack to make _InstallUser have a default other than "root". Made _InstallUser into a proper DBMS-specific internal variable instead, since every DBMS we support so far needs a different default.
* Removed the $dbName parameters from openConnection/getConnection, and got rid of $this->useAdmin. Implemented a more sophisticated caching scheme instead. Partial revert of r89389 and r81440.
* When connecting as the install user before DB creation, and when testing the web user's credentials, try a few different database names and use whichever one works.
* Instead of connecting as the web user to create tables, I used SET ROLE. It seems cleaner and more like what the other DBMSes do during installation. "SET ROLE wikiuser" requires the same privileges as "CREATE SCHEMA ... AUTHORIZATION wikiuser", so it's unlikely to break anything.
* In the area of web account creation, fixed various minor logic errors and introduced more informative error messages at the submit stage, pre-install. Show a helpful error message if the web user exists already and the install user can't do the relevant SET ROLE.
* Split schema creation out to a separate install step.
* When creating an account as a non-superuser, add the administrative account to the new account's group. This is necessary to avoid a fatal error during installation (bug 28845).
* Removed code which alters an existing web user to have appropriate search paths and permissions. This may break other apps and is not necessary. As in other DBMSes, If the web user exists, it is the responsibility of the sysadmin to ensure that it has appropriate permissions.
* Rewrote setupPLpgSQL() to use the query builder functions.
2011-06-10 11:32:57 +00:00
|
|
|
'_InstallUser' => 'root',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2010-05-07 12:25:01 +00:00
|
|
|
|
2019-06-29 07:58:02 +00:00
|
|
|
public $supportedEngines = [ 'InnoDB' ];
|
2010-05-07 12:25:01 +00:00
|
|
|
|
2023-07-22 20:59:55 +00:00
|
|
|
private const MIN_VERSIONS = [
|
|
|
|
|
'MySQL' => '5.7.0',
|
|
|
|
|
'MariaDB' => '10.3',
|
|
|
|
|
];
|
|
|
|
|
public static $minimumVersion;
|
|
|
|
|
protected static $notMinimumVersionMessage;
|
2011-05-15 13:21:16 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
public $webUserPrivs = [
|
2010-05-07 12:25:01 +00:00
|
|
|
'DELETE',
|
|
|
|
|
'INSERT',
|
|
|
|
|
'SELECT',
|
|
|
|
|
'UPDATE',
|
|
|
|
|
'CREATE TEMPORARY TABLES',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2010-05-07 12:25:01 +00:00
|
|
|
|
2011-05-26 20:26:51 +00:00
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
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
|
|
|
|
2011-05-26 20:26:51 +00:00
|
|
|
/**
|
2014-04-19 11:55:27 +00:00
|
|
|
* @return bool
|
2011-05-26 20:26:51 +00:00
|
|
|
*/
|
2010-07-07 13:52:05 +00:00
|
|
|
public function isCompiled() {
|
2018-01-16 19:02:11 +00:00
|
|
|
return self::checkExtension( 'mysqli' );
|
2010-05-07 12:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
2024-03-04 05:27:34 +00:00
|
|
|
public function getConnectForm( WebInstaller $webInstaller ): DatabaseConnectForm {
|
|
|
|
|
return new MysqlConnectForm( $webInstaller, $this );
|
2010-05-07 12:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
2024-03-04 05:27:34 +00:00
|
|
|
public function getSettingsForm( WebInstaller $webInstaller ): DatabaseSettingsForm {
|
|
|
|
|
return new MysqlSettingsForm( $webInstaller, $this );
|
2023-07-22 20:59:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function meetsMinimumRequirement( IDatabase $conn ) {
|
|
|
|
|
$type = str_contains( $conn->getSoftwareLink(), 'MariaDB' ) ? 'MariaDB' : 'MySQL';
|
|
|
|
|
self::$minimumVersion = self::MIN_VERSIONS[$type];
|
|
|
|
|
// Used messages: config-mysql-old, config-mariadb-old
|
|
|
|
|
self::$notMinimumVersionMessage = 'config-' . strtolower( $type ) . '-old';
|
|
|
|
|
return parent::meetsMinimumRequirement( $conn );
|
2010-05-07 12:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
2011-05-26 20:26:51 +00:00
|
|
|
/**
|
2024-03-04 05:27:34 +00:00
|
|
|
* @return ConnectionStatus
|
2011-05-26 20:26:51 +00:00
|
|
|
*/
|
PostgreSQL install fixes:
* Made PG throw a DBQueryError when it gets a query error, instead of DBUnexpectedError. Apparently this mistake goes back to r14625, when exceptions were first introduced. Did it by removing reportQueryError(), the DatabaseBase version works fine.
* Fixed several places where there was an attempt to check for a query error by checking if the result of query() was false. This never worked. Used try/catch instead.
* Made the DBConnectionError messages go on one line so that they don't mess up the formatting in the installer.
* In DatabasePostgres::selectDB(), only disconnect and reconnect if the DB name is actually changing.
* Made DatabasePostgres::schemaExists() less weird and scary.
* Added DatabasePostgres::roleExists() for use by the installer.
* Removed the PostgreSQL-specific hack to make _InstallUser have a default other than "root". Made _InstallUser into a proper DBMS-specific internal variable instead, since every DBMS we support so far needs a different default.
* Removed the $dbName parameters from openConnection/getConnection, and got rid of $this->useAdmin. Implemented a more sophisticated caching scheme instead. Partial revert of r89389 and r81440.
* When connecting as the install user before DB creation, and when testing the web user's credentials, try a few different database names and use whichever one works.
* Instead of connecting as the web user to create tables, I used SET ROLE. It seems cleaner and more like what the other DBMSes do during installation. "SET ROLE wikiuser" requires the same privileges as "CREATE SCHEMA ... AUTHORIZATION wikiuser", so it's unlikely to break anything.
* In the area of web account creation, fixed various minor logic errors and introduced more informative error messages at the submit stage, pre-install. Show a helpful error message if the web user exists already and the install user can't do the relevant SET ROLE.
* Split schema creation out to a separate install step.
* When creating an account as a non-superuser, add the administrative account to the new account's group. This is necessary to avoid a fatal error during installation (bug 28845).
* Removed code which alters an existing web user to have appropriate search paths and permissions. This may break other apps and is not necessary. As in other DBMSes, If the web user exists, it is the responsibility of the sysadmin to ensure that it has appropriate permissions.
* Rewrote setupPLpgSQL() to use the query builder functions.
2011-06-10 11:32:57 +00:00
|
|
|
public function openConnection() {
|
2024-03-04 05:27:34 +00:00
|
|
|
$status = new ConnectionStatus;
|
* 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 {
|
2023-09-13 07:23:02 +00:00
|
|
|
/** @var DatabaseMySQL $db */
|
2023-02-23 17:56:12 +00:00
|
|
|
$db = ( new DatabaseFactory() )->create( 'mysql', [
|
2013-10-16 23:38:11 +00:00
|
|
|
'host' => $this->getVar( 'wgDBserver' ),
|
|
|
|
|
'user' => $this->getVar( '_InstallUser' ),
|
|
|
|
|
'password' => $this->getVar( '_InstallPassword' ),
|
2023-05-03 17:43:43 +00:00
|
|
|
'ssl' => $this->getVar( 'wgDBssl' ),
|
2024-05-23 19:17:07 +00:00
|
|
|
'dbname' => null,
|
2013-10-16 23:38:11 +00:00
|
|
|
'flags' => 0,
|
2016-02-17 09:09:32 +00:00
|
|
|
'tablePrefix' => $this->getVar( 'wgDBprefix' ) ] );
|
2024-03-04 05:27:34 +00:00
|
|
|
$status->setDB( $db );
|
* 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
|
|
|
} catch ( DBConnectionError $e ) {
|
|
|
|
|
$status->fatal( 'config-connection-error', $e->getMessage() );
|
2010-05-07 12:25:01 +00:00
|
|
|
}
|
2013-10-08 11:43:42 +00:00
|
|
|
|
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() ) {
|
2019-06-29 07:58:02 +00:00
|
|
|
$this->parent->showStatusMessage( $status );
|
2013-10-08 11:43:42 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2024-03-04 05:27:34 +00:00
|
|
|
$conn = $status->getDB();
|
2022-06-07 20:10:35 +00:00
|
|
|
$this->selectDatabase( $conn, $this->getVar( 'wgDBname' ) );
|
2010-05-07 12:25:01 +00:00
|
|
|
# Determine existing default character set
|
2011-11-10 20:39:23 +00:00
|
|
|
if ( $conn->tableExists( "revision", __METHOD__ ) ) {
|
2017-05-24 22:20:55 +00:00
|
|
|
$revision = $this->escapeLikeInternal( $this->getVar( 'wgDBprefix' ) . 'revision', '\\' );
|
|
|
|
|
$res = $conn->query( "SHOW TABLE STATUS LIKE '$revision'", __METHOD__ );
|
2022-01-19 00:42:16 +00:00
|
|
|
$row = $res->fetchObject();
|
2010-05-07 12:25:01 +00:00
|
|
|
if ( !$row ) {
|
|
|
|
|
$this->parent->showMessage( 'config-show-table-status' );
|
|
|
|
|
$existingSchema = false;
|
|
|
|
|
$existingEngine = false;
|
|
|
|
|
} else {
|
|
|
|
|
if ( preg_match( '/^latin1/', $row->Collation ) ) {
|
2012-01-04 15:52:48 +00:00
|
|
|
$existingSchema = 'latin1';
|
2010-05-07 12:25:01 +00:00
|
|
|
} 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' );
|
|
|
|
|
}
|
2018-10-20 21:55:44 +00:00
|
|
|
$existingEngine = $row->Engine ?? $row->Type;
|
2010-05-07 12:25:01 +00:00
|
|
|
}
|
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' );
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-24 22:20:55 +00:00
|
|
|
/**
|
|
|
|
|
* @param string $s
|
2017-09-09 20:47:04 +00:00
|
|
|
* @param string $escapeChar
|
2017-05-24 22:20:55 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
protected function escapeLikeInternal( $s, $escapeChar = '`' ) {
|
|
|
|
|
return str_replace( [ $escapeChar, '%', '_' ],
|
|
|
|
|
[ "{$escapeChar}{$escapeChar}", "{$escapeChar}%", "{$escapeChar}_" ],
|
|
|
|
|
$s );
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
/**
|
|
|
|
|
* Get a list of storage engines that are available and supported
|
2011-05-26 20:26:51 +00:00
|
|
|
*
|
|
|
|
|
* @return array
|
2010-05-07 12:25:01 +00:00
|
|
|
*/
|
2010-07-20 11:08:30 +00:00
|
|
|
public function getEngines() {
|
2010-05-07 12:25:01 +00:00
|
|
|
$status = $this->getConnection();
|
2024-03-04 05:27:34 +00:00
|
|
|
$conn = $status->getDB();
|
2010-05-07 12:25:01 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$engines = [];
|
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 );
|
2013-10-08 11:43:42 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
return $engines;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a list of character sets that are available and supported
|
2011-05-26 20:26:51 +00:00
|
|
|
*
|
|
|
|
|
* @return array
|
2010-05-07 12:25:01 +00:00
|
|
|
*/
|
2010-07-20 11:08:30 +00:00
|
|
|
public function getCharsets() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [ 'binary', 'utf8' ];
|
2010-05-07 12:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return true if the install user can create accounts
|
2011-05-26 20:26:51 +00:00
|
|
|
*
|
|
|
|
|
* @return bool
|
2010-05-07 12:25:01 +00:00
|
|
|
*/
|
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;
|
|
|
|
|
}
|
2024-03-04 05:27:34 +00:00
|
|
|
$conn = $status->getDB();
|
2010-05-07 12:25:01 +00:00
|
|
|
|
|
|
|
|
// 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', '*',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'GRANTEE' => $quotedUser ], __METHOD__ );
|
2010-05-07 12:25:01 +00:00
|
|
|
$insertMysql = false;
|
2021-06-11 02:52:06 +00:00
|
|
|
$grantOptions = array_fill_keys( $this->webUserPrivs, true );
|
2010-05-07 12:25:01 +00:00
|
|
|
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', '*',
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2010-05-07 12:25:01 +00:00
|
|
|
'GRANTEE' => $quotedUser,
|
|
|
|
|
'TABLE_SCHEMA' => 'mysql',
|
|
|
|
|
'PRIVILEGE_TYPE' => 'INSERT',
|
2016-02-17 09:09:32 +00:00
|
|
|
], __METHOD__ );
|
2010-05-07 12:25:01 +00:00
|
|
|
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', '*',
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2010-05-07 12:25:01 +00:00
|
|
|
'GRANTEE' => $quotedUser,
|
|
|
|
|
'IS_GRANTABLE' => 1,
|
2016-02-17 09:09:32 +00:00
|
|
|
], __METHOD__ );
|
2010-05-07 12:25:01 +00:00
|
|
|
foreach ( $res as $row ) {
|
2017-01-11 18:23:00 +00:00
|
|
|
$regex = $this->likeToRegex( $row->TABLE_SCHEMA );
|
2010-05-07 12:25:01 +00:00
|
|
|
if ( preg_match( $regex, $this->getVar( 'wgDBname' ) ) ) {
|
|
|
|
|
unset( $grantOptions[$row->PRIVILEGE_TYPE] );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( count( $grantOptions ) ) {
|
|
|
|
|
// Can't grant everything
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-10-08 11:43:42 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-11 18:23:00 +00:00
|
|
|
/**
|
|
|
|
|
* Convert a wildcard (as used in LIKE) to a regex
|
|
|
|
|
* Slashes are escaped, slash terminators included
|
2017-09-09 20:47:04 +00:00
|
|
|
* @param string $wildcard
|
|
|
|
|
* @return string
|
2017-01-11 18:23:00 +00:00
|
|
|
*/
|
|
|
|
|
protected function likeToRegex( $wildcard ) {
|
|
|
|
|
$r = preg_quote( $wildcard, '/' );
|
|
|
|
|
$r = strtr( $r, [
|
|
|
|
|
'%' => '.*',
|
|
|
|
|
'_' => '.'
|
|
|
|
|
] );
|
|
|
|
|
return "/$r/s";
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-07 13:52:05 +00:00
|
|
|
public function preInstall() {
|
|
|
|
|
# Add our user callback to installSteps, right before the tables are created.
|
2016-02-17 09:09:32 +00:00
|
|
|
$callback = [
|
2010-11-09 15:58:18 +00:00
|
|
|
'name' => 'user',
|
2016-02-17 09:09:32 +00:00
|
|
|
'callback' => [ $this, 'setupUser' ],
|
|
|
|
|
];
|
2010-12-22 05:21:22 +00:00
|
|
|
$this->parent->addInstallStep( $callback, 'tables' );
|
2010-07-07 13:52:05 +00:00
|
|
|
}
|
|
|
|
|
|
2011-05-26 20:26:51 +00:00
|
|
|
/**
|
|
|
|
|
* @return Status
|
|
|
|
|
*/
|
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;
|
|
|
|
|
}
|
2024-03-04 05:27:34 +00:00
|
|
|
$conn = $status->getDB();
|
2010-05-07 12:25:01 +00:00
|
|
|
$dbName = $this->getVar( 'wgDBname' );
|
2018-08-25 05:49:15 +00:00
|
|
|
if ( !$this->databaseExists( $dbName ) ) {
|
2013-10-23 12:16:03 +00:00
|
|
|
$conn->query(
|
|
|
|
|
"CREATE DATABASE " . $conn->addIdentifierQuotes( $dbName ) . "CHARACTER SET utf8",
|
|
|
|
|
__METHOD__
|
|
|
|
|
);
|
2010-05-07 12:25:01 +00:00
|
|
|
}
|
2022-06-07 20:10:35 +00:00
|
|
|
$this->selectDatabase( $conn, $dbName );
|
2011-01-27 08:25:48 +00:00
|
|
|
$this->setupSchemaVars();
|
2013-10-08 11:43:42 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
return $status;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-25 05:49:15 +00:00
|
|
|
/**
|
|
|
|
|
* 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;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-26 20:26:51 +00:00
|
|
|
/**
|
|
|
|
|
* @return Status
|
|
|
|
|
*/
|
2010-07-20 11:08:30 +00:00
|
|
|
public function setupUser() {
|
2011-05-05 21:28:26 +00:00
|
|
|
$dbUser = $this->getVar( 'wgDBuser' );
|
2013-04-20 21:11:46 +00:00
|
|
|
if ( $dbUser == $this->getVar( '_InstallUser' ) ) {
|
2011-05-05 21:28:26 +00:00
|
|
|
return Status::newGood();
|
|
|
|
|
}
|
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' );
|
2022-06-07 20:10:35 +00:00
|
|
|
$this->selectDatabase( $this->db, $dbName );
|
2011-03-01 18:46:16 +00:00
|
|
|
$server = $this->getVar( 'wgDBserver' );
|
|
|
|
|
$password = $this->getVar( 'wgDBpassword' );
|
2016-02-17 09:09:32 +00:00
|
|
|
$grantableNames = [];
|
2011-03-01 18:46:16 +00:00
|
|
|
|
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
|
2023-02-23 17:56:12 +00:00
|
|
|
( new DatabaseFactory() )->create( 'mysql', [
|
2013-10-16 23:38:11 +00:00
|
|
|
'host' => $server,
|
|
|
|
|
'user' => $dbUser,
|
|
|
|
|
'password' => $password,
|
2023-05-03 17:43:43 +00:00
|
|
|
'ssl' => $this->getVar( 'wgDBssl' ),
|
2024-05-23 19:17:07 +00:00
|
|
|
'dbname' => null,
|
2013-10-16 23:38:11 +00:00
|
|
|
'flags' => 0,
|
2013-11-25 13:42:34 +00:00
|
|
|
'tablePrefix' => $this->getVar( 'wgDBprefix' )
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2011-05-02 18:54:31 +00:00
|
|
|
$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;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-20 21:11:46 +00:00
|
|
|
if ( $tryToCreate ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$createHostList = [
|
2013-02-03 19:28:43 +00:00
|
|
|
$server,
|
2011-03-01 18:46:16 +00:00
|
|
|
'localhost',
|
|
|
|
|
'localhost.localdomain',
|
|
|
|
|
'%'
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2011-03-01 18:46:16 +00:00
|
|
|
|
|
|
|
|
$createHostList = array_unique( $createHostList );
|
|
|
|
|
$escPass = $this->db->addQuotes( $password );
|
|
|
|
|
|
2013-04-20 21:11:46 +00:00
|
|
|
foreach ( $createHostList as $host ) {
|
2011-03-01 18:46:16 +00:00
|
|
|
$fullName = $this->buildFullUserName( $dbUser, $host );
|
2016-05-25 19:52:46 +00:00
|
|
|
if ( !$this->userDefinitelyExists( $host, $dbUser ) ) {
|
2013-04-27 12:02:08 +00:00
|
|
|
try {
|
2012-02-24 18:45:24 +00:00
|
|
|
$this->db->begin( __METHOD__ );
|
2011-03-01 18:46:16 +00:00
|
|
|
$this->db->query( "CREATE USER $fullName IDENTIFIED BY $escPass", __METHOD__ );
|
2012-02-24 18:45:24 +00:00
|
|
|
$this->db->commit( __METHOD__ );
|
2011-03-01 18:46:16 +00:00
|
|
|
$grantableNames[] = $fullName;
|
2013-04-27 12:02:08 +00:00
|
|
|
} catch ( DBQueryError $dqe ) {
|
2013-04-20 21:11:46 +00:00
|
|
|
if ( $this->db->lastErrno() == 1396 /* ER_CANNOT_USER */ ) {
|
2011-03-01 18:46:16 +00:00
|
|
|
// User (probably) already exists
|
2012-02-26 17:19:11 +00:00
|
|
|
$this->db->rollback( __METHOD__ );
|
2011-03-01 18:46:16 +00:00
|
|
|
$status->warning( 'config-install-user-alreadyexists', $dbUser );
|
|
|
|
|
$grantableNames[] = $fullName;
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
2022-01-09 17:30:20 +00:00
|
|
|
// If we couldn't create for some bizarre reason and the
|
2011-03-01 18:46:16 +00:00
|
|
|
// user probably doesn't exist, skip the grant
|
2012-02-26 17:19:11 +00:00
|
|
|
$this->db->rollback( __METHOD__ );
|
2017-05-15 15:17:04 +00:00
|
|
|
$status->warning( 'config-install-user-create-failed', $dbUser, $dqe->getMessage() );
|
2011-03-01 18:46:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} 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 ) . '.*';
|
2013-04-20 21:11:46 +00:00
|
|
|
foreach ( $grantableNames as $name ) {
|
2011-03-01 18:46:16 +00:00
|
|
|
try {
|
2012-02-24 18:45:24 +00:00
|
|
|
$this->db->begin( __METHOD__ );
|
2011-03-01 18:46:16 +00:00
|
|
|
$this->db->query( "GRANT ALL PRIVILEGES ON $dbAllTables TO $name", __METHOD__ );
|
2012-02-24 18:45:24 +00:00
|
|
|
$this->db->commit( __METHOD__ );
|
2013-04-27 12:02:08 +00:00
|
|
|
} catch ( DBQueryError $dqe ) {
|
2012-02-24 18:45:24 +00:00
|
|
|
$this->db->rollback( __METHOD__ );
|
2017-05-15 15:17:04 +00:00
|
|
|
$status->fatal( 'config-install-user-grant-failed', $dbUser, $dqe->getMessage() );
|
2011-03-01 18:46:16 +00:00
|
|
|
}
|
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
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $name Username, quotes will be added
|
|
|
|
|
* @param string $host Hostname, quotes will be added
|
2014-04-19 11:55:27 +00:00
|
|
|
* @return string
|
2011-03-01 18:46:16 +00:00
|
|
|
*/
|
|
|
|
|
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"
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $host Hostname to check
|
|
|
|
|
* @param string $user Username to check
|
2014-04-19 11:55:27 +00:00
|
|
|
* @return bool
|
2011-03-01 18:46:16 +00:00
|
|
|
*/
|
|
|
|
|
private function userDefinitelyExists( $host, $user ) {
|
|
|
|
|
try {
|
2023-09-19 11:06:53 +00:00
|
|
|
$res = $this->db->newSelectQueryBuilder()
|
|
|
|
|
->select( [ 'Host', 'User' ] )
|
|
|
|
|
->from( 'mysql.user' )
|
|
|
|
|
->where( [ 'Host' => $host, 'User' => $user ] )
|
|
|
|
|
->caller( __METHOD__ )->fetchRow();
|
2013-10-08 11:43:42 +00:00
|
|
|
|
2011-03-01 18:46:16 +00:00
|
|
|
return (bool)$res;
|
2013-04-27 12:02:08 +00:00
|
|
|
} catch ( DBQueryError $dqe ) {
|
2011-03-01 18:46:16 +00:00
|
|
|
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.
|
|
|
|
|
*
|
2014-04-19 11:55:27 +00:00
|
|
|
* @return string
|
* 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
|
|
|
*/
|
|
|
|
|
protected function getTableOptions() {
|
2016-02-17 09:09:32 +00:00
|
|
|
$options = [];
|
* 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
|
|
|
if ( $this->getVar( '_MysqlEngine' ) !== null ) {
|
|
|
|
|
$options[] = "ENGINE=" . $this->getVar( '_MysqlEngine' );
|
|
|
|
|
}
|
|
|
|
|
if ( $this->getVar( '_MysqlCharset' ) !== null ) {
|
|
|
|
|
$options[] = 'DEFAULT CHARSET=' . $this->getVar( '_MysqlCharset' );
|
|
|
|
|
}
|
2013-10-08 11:43:42 +00:00
|
|
|
|
* 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 implode( ', ', $options );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get variables to substitute into tables.sql and the SQL patch files.
|
2011-05-26 20:26:51 +00:00
|
|
|
*
|
|
|
|
|
* @return array
|
* 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 getSchemaVars() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
* 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
|
|
|
'wgDBTableOptions' => $this->getTableOptions(),
|
2011-02-19 08:01:45 +00:00
|
|
|
'wgDBname' => $this->getVar( 'wgDBname' ),
|
|
|
|
|
'wgDBuser' => $this->getVar( 'wgDBuser' ),
|
|
|
|
|
'wgDBpassword' => $this->getVar( 'wgDBpassword' ),
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2010-05-07 12:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-20 11:08:30 +00:00
|
|
|
public function getLocalSettings() {
|
* 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' ) );
|
2023-05-03 17:43:43 +00:00
|
|
|
$useSsl = $this->getVar( 'wgDBssl' ) ? 'true' : '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
|
|
|
$tblOpts = LocalSettingsGenerator::escapePhpString( $this->getTableOptions() );
|
2013-10-08 11:43:42 +00:00
|
|
|
|
|
|
|
|
return "# MySQL specific settings
|
2013-03-07 16:50:43 +00:00
|
|
|
\$wgDBprefix = \"{$prefix}\";
|
2023-05-03 17:43:43 +00:00
|
|
|
\$wgDBssl = {$useSsl};
|
2010-05-07 12:25:01 +00:00
|
|
|
|
|
|
|
|
# MySQL table options to use during installation or update
|
2018-06-01 18:57:36 +00:00
|
|
|
\$wgDBTableOptions = \"{$tblOpts}\";";
|
2010-05-07 12:25:01 +00:00
|
|
|
}
|
|
|
|
|
}
|