## Possible connect as a superuser
// Changed !mysql to postgres check since it seems to only apply to postgres
if( $useRoot && $conf->DBtype == 'postgres' ) {
- $wgDBsuperuser = $conf->RootUser;
echo( "<li>Attempting to connect to database \"postgres\" as superuser \"" .
- htmlspecialchars( $wgDBsuperuser ) . "\"..." );
- $wgDatabase = $dbc->newFromParams($wgDBserver, $wgDBsuperuser, $conf->RootPW, "postgres", 1);
+ htmlspecialchars( $conf->RootUser ) . "\"..." );
+ $wgDatabase = $dbc->newFromParams($wgDBserver, $conf->RootUser, $conf->RootPW, "postgres", 1);
if (!$wgDatabase->isOpen()) {
print " error: " . htmlspecialchars( $wgDatabase->lastError() ) . "</li>\n";
$errs["DBserver"] = "Could not connect to database as superuser";
$errs["RootPW"] = "and password";
continue;
}
- $wgDatabase->initial_setup($conf->RootPW, 'postgres');
+ $wgDatabase->initial_setup($conf->RootUser, $conf->RootPW, 'postgres');
}
echo( "<li>Attempting to connect to database \"" . htmlspecialchars( $wgDBname ) .
"\" as \"" . htmlspecialchars( $wgDBuser ) . "\"..." );
}
- function initial_setup($password, $dbName) {
+ function initial_setup($superuser, $password, $dbName) {
// If this is the initial connection, setup the schema stuff and possibly create the user
- global $wgDBname, $wgDBuser, $wgDBpassword, $wgDBsuperuser, $wgDBmwschema, $wgDBts2schema;
+ global $wgDBname, $wgDBuser, $wgDBpassword, $superuser, $wgDBmwschema, $wgDBts2schema;
print "<li>Checking the version of Postgres...";
$version = $this->getServerVersion();
$safeuser = $this->quote_ident($wgDBuser);
// Are we connecting as a superuser for the first time?
- if ($wgDBsuperuser) {
+ if ($superuser) {
// Are we really a superuser? Check out our rights
$SQL = "SELECT
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
- FROM pg_catalog.pg_user WHERE usename = " . $this->addQuotes($wgDBsuperuser);
+ FROM pg_catalog.pg_user WHERE usename = " . $this->addQuotes($superuser);
$rows = $this->numRows($res = $this->doQuery($SQL));
if (!$rows) {
- print "<li>ERROR: Could not read permissions for user \"" . htmlspecialchars( $wgDBsuperuser ) . "\"</li>\n";
+ print "<li>ERROR: Could not read permissions for user \"" . htmlspecialchars( $superuser ) . "\"</li>\n";
dieout('</ul>');
}
$perms = pg_fetch_result($res, 0, 0);
}
else {
if ($perms != 1 and $perms != 3) {
- print "<li>ERROR: the user \"" . htmlspecialchars( $wgDBsuperuser ) . "\" cannot create other users. ";
+ print "<li>ERROR: the user \"" . htmlspecialchars( $superuser ) . "\" cannot create other users. ";
print 'Please use a different Postgres user.</li>';
dieout('</ul>');
}
}
else {
if ($perms < 1) {
- print "<li>ERROR: the user \"" . htmlspecialchars( $wgDBsuperuser ) . "\" cannot create databases. ";
+ print "<li>ERROR: the user \"" . htmlspecialchars( $superuser ) . "\" cannot create databases. ";
print 'Please use a different Postgres user.</li>';
dieout('</ul>');
}
// Reconnect to check out tsearch2 rights for this user
print "<li>Connecting to \"" . htmlspecialchars( $wgDBname ) . "\" as superuser \"" .
- htmlspecialchars( $wgDBsuperuser ) . "\" to check rights...";
+ htmlspecialchars( $superuser ) . "\" to check rights...";
$connectVars = array();
if ($this->mServer!=false && $this->mServer!="") {
$connectVars['port'] = $this->mPort;
}
$connectVars['dbname'] = $wgDBname;
- $connectVars['user'] = $wgDBsuperuser;
+ $connectVars['user'] = $superuser;
$connectVars['password'] = $password;
@$this->mConn = pg_connect( $this->makeConnectionString( $connectVars ) );
// Install plpgsql if needed
$this->setup_plpgsql();
- $wgDBsuperuser = '';
+ $superuser = '';
return true; // Reconnect as regular user
} // end superuser