From: Skizzerz Date: Fri, 27 Jun 2014 01:17:05 +0000 (-0500) Subject: Set the default database schema to "mediawiki" so as not to break the CLI installer. X-Git-Tag: 1.31.0-rc.0~15042 X-Git-Url: http://git.cyclocoop.org/%22.%24h.%22?a=commitdiff_plain;h=30a82aae9cf7e5536eef761637a1277b7c18017e;p=lhc%2Fweb%2Fwiklou.git 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 --- diff --git a/includes/db/DatabaseMssql.php b/includes/db/DatabaseMssql.php index a03dd75a9b..be01f1a0ec 100644 --- a/includes/db/DatabaseMssql.php +++ b/includes/db/DatabaseMssql.php @@ -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 ); } } diff --git a/includes/installer/Installer.php b/includes/installer/Installer.php index 540b647dac..481de87d38 100644 --- a/includes/installer/Installer.php +++ b/includes/installer/Installer.php @@ -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 :( diff --git a/includes/installer/MssqlInstaller.php b/includes/installer/MssqlInstaller.php index 51db148a1e..83681b6b29 100644 --- a/includes/installer/MssqlInstaller.php +++ b/includes/installer/MssqlInstaller.php @@ -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 diff --git a/includes/installer/PostgresInstaller.php b/includes/installer/PostgresInstaller.php index 9e25f47e8e..89a697897a 100644 --- a/includes/installer/PostgresInstaller.php +++ b/includes/installer/PostgresInstaller.php @@ -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" diff --git a/maintenance/install.php b/maintenance/install.php index 5a3e00cf8c..fbc5d9815f 100644 --- a/maintenance/install.php +++ b/maintenance/install.php @@ -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" );