http://www.mediawiki.org/wiki/Special:Code/MediaWiki/89822
Revision: 89822
Author: tstarling
Date: 2011-06-10 11:55:23 +0000 (Fri, 10 Jun 2011)
Log Message:
-----------
Revert r89807, i.e. reapply r88929, since it has some useful changes and is the
required base for backporting r89821.
Modified Paths:
--------------
branches/REL1_17/phase3/includes/installer/DatabaseInstaller.php
branches/REL1_17/phase3/includes/installer/Installer.i18n.php
branches/REL1_17/phase3/includes/installer/MysqlInstaller.php
branches/REL1_17/phase3/includes/installer/OracleInstaller.php
branches/REL1_17/phase3/includes/installer/PostgresInstaller.php
branches/REL1_17/phase3/includes/installer/PostgresUpdater.php
branches/REL1_17/phase3/includes/installer/SqliteInstaller.php
Modified: branches/REL1_17/phase3/includes/installer/DatabaseInstaller.php
===================================================================
--- branches/REL1_17/phase3/includes/installer/DatabaseInstaller.php
2011-06-10 11:32:57 UTC (rev 89821)
+++ branches/REL1_17/phase3/includes/installer/DatabaseInstaller.php
2011-06-10 11:55:23 UTC (rev 89822)
@@ -102,7 +102,7 @@
*
* @return Status
*/
- public abstract function openConnection();
+ public abstract function openConnection( $dbName = null );
/**
* Create the database and return a Status object indicating success or
@@ -121,11 +121,14 @@
*
* @return Status
*/
- public function getConnection() {
- if ( $this->db ) {
+ public function getConnection( $dbName = null ) {
+ if ( isset($this->db) && $this->db ) { /* Weirdly get E_STRICT
+
* errors without the
+
* isset */
return Status::newGood( $this->db );
}
- $status = $this->openConnection();
+
+ $status = $this->openConnection( $dbName );
if ( $status->isOK() ) {
$this->db = $status->value;
// Enable autocommit
Modified: branches/REL1_17/phase3/includes/installer/Installer.i18n.php
===================================================================
--- branches/REL1_17/phase3/includes/installer/Installer.i18n.php
2011-06-10 11:32:57 UTC (rev 89821)
+++ branches/REL1_17/phase3/includes/installer/Installer.i18n.php
2011-06-10 11:55:23 UTC (rev 89822)
@@ -253,7 +253,7 @@
Use only ASCII letters (a-z, A-Z), numbers (0-9), underscores (_) and hyphens
(-).',
'config-connection-error' => '$1.
-Check the host, username and password below and try again.',
+Check the host, username and password and try again.',
'config-invalid-schema' => 'Invalid schema for MediaWiki "$1".
Use only ASCII letters (a-z, A-Z), numbers (0-9) and underscores (_).',
'config-db-sys-create-oracle' => 'Installer only supports using a
SYSDBA account for creating a new account.',
Modified: branches/REL1_17/phase3/includes/installer/MysqlInstaller.php
===================================================================
--- branches/REL1_17/phase3/includes/installer/MysqlInstaller.php
2011-06-10 11:32:57 UTC (rev 89821)
+++ branches/REL1_17/phase3/includes/installer/MysqlInstaller.php
2011-06-10 11:55:23 UTC (rev 89822)
@@ -111,7 +111,7 @@
return $status;
}
- public function openConnection() {
+ public function openConnection( $dbName = null ) {
$status = Status::newGood();
try {
$db = new DatabaseMysql(
Modified: branches/REL1_17/phase3/includes/installer/OracleInstaller.php
===================================================================
--- branches/REL1_17/phase3/includes/installer/OracleInstaller.php
2011-06-10 11:32:57 UTC (rev 89821)
+++ branches/REL1_17/phase3/includes/installer/OracleInstaller.php
2011-06-10 11:55:23 UTC (rev 89822)
@@ -127,7 +127,7 @@
return $status;
}
- public function openConnection() {
+ public function openConnection( $dbName = null ) {
$status = Status::newGood();
try {
$db = new DatabaseOracle(
Modified: branches/REL1_17/phase3/includes/installer/PostgresInstaller.php
===================================================================
--- branches/REL1_17/phase3/includes/installer/PostgresInstaller.php
2011-06-10 11:32:57 UTC (rev 89821)
+++ branches/REL1_17/phase3/includes/installer/PostgresInstaller.php
2011-06-10 11:55:23 UTC (rev 89822)
@@ -101,22 +101,31 @@
return $status;
}
- public function openConnection() {
+ public function openConnection( $dbName = null ) {
$status = Status::newGood();
try {
if ( $this->useAdmin ) {
+ if ( $dbName === null ) $dbName = 'postgres';
+
$db = new DatabasePostgres(
$this->getVar( 'wgDBserver' ),
$this->getVar( '_InstallUser' ),
$this->getVar( '_InstallPassword' ),
- 'postgres' );
+ $dbName );
} else {
+ if ( $dbName === null ) $dbName =
$this->getVar( 'wgDBname' );
+
$db = new DatabasePostgres(
$this->getVar( 'wgDBserver' ),
$this->getVar( 'wgDBuser' ),
$this->getVar( 'wgDBpassword' ),
- $this->getVar( 'wgDBname' ) );
+ $dbName );
}
+
+ if( $db === null ) throw new DBConnectionError("Unknown
problem while connecting.");
+ $safeschema = $db->addIdentifierQuotes( $this->getVar(
'wgDBmwschema' ) );
+ if( $db->schemaExists( $this->getVar( 'wgDBmwschema' )
) ) $db->query( "SET search_path = $safeschema" );
+
$status->value = $db;
} catch ( DBConnectionError $e ) {
$status->fatal( 'config-connection-error',
$e->getMessage() );
@@ -134,15 +143,15 @@
$superuser = $this->getVar( '_InstallUser' );
- $rights = $conn->selectField( 'pg_catalog.pg_user',
- 'CASE WHEN usesuper IS TRUE THEN
- CASE WHEN usecreatedb IS TRUE THEN 3 ELSE 1 END
- ELSE CASE WHEN usecreatedb IS TRUE THEN 2 ELSE
0 END
- END AS rights',
- array( 'usename' => $superuser ), __METHOD__
+ $rights = $conn->selectField( 'pg_catalog.pg_roles',
+ 'CASE WHEN rolsuper then 1
+ WHEN rolcreatedb then 2
+ ELSE 3
+ END as rights',
+ array( 'rolname' => $superuser ), __METHOD__
);
- if( !$rights || ( $rights != 1 && $rights != 3 ) ) {
+ if( !$rights || $rights == 3 ) {
return false;
}
@@ -226,11 +235,12 @@
$rows = $conn->numRows( $conn->query( $SQL ) );
$safedb = $conn->addIdentifierQuotes( $dbName );
if( !$rows ) {
- $conn->query( "CREATE DATABASE $safedb OWNER
$safeuser", __METHOD__ );
+ $conn->query( "CREATE DATABASE $safedb", __METHOD__ );
+ $conn->query( "GRANT ALL ON DATABASE $safedb to
$safeuser", __METHOD__ );
} else {
- $conn->query( "ALTER DATABASE $safedb OWNER TO
$safeuser", __METHOD__ );
+ $conn->query( "GRANT ALL ON DATABASE $safedb TO
$safeuser", __METHOD__ );
}
-
+
// Now that we've established the real database exists, connect
to it
// Because we do not want the same connection, forcibly expire
the existing conn
$this->db = null;
@@ -287,17 +297,18 @@
$safeschema = $this->db->addIdentifierQuotes( $schema );
$rows = $this->db->numRows(
- $this->db->query( "SELECT 1 FROM pg_catalog.pg_shadow
WHERE usename = $safeusercheck" )
+ $this->db->query( "SELECT 1 FROM pg_catalog.pg_roles
WHERE rolname = $safeusercheck" )
);
if ( $rows < 1 ) {
- $res = $this->db->query( "CREATE USER $safeuser
NOCREATEDB PASSWORD $safepass", __METHOD__ );
+ $res = $this->db->query( "CREATE ROLE $safeuser
NOCREATEDB LOGIN PASSWORD $safepass", __METHOD__ );
if ( $res !== true && !( $res instanceOf ResultWrapper
) ) {
$status->fatal( 'config-install-user-failed',
$this->getVar( 'wgDBuser' ), $res );
}
if( $status->isOK() ) {
- $this->db->query("ALTER USER $safeuser SET
search_path = $safeschema");
+ $this->db->query("ALTER ROLE $safeuser LOGIN");
}
}
+ $this->db->query("ALTER ROLE $safeuser SET search_path =
$safeschema, public");
return $status;
}
@@ -337,12 +348,11 @@
$this->db->begin( __METHOD__ );
+ // getConnection() should have already selected the schema if
it exists
if( !$this->db->schemaExists( $schema ) ) {
$status->error( 'config-install-pg-schema-not-exist' );
return $status;
}
- $safeschema = $this->db->addIdentifierQuotes( $schema );
- $this->db->query( "SET search_path = $safeschema" );
$error = $this->db->sourceFile( $this->db->getSchema() );
if( $error !== true ) {
$this->db->reportQueryError( $error, 0, '', __METHOD__
);
@@ -359,12 +369,18 @@
}
public function setupPLpgSQL() {
+ $this->db = null;
$this->useAdmin = true;
- $status = $this->getConnection();
+ $dbName = $this->getVar( 'wgDBname' );
+ $status = $this->getConnection( $dbName );
if ( !$status->isOK() ) {
return $status;
}
+ $this->db = $status->value;
+ /* Admin user has to be connected to the db it just
+ created to satisfy ownership requirements for
+ "CREATE LANGAUGE" */
$rows = $this->db->numRows(
$this->db->query( "SELECT 1 FROM pg_catalog.pg_language
WHERE lanname = 'plpgsql'" )
);
@@ -373,7 +389,6 @@
$SQL = "SELECT 1 FROM pg_catalog.pg_class c JOIN
pg_catalog.pg_namespace n ON (n.oid = c.relnamespace) ".
"WHERE relname = 'pg_pltemplate' AND
nspname='pg_catalog'";
$rows = $this->db->numRows( $this->db->query( $SQL ) );
- $dbName = $this->getVar( 'wgDBname' );
if ( $rows >= 1 ) {
$result = $this->db->query( 'CREATE LANGUAGE
plpgsql' );
if ( !$result ) {
Modified: branches/REL1_17/phase3/includes/installer/PostgresUpdater.php
===================================================================
--- branches/REL1_17/phase3/includes/installer/PostgresUpdater.php
2011-06-10 11:32:57 UTC (rev 89821)
+++ branches/REL1_17/phase3/includes/installer/PostgresUpdater.php
2011-06-10 11:55:23 UTC (rev 89822)
@@ -79,7 +79,6 @@
array( 'addPgField', 'logging', 'log_id',
"INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('logging_log_id_seq')" ),
array( 'addPgField', 'logging', 'log_params',
'TEXT' ),
array( 'addPgField', 'mwuser', 'user_editcount',
'INTEGER' ),
- array( 'addPgField', 'mwuser', 'user_hidden',
'SMALLINT NOT NULL DEFAULT 0' ),
array( 'addPgField', 'mwuser',
'user_newpass_time', 'TIMESTAMPTZ' ),
array( 'addPgField', 'oldimage', 'oi_deleted',
'SMALLINT NOT NULL DEFAULT 0' ),
array( 'addPgField', 'oldimage', 'oi_major_mime',
"TEXT NOT NULL DEFAULT 'unknown'" ),
Modified: branches/REL1_17/phase3/includes/installer/SqliteInstaller.php
===================================================================
--- branches/REL1_17/phase3/includes/installer/SqliteInstaller.php
2011-06-10 11:32:57 UTC (rev 89821)
+++ branches/REL1_17/phase3/includes/installer/SqliteInstaller.php
2011-06-10 11:55:23 UTC (rev 89822)
@@ -103,7 +103,7 @@
return Status::newGood();
}
- public function openConnection() {
+ public function openConnection( $dbName = null ) {
global $wgSQLiteDataDir;
$status = Status::newGood();
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs