Paladox has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/248614

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

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.

Backported to MediaWiki 1.23 from patch 
Id364306d883e0d494b948854e05f3f79ba7dd6d2

Author of original patch Skizzerz

Bug: T66043
Change-Id: I842dd8e00637cc818b4e29d5bdc2930d8c7ee223
---
M includes/db/DatabaseMssql.php
M includes/installer/Installer.php
M includes/installer/MssqlInstaller.php
M includes/installer/PostgresInstaller.php
M maintenance/install.php
5 files changed, 39 insertions(+), 25 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/14/248614/1

diff --git a/includes/db/DatabaseMssql.php b/includes/db/DatabaseMssql.php
index 7b578a2..8c2a8c4 100644
--- a/includes/db/DatabaseMssql.php
+++ b/includes/db/DatabaseMssql.php
@@ -1004,6 +1004,11 @@
                        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'" 
);
@@ -1344,7 +1349,7 @@
                        // 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 56db77e..c91e370 100644
--- a/includes/installer/Installer.php
+++ b/includes/installer/Installer.php
@@ -367,26 +367,15 @@
                        $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 d6c84eb..f3f8c07 100644
--- a/includes/installer/MssqlInstaller.php
+++ b/includes/installer/MssqlInstaller.php
@@ -207,6 +207,7 @@
                                'password' => $password,
                                'dbname' => false,
                                'flags' => 0,
+                               'schema' => $this->getVar( 'wgDBmwschema' ),
                                'tablePrefix' => $this->getVar( 'wgDBprefix' ) 
) );
                        $db->prepareStatements( false );
                        $db->scrollableCursor( false );
@@ -612,6 +613,14 @@
                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 780431a..6cfb63e 100644
--- a/includes/installer/PostgresInstaller.php
+++ b/includes/installer/PostgresInstaller.php
@@ -152,16 +152,18 @@
         * @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 ) {
@@ -231,7 +233,8 @@
                                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() ) {
@@ -261,11 +264,11 @@
                $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,
@@ -623,6 +626,14 @@
                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 44c117e..71a733e 100644
--- a/maintenance/install.php
+++ b/maintenance/install.php
@@ -64,7 +64,7 @@
                $this->addOption( 'dbpass', 'The pasword for the DB user for 
normal operations', false, true );
                $this->addOption( 'dbpassfile', 'An alternative way to provide 
dbpass option, as the contents of this file', false, true );
                $this->addOption( 'confpath', "Path to write LocalSettings.php 
to, default $IP", false, true );
-               /* $this->addOption( 'dbschema', 'The schema for the MediaWiki 
DB in pg (mediawiki)', false, true ); */
+               $this->addOption( 'dbschema', 'The schema for the MediaWiki DB 
in PostgreSQL/Microsoft SQL Server (mediawiki)', false, true );
                /* $this->addOption( 'namespace', 'The project namespace (same 
as the name)', false, true ); */
                $this->addOption( 'env-checks', "Run environment checks only, 
don't change anything" );
        }

-- 
To view, visit https://gerrit.wikimedia.org/r/248614
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I842dd8e00637cc818b4e29d5bdc2930d8c7ee223
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: REL1_23
Gerrit-Owner: Paladox <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to