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
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'" );
// 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 );
}
}
$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 :(
'password' => $password,
'dbname' => false,
'flags' => 0,
+ 'schema' => $this->getVar( 'wgDBmwschema' ),
'tablePrefix' => $this->getVar( 'wgDBprefix' ) ) );
$db->prepareStatements( false );
$db->scrollableCursor( false );
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
* @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() );
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() ) {
$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,
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"
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" );