Add some functions to DatabasePostgres.php.
<?php
$conf->DBserver = importPost( "DBserver", "localhost" );
+ $conf->DBport = importPost( "DBport", "5432" );
$conf->DBname = importPost( "DBname", "wikidb" );
$conf->DBuser = importPost( "DBuser", "wikiuser" );
$conf->DBpassword = importPost( "DBpassword" );
$conf->DBpassword2 = importPost( "DBpassword2" );
$conf->DBprefix = importPost( "DBprefix" );
$conf->DBschema = importPost( "DBschema", "mediawiki" );
- $conf->DBport = importPost( "DBport", "5432" );
$conf->DBmysql5 = (importPost( "DBmysql5" ) == "true") ? "true" : "false";
$conf->RootUser = importPost( "RootUser", "root" );
$conf->RootPW = importPost( "RootPW", "-" );
# Attempt to connect
echo( "<li>Attempting to connect to database server as $db_user..." );
- $wgDatabase = Database::newFromParams( $wgDBserver, $db_user, $db_pass, '', 1 );
+ $wgDatabase = Database::newFromParams( $wgDBserver, $wgDBport, $db_user, $db_pass, '', 1 );
# Check the connection and respond to errors
if( $wgDatabase->isOpen() ) {
} else /* not mysql */ {
echo( "<li>Attempting to connect to database server as $wgDBuser..." );
- $wgDatabase = $dbc->newFromParams($wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1);
+ $wgDatabase = $dbc->newFromParams($wgDBserver, $wgDBport, $wgDBuser, $wgDBpassword, $wgDBname, 1);
if (!$wgDatabase->isOpen()) {
print " error: " . $wgDatabase->lastError() . "</li>\n";
} else {
# Create user if required
if ( $conf->Root ) {
- $conn = $dbc->newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1 );
+ $conn = $dbc->newFromParams( $wgDBserver, $wgDBport, $wgDBuser, $wgDBpassword, $wgDBname, 1 );
if ( $conn->isOpen() ) {
print "<li>DB user account ok</li>\n";
$conn->close();
# Set up the "regular user" account *if we can, and if we need to*
if( $conf->Root ) {
# See if we need to
- $wgDatabase2 = $dbc->newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1 );
+ $wgDatabase2 = $dbc->newFromParams( $wgDBserver, $wgDBport, $wgDBuser, $wgDBpassword, $wgDBname, 1 );
if( $wgDatabase2->isOpen() ) {
# Nope, just close the test connection and continue
$wgDatabase2->close();
\$wgEmailAuthentication = $eauthent;
\$wgDBserver = \"{$slconf['DBserver']}\";
+\$wgDBport = \"{$slconf['DBport']}\";
\$wgDBname = \"{$slconf['DBname']}\";
\$wgDBuser = \"{$slconf['DBuser']}\";
\$wgDBpassword = \"{$slconf['DBpassword']}\";
protected $mLastQuery = '';
- protected $mServer, $mUser, $mPassword, $mConn = null, $mDBname;
+ protected $mServer, $mPort, $mUser, $mPassword, $mConn = null, $mDBname;
protected $mOut, $mOpened = false;
protected $mFailFunction;
/**@{{
* @param string $server database server host
+ * @param string $port database server port
* @param string $user database user name
* @param string $password database user password
* @param string $dbname database name
* @param $flags
* @param $tablePrefix String: database table prefixes. By default use the prefix gave in LocalSettings.php
*/
- function __construct( $server = false, $user = false, $password = false, $dbName = false,
- $failFunction = false, $flags = 0, $tablePrefix = 'get from global' ) {
+ function __construct( $server = false, $port = false, $user = false, $password = false, $dbName = false,
+ $failFunction = false, $flags = 0, $tablePrefix = 'get from global') {
global $wgOut, $wgDBprefix, $wgCommandLineMode;
# Can't get a reference if it hasn't been set yet
$this->mTablePrefix = $tablePrefix;
}
- if ( $server ) {
- $this->open( $server, $user, $password, $dbName );
+ if ( $server or $port) {
+ $this->open( $server, $port, $user, $password, $dbName );
}
}
* @param failFunction
* @param $flags
*/
- static function newFromParams( $server, $user, $password, $dbName,
+ static function newFromParams( $server, $port, $user, $password, $dbName,
$failFunction = false, $flags = 0 )
{
- return new Database( $server, $user, $password, $dbName, $failFunction, $flags );
+ return new Database( $server, $port, $user, $password, $dbName, $failFunction, $flags );
}
/**
* Usually aborts on failure
* If the failFunction is set to a non-zero integer, returns success
*/
- function open( $server, $user, $password, $dbName ) {
+ function open( $server, $port, $user, $password, $dbName ) {
global $wguname;
# Test for missing mysql.so
*/
protected function replaceVars( $ins ) {
$varnames = array(
- 'wgDBserver', 'wgDBname', 'wgDBintlname', 'wgDBuser',
+ 'wgDBserver', 'wgDBport', 'wgDBname', 'wgDBintlname', 'wgDBuser',
'wgDBpassword', 'wgDBsqluser', 'wgDBsqlpassword',
'wgDBadminuser', 'wgDBadminpassword',
);
Database::Database( $server, $user, $password, $dbName, $failFunction, $flags, $tablePrefix );
}
- /* static */ function newFromParams( $server = false, $user = false, $password = false, $dbName = false,
+ /* static */ function newFromParams( $server = false, $port = false, $user = false, $password = false, $dbName = false,
$failFunction = false, $flags = 0, $tablePrefix = 'get from global' )
{
return new DatabaseOracle( $server, $user, $password, $dbName, $failFunction, $flags, $tablePrefix );
* than MySQL ones, some of them should be moved to parent
* Database class.
*
- * STATUS: Working PG implementation of MediaWiki
- * TODO: Installer support
- *
* @package MediaWiki
*/
*/
require_once( 'Database.php' );
-/**
- *
- * @package MediaWiki
- */
class DatabasePostgres extends Database {
var $mInsertId = NULL;
var $mLastResult = NULL;
- function DatabasePostgres($server = false, $user = false, $password = false, $dbName = false,
+ function DatabasePostgres($server = false, $port = false, $user = false, $password = false, $dbName = false,
$failFunction = false, $flags = 0 )
{
- Database::__construct( $server, $user, $password, $dbName, $failFunction, $flags );
+ Database::__construct( $server, $port, $user, $password, $dbName, $failFunction, $flags );
}
- static function newFromParams( $server = false, $user = false, $password = false, $dbName = false,
+ static function newFromParams( $server = false, $port = false, $user = false, $password = false, $dbName = false,
$failFunction = false, $flags = 0)
{
- return new DatabasePostgres( $server, $user, $password, $dbName, $failFunction, $flags );
+ return new DatabasePostgres( $server, $port, $user, $password, $dbName, $failFunction, $flags );
}
/**
* Usually aborts on failure
* If the failFunction is set to a non-zero integer, returns success
*/
- function open( $server, $user, $password, $dbName ) {
+ function open( $server, $port, $user, $password, $dbName ) {
+
# Test for PostgreSQL support, to avoid suppressed fatal error
if ( !function_exists( 'pg_connect' ) ) {
throw new DBConnectionError( $this, "PostgreSQL functions missing, have you compiled PHP with the --with-pgsql option?\n" );
$this->mPassword = $password;
$this->mDBname = $dbName;
$this->mSchemas = array($wgDBschema,'public');
+ $this->mPort = $port;
$success = false;
if ($server!=false && $server!="") {
$hstring="host=$server ";
}
+ if ($port!=false && $port != '') {
+ $hstring .= "port=$port ";
+ }
@$this->mConn = pg_connect("$hstring dbname=$dbName user=$user password=$password");
if ( $this->mConn == false ) {
$n = pg_num_fields( $res );
for( $i = 0; $i < $n; $i++ ) {
// FIXME
- throw new DBUnexpectedError($this, "Database::fieldInfo() error : mysql_fetch_field() not implemented for postgre" );
+ throw new DBUnexpectedError($this, "Database::fieldInfo() error : mysql_fetch_field() not implemented for postgres" );
$meta = mysql_fetch_field( $res, $i );
if( $field == $meta->name ) {
return $meta;
$searchpath=$this->makeList($schemas,LIST_NAMES);
$this->query("SET search_path = $searchpath");
}
+
+
+ /**
+ * Query whether a given table exists
+ */
+ function tableExists( $table ) {
+ global $wgDBschema;
+ $safetable = preg_replace("/'/", "''", $table);
+ $SQL = "SELECT 1 FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n WHERE c.relnamespace = n.oid "
+ . "AND c.relname = '$safetable' AND n.nspname = '$wgDBschema'";
+ $res = $this->query($SQL);
+ if( $res ) {
+ $this->freeResult( $res );
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ function fieldExists( $table, $field, $fname = 'DatabasePostgres::fieldExists' ) {
+ global $wgDBschema;
+ $safetable = preg_replace("/'/", "''", $table);
+ $safecol = preg_replace("/'/", "''", $field);
+ $SQL = "SELECT 1 FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n, pg_attribute a "
+ . "WHERE c.relnamespace = n.oid AND c.relname = '$safetable' AND n.nspname = '$wgDBschema' "
+ . "AND a.attrelid = c.oid AND a.attname = '$safecol'";
+ $res = $this->query($SQL, $fname);
+ if( $res ) {
+ $this->freeResult( $res );
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+
+
+
}
?>
$wgDBserver = 'localhost';
/** name of the database */
$wgDBname = 'wikidb';
+/** port number for databases that use them (e.g. postgres) */
+$wgDBport = 5432;
/** */
$wgDBconnection = '';
/** Database username */
$wgDBuser = 'wikiuser';
/** Database type
- * "mysql" for working code and "PostgreSQL" for development/broken code
*/
$wgDBtype = "mysql";
/** Search type
if ( !$wgDBservers ) {
$wgDBservers = array(array(
'host' => $wgDBserver,
+ 'port' => $wgDBport,
'user' => $wgDBuser,
'password' => $wgDBpassword,
'dbname' => $wgDBname,
/** */
function convertLinks() {
global $wgDBtype;
- if( $wgDBtype == 'PostgreSQL' ) {
+ if( $wgDBtype == 'Postgres' ) {
print "Links table already ok on PostgreSQL.\n";
return;
}
print "Converting links table to ID-ID...\n";
- global $wgLang, $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname;
+ global $wgLang, $wgDBserver, $wgDBport, $wgDBadminuser, $wgDBadminpassword, $wgDBname;
global $noKeys, $logPerformance, $fh;
$numRows = $tuplesAdded = $numBadLinks = $curRowsRead = 0; #counters etc
#--------------------------------------------------------------------
if ( $overwriteLinksTable ) {
- $dbConn = Database::newFromParams( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname );
+ $dbConn = Database::newFromParams( $wgDBserver, $wgDBport, $wgDBadminuser, $wgDBadminpassword, $wgDBname );
if (!($dbConn->isOpen())) {
print "Opening connection to database failed.\n";
return;
#--------------------------------------------------------------------
function createTempTable() {
- global $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname;
+ global $wgDBserver, $wgDBport, $wgDBadminuser, $wgDBadminpassword, $wgDBname;
global $noKeys;
- $dbConn = Database::newFromParams( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname );
+ $dbConn = Database::newFromParams( $wgDBserver, $wgDBport, $wgDBadminuser, $wgDBadminpassword, $wgDBname );
if (!($dbConn->isOpen())) {
print "Opening connection to database failed.\n";
require_once( "rebuildtextindex.inc" );
require_once( "rebuildrecentchanges.inc" );
-$database = Database::newFromParams( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname );
+$database = Database::newFromParams( $wgDBserver, $wgDBport, wgDBadminuser, $wgDBadminpassword, $wgDBname );
print "** Rebuilding fulltext search index (if you abort this will break searching; run this script again to fix):\n";
dropTextIndex( $database );
require_once( "rebuildtextindex.inc" );
$wgTitle = Title::newFromText( "Rebuild text index script" );
-$database = Database::newFromParams( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname );
+$database = Database::newFromParams( $wgDBserver, $wgDBport, $wgDBadminuser, $wgDBadminpassword, $wgDBname );
dropTextIndex( $database );
rebuildTextIndex( $database );
UNIQUE KEY ( qci_type )
-) TYPE=InnoDB;
\ No newline at end of file
+) TYPE=InnoDB;
# Attempt to connect to the database as a privileged user
# This will vomit up an error if there are permissions problems
-$wgDatabase = $dbc->newFromParams( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname, 1 );
+$wgDatabase = $dbc->newFromParams( $wgDBserver, $wgDBport, $wgDBadminuser, $wgDBadminpassword, $wgDBname, 1 );
if( !$wgDatabase->isOpen() ) {
# Appears to have failed
$testOptions = array(
'mysql3' => array(
'server' => null,
+ 'port' => null,
'user' => null,
'password' => null,
'database' => null ),
'mysql4' => array(
'server' => null,
+ 'port' => null,
'user' => null,
'password' => null,
'database' => null ),
'postgres' => array(
'server' => null,
+ 'port' => null,
'user' => null,
'password' => null,
'database' => null ),
$testOptions = array(
'mysql4' => array(
- 'server' => null,
- 'user' => null,
+ 'server' => null,
+ 'port' => null,
+ 'user' => null,
'password' => null,
'database' => null ),
'postgres' => array(
- 'server' => null,
- 'user' => null,
+ 'server' => null,
+ 'port' => null
+ 'user' => null,
'password' => null,
'database' => null ),
);