Set the default database schema to "mediawiki" so as not to break the CLI installer.

Due to changes made to support Microsoft SQL Server, $wgDBmwschema changed its default from
"mediawiki" to null in DefaultSettings.php, as anything else horribly broke every DBMS that did
not use schemas (such as MySQL and SQLite). This change makes it so that the default value can
be properly overridden again by PostgreSQL and Microsoft SQL Server, and also enables the
--dbschema flag to the CLI installer.

Bug: 64043
Change-Id: Id364306d883e0d494b948854e05f3f79ba7dd6d2
This commit is contained in:
Skizzerz 2014-06-26 20:17:05 -05:00 committed by Legoktm
parent 1e10fcca50
commit 30a82aae9c
5 changed files with 39 additions and 26 deletions

View file

@ -1004,6 +1004,11 @@ class DatabaseMssql extends DatabaseBase {
return false;
}
if ( $schema === false ) {
global $wgDBmwschema;
$schema = $wgDBmwschema;
}
$res = $this->query( "SELECT 1 FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
AND TABLE_SCHEMA = '$schema' AND TABLE_NAME = '$table'" );
@ -1341,7 +1346,7 @@ class DatabaseMssql extends DatabaseBase {
// Used internally, we want the schema split off from the table name and returned
// as a list with 3 elements (database, schema, table)
$table = explode( '.', $table );
if ( count( $table ) == 2 ) {
while ( count( $table ) < 3 ) {
array_unshift( $table, false );
}
}

View file

@ -380,26 +380,15 @@ abstract class Installer {
$this->settings[$var] = $GLOBALS[$var];
}
$compiledDBs = array();
$this->compiledDBs = array();
foreach ( self::getDBTypes() as $type ) {
$installer = $this->getDBInstaller( $type );
if ( !$installer->isCompiled() ) {
continue;
}
$compiledDBs[] = $type;
$defaults = $installer->getGlobalDefaults();
foreach ( $installer->getGlobalNames() as $var ) {
if ( isset( $defaults[$var] ) ) {
$this->settings[$var] = $defaults[$var];
} else {
$this->settings[$var] = $GLOBALS[$var];
}
}
$this->compiledDBs[] = $type;
}
$this->compiledDBs = $compiledDBs;
$this->parserTitle = Title::newFromText( 'Installer' );
$this->parserOptions = new ParserOptions; // language will be wrong :(

View file

@ -218,6 +218,7 @@ class MssqlInstaller extends DatabaseInstaller {
'password' => $password,
'dbname' => false,
'flags' => 0,
'schema' => $this->getVar( 'wgDBmwschema' ),
'tablePrefix' => $this->getVar( 'wgDBprefix' ) ) );
$db->prepareStatements( false );
$db->scrollableCursor( false );
@ -648,6 +649,14 @@ class MssqlInstaller extends DatabaseInstaller {
return $status;
}
public function getGlobalDefaults() {
// The default $wgDBmwschema is null, which breaks Postgres and other DBMSes that require
// the use of a schema, so we need to set it here
return array(
'wgDBmwschema' => 'mediawiki',
);
}
/**
* Try to see if the login exists
* @param string $user Username to check

View file

@ -152,17 +152,18 @@ class PostgresInstaller extends DatabaseInstaller {
* @param string $user User name
* @param string $password Password
* @param string $dbName Database name
* @param string $schema Database schema
* @return Status
*/
protected function openConnectionWithParams( $user, $password, $dbName ) {
protected function openConnectionWithParams( $user, $password, $dbName, $schema ) {
$status = Status::newGood();
try {
$db = new DatabasePostgres(
$this->getVar( 'wgDBserver' ),
$user,
$password,
$dbName
);
$db = Database::factory( 'postgres', array(
'host' => $this->getVar( 'wgDBserver' ),
'user' => $user,
'password' => $password,
'dbname' => $dbName,
'schema' => $schema ) );
$status->value = $db;
} catch ( DBConnectionError $e ) {
$status->fatal( 'config-connection-error', $e->getMessage() );
@ -230,7 +231,8 @@ class PostgresInstaller extends DatabaseInstaller {
return $this->openConnectionWithParams(
$this->getVar( '_InstallUser' ),
$this->getVar( '_InstallPassword' ),
$this->getVar( 'wgDBname' ) );
$this->getVar( 'wgDBname' ),
$this->getVar( 'wgDBmwschema' ) );
case 'create-tables':
$status = $this->openPgConnection( 'create-schema' );
if ( $status->isOK() ) {
@ -260,11 +262,11 @@ class PostgresInstaller extends DatabaseInstaller {
$status = Status::newGood();
foreach ( $dbs as $db ) {
try {
$conn = new DatabasePostgres(
$this->getVar( 'wgDBserver' ),
$conn = $this->openConnectionWithParams(
$user,
$password,
$db );
$db,
$this->getVar( 'wgDBmwschema' ) );
} catch ( DBConnectionError $error ) {
$conn = false;
$status->fatal( 'config-pg-test-error', $db,
@ -622,6 +624,14 @@ class PostgresInstaller extends DatabaseInstaller {
return $status;
}
public function getGlobalDefaults() {
// The default $wgDBmwschema is null, which breaks Postgres and other DBMSes that require
// the use of a schema, so we need to set it here
return array(
'wgDBmwschema' => 'mediawiki',
);
}
public function setupPLpgSQL() {
// Connect as the install user, since it owns the database and so is
// the user that needs to run "CREATE LANGAUGE"

View file

@ -85,8 +85,8 @@ class CommandLineInstaller extends Maintenance {
true
);
$this->addOption( 'confpath', "Path to write LocalSettings.php to ($IP)", false, true );
$this->addOption( 'dbschema', 'The schema for the MediaWiki DB in PostgreSQL/Microsoft SQL Server (mediawiki)', false, true );
/*
$this->addOption( 'dbschema', 'The schema for the MediaWiki DB in pg (mediawiki)', false, true );
$this->addOption( 'namespace', 'The project namespace (same as the "name" argument)', false, true );
*/
$this->addOption( 'env-checks', "Run environment checks only, don't change anything" );