Index: trunk/phase3/maintenance/update.php |
— | — | @@ -32,7 +32,7 @@ |
33 | 33 | |
34 | 34 | # Attempt to connect to the database as a privileged user |
35 | 35 | # This will vomit up an error if there are permissions problems |
36 | | -$wgDatabase = $dbc->newFromParams( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname, 1 ); |
| 36 | +$wgDatabase = $dbc->newFromParams( $wgDBserver, $wgDBport, $wgDBadminuser, $wgDBadminpassword, $wgDBname, 1 ); |
37 | 37 | |
38 | 38 | if( !$wgDatabase->isOpen() ) { |
39 | 39 | # Appears to have failed |
Index: trunk/phase3/maintenance/rebuildall.php |
— | — | @@ -15,7 +15,7 @@ |
16 | 16 | require_once( "rebuildtextindex.inc" ); |
17 | 17 | require_once( "rebuildrecentchanges.inc" ); |
18 | 18 | |
19 | | -$database = Database::newFromParams( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname ); |
| 19 | +$database = Database::newFromParams( $wgDBserver, $wgDBport, wgDBadminuser, $wgDBadminpassword, $wgDBname ); |
20 | 20 | |
21 | 21 | print "** Rebuilding fulltext search index (if you abort this will break searching; run this script again to fix):\n"; |
22 | 22 | dropTextIndex( $database ); |
Index: trunk/phase3/maintenance/rebuildtextindex.php |
— | — | @@ -13,7 +13,7 @@ |
14 | 14 | require_once( "rebuildtextindex.inc" ); |
15 | 15 | $wgTitle = Title::newFromText( "Rebuild text index script" ); |
16 | 16 | |
17 | | -$database = Database::newFromParams( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname ); |
| 17 | +$database = Database::newFromParams( $wgDBserver, $wgDBport, $wgDBadminuser, $wgDBadminpassword, $wgDBname ); |
18 | 18 | |
19 | 19 | dropTextIndex( $database ); |
20 | 20 | rebuildTextIndex( $database ); |
Index: trunk/phase3/maintenance/convertLinks.inc |
— | — | @@ -8,14 +8,14 @@ |
9 | 9 | /** */ |
10 | 10 | function convertLinks() { |
11 | 11 | global $wgDBtype; |
12 | | - if( $wgDBtype == 'PostgreSQL' ) { |
| 12 | + if( $wgDBtype == 'Postgres' ) { |
13 | 13 | print "Links table already ok on PostgreSQL.\n"; |
14 | 14 | return; |
15 | 15 | } |
16 | 16 | |
17 | 17 | print "Converting links table to ID-ID...\n"; |
18 | 18 | |
19 | | - global $wgLang, $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname; |
| 19 | + global $wgLang, $wgDBserver, $wgDBport, $wgDBadminuser, $wgDBadminpassword, $wgDBname; |
20 | 20 | global $noKeys, $logPerformance, $fh; |
21 | 21 | |
22 | 22 | $numRows = $tuplesAdded = $numBadLinks = $curRowsRead = 0; #counters etc |
— | — | @@ -147,7 +147,7 @@ |
148 | 148 | #-------------------------------------------------------------------- |
149 | 149 | |
150 | 150 | if ( $overwriteLinksTable ) { |
151 | | - $dbConn = Database::newFromParams( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname ); |
| 151 | + $dbConn = Database::newFromParams( $wgDBserver, $wgDBport, $wgDBadminuser, $wgDBadminpassword, $wgDBname ); |
152 | 152 | if (!($dbConn->isOpen())) { |
153 | 153 | print "Opening connection to database failed.\n"; |
154 | 154 | return; |
— | — | @@ -174,9 +174,9 @@ |
175 | 175 | #-------------------------------------------------------------------- |
176 | 176 | |
177 | 177 | function createTempTable() { |
178 | | - global $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname; |
| 178 | + global $wgDBserver, $wgDBport, $wgDBadminuser, $wgDBadminpassword, $wgDBname; |
179 | 179 | global $noKeys; |
180 | | - $dbConn = Database::newFromParams( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname ); |
| 180 | + $dbConn = Database::newFromParams( $wgDBserver, $wgDBport, $wgDBadminuser, $wgDBadminpassword, $wgDBname ); |
181 | 181 | |
182 | 182 | if (!($dbConn->isOpen())) { |
183 | 183 | print "Opening connection to database failed.\n"; |
Index: trunk/phase3/maintenance/tables.sql |
— | — | @@ -995,4 +995,4 @@ |
996 | 996 | |
997 | 997 | UNIQUE KEY ( qci_type ) |
998 | 998 | |
999 | | -) TYPE=InnoDB; |
\ No newline at end of file |
| 999 | +) TYPE=InnoDB; |
Index: trunk/phase3/tests/LocalTestSettings.sample |
— | — | @@ -12,16 +12,19 @@ |
13 | 13 | $testOptions = array( |
14 | 14 | 'mysql3' => array( |
15 | 15 | 'server' => null, |
| 16 | + 'port' => null, |
16 | 17 | 'user' => null, |
17 | 18 | 'password' => null, |
18 | 19 | 'database' => null ), |
19 | 20 | 'mysql4' => array( |
20 | 21 | 'server' => null, |
| 22 | + 'port' => null, |
21 | 23 | 'user' => null, |
22 | 24 | 'password' => null, |
23 | 25 | 'database' => null ), |
24 | 26 | 'postgres' => array( |
25 | 27 | 'server' => null, |
| 28 | + 'port' => null, |
26 | 29 | 'user' => null, |
27 | 30 | 'password' => null, |
28 | 31 | 'database' => null ), |
Index: trunk/phase3/tests/RunTests.php |
— | — | @@ -14,13 +14,15 @@ |
15 | 15 | |
16 | 16 | $testOptions = array( |
17 | 17 | 'mysql4' => array( |
18 | | - 'server' => null, |
19 | | - 'user' => null, |
| 18 | + 'server' => null, |
| 19 | + 'port' => null, |
| 20 | + 'user' => null, |
20 | 21 | 'password' => null, |
21 | 22 | 'database' => null ), |
22 | 23 | 'postgres' => array( |
23 | | - 'server' => null, |
24 | | - 'user' => null, |
| 24 | + 'server' => null, |
| 25 | + 'port' => null |
| 26 | + 'user' => null, |
25 | 27 | 'password' => null, |
26 | 28 | 'database' => null ), |
27 | 29 | ); |
Index: trunk/phase3/config/index.php |
— | — | @@ -476,13 +476,13 @@ |
477 | 477 | |
478 | 478 | <?php |
479 | 479 | $conf->DBserver = importPost( "DBserver", "localhost" ); |
| 480 | + $conf->DBport = importPost( "DBport", "5432" ); |
480 | 481 | $conf->DBname = importPost( "DBname", "wikidb" ); |
481 | 482 | $conf->DBuser = importPost( "DBuser", "wikiuser" ); |
482 | 483 | $conf->DBpassword = importPost( "DBpassword" ); |
483 | 484 | $conf->DBpassword2 = importPost( "DBpassword2" ); |
484 | 485 | $conf->DBprefix = importPost( "DBprefix" ); |
485 | 486 | $conf->DBschema = importPost( "DBschema", "mediawiki" ); |
486 | | - $conf->DBport = importPost( "DBport", "5432" ); |
487 | 487 | $conf->DBmysql5 = (importPost( "DBmysql5" ) == "true") ? "true" : "false"; |
488 | 488 | $conf->RootUser = importPost( "RootUser", "root" ); |
489 | 489 | $conf->RootPW = importPost( "RootPW", "-" ); |
— | — | @@ -620,7 +620,7 @@ |
621 | 621 | |
622 | 622 | # Attempt to connect |
623 | 623 | echo( "<li>Attempting to connect to database server as $db_user..." ); |
624 | | - $wgDatabase = Database::newFromParams( $wgDBserver, $db_user, $db_pass, '', 1 ); |
| 624 | + $wgDatabase = Database::newFromParams( $wgDBserver, $wgDBport, $db_user, $db_pass, '', 1 ); |
625 | 625 | |
626 | 626 | # Check the connection and respond to errors |
627 | 627 | if( $wgDatabase->isOpen() ) { |
— | — | @@ -664,7 +664,7 @@ |
665 | 665 | |
666 | 666 | } else /* not mysql */ { |
667 | 667 | echo( "<li>Attempting to connect to database server as $wgDBuser..." ); |
668 | | - $wgDatabase = $dbc->newFromParams($wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1); |
| 668 | + $wgDatabase = $dbc->newFromParams($wgDBserver, $wgDBport, $wgDBuser, $wgDBpassword, $wgDBname, 1); |
669 | 669 | if (!$wgDatabase->isOpen()) { |
670 | 670 | print " error: " . $wgDatabase->lastError() . "</li>\n"; |
671 | 671 | } else { |
— | — | @@ -728,7 +728,7 @@ |
729 | 729 | |
730 | 730 | # Create user if required |
731 | 731 | if ( $conf->Root ) { |
732 | | - $conn = $dbc->newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1 ); |
| 732 | + $conn = $dbc->newFromParams( $wgDBserver, $wgDBport, $wgDBuser, $wgDBpassword, $wgDBname, 1 ); |
733 | 733 | if ( $conn->isOpen() ) { |
734 | 734 | print "<li>DB user account ok</li>\n"; |
735 | 735 | $conn->close(); |
— | — | @@ -785,7 +785,7 @@ |
786 | 786 | # Set up the "regular user" account *if we can, and if we need to* |
787 | 787 | if( $conf->Root ) { |
788 | 788 | # See if we need to |
789 | | - $wgDatabase2 = $dbc->newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1 ); |
| 789 | + $wgDatabase2 = $dbc->newFromParams( $wgDBserver, $wgDBport, $wgDBuser, $wgDBpassword, $wgDBname, 1 ); |
790 | 790 | if( $wgDatabase2->isOpen() ) { |
791 | 791 | # Nope, just close the test connection and continue |
792 | 792 | $wgDatabase2->close(); |
— | — | @@ -1340,6 +1340,7 @@ |
1341 | 1341 | \$wgEmailAuthentication = $eauthent; |
1342 | 1342 | |
1343 | 1343 | \$wgDBserver = \"{$slconf['DBserver']}\"; |
| 1344 | +\$wgDBport = \"{$slconf['DBport']}\"; |
1344 | 1345 | \$wgDBname = \"{$slconf['DBname']}\"; |
1345 | 1346 | \$wgDBuser = \"{$slconf['DBuser']}\"; |
1346 | 1347 | \$wgDBpassword = \"{$slconf['DBpassword']}\"; |
Index: trunk/phase3/includes/DatabaseOracle.php |
— | — | @@ -40,7 +40,7 @@ |
41 | 41 | Database::Database( $server, $user, $password, $dbName, $failFunction, $flags, $tablePrefix ); |
42 | 42 | } |
43 | 43 | |
44 | | - /* static */ function newFromParams( $server = false, $user = false, $password = false, $dbName = false, |
| 44 | + /* static */ function newFromParams( $server = false, $port = false, $user = false, $password = false, $dbName = false, |
45 | 45 | $failFunction = false, $flags = 0, $tablePrefix = 'get from global' ) |
46 | 46 | { |
47 | 47 | return new DatabaseOracle( $server, $user, $password, $dbName, $failFunction, $flags, $tablePrefix ); |
Index: trunk/phase3/includes/Setup.php |
— | — | @@ -147,6 +147,7 @@ |
148 | 148 | if ( !$wgDBservers ) { |
149 | 149 | $wgDBservers = array(array( |
150 | 150 | 'host' => $wgDBserver, |
| 151 | + 'port' => $wgDBport, |
151 | 152 | 'user' => $wgDBuser, |
152 | 153 | 'password' => $wgDBpassword, |
153 | 154 | 'dbname' => $wgDBname, |
Index: trunk/phase3/includes/DatabasePostgres.php |
— | — | @@ -7,9 +7,6 @@ |
8 | 8 | * than MySQL ones, some of them should be moved to parent |
9 | 9 | * Database class. |
10 | 10 | * |
11 | | - * STATUS: Working PG implementation of MediaWiki |
12 | | - * TODO: Installer support |
13 | | - * |
14 | 11 | * @package MediaWiki |
15 | 12 | */ |
16 | 13 | |
— | — | @@ -18,31 +15,28 @@ |
19 | 16 | */ |
20 | 17 | require_once( 'Database.php' ); |
21 | 18 | |
22 | | -/** |
23 | | - * |
24 | | - * @package MediaWiki |
25 | | - */ |
26 | 19 | class DatabasePostgres extends Database { |
27 | 20 | var $mInsertId = NULL; |
28 | 21 | var $mLastResult = NULL; |
29 | 22 | |
30 | | - function DatabasePostgres($server = false, $user = false, $password = false, $dbName = false, |
| 23 | + function DatabasePostgres($server = false, $port = false, $user = false, $password = false, $dbName = false, |
31 | 24 | $failFunction = false, $flags = 0 ) |
32 | 25 | { |
33 | | - Database::__construct( $server, $user, $password, $dbName, $failFunction, $flags ); |
| 26 | + Database::__construct( $server, $port, $user, $password, $dbName, $failFunction, $flags ); |
34 | 27 | } |
35 | 28 | |
36 | | - static function newFromParams( $server = false, $user = false, $password = false, $dbName = false, |
| 29 | + static function newFromParams( $server = false, $port = false, $user = false, $password = false, $dbName = false, |
37 | 30 | $failFunction = false, $flags = 0) |
38 | 31 | { |
39 | | - return new DatabasePostgres( $server, $user, $password, $dbName, $failFunction, $flags ); |
| 32 | + return new DatabasePostgres( $server, $port, $user, $password, $dbName, $failFunction, $flags ); |
40 | 33 | } |
41 | 34 | |
42 | 35 | /** |
43 | 36 | * Usually aborts on failure |
44 | 37 | * If the failFunction is set to a non-zero integer, returns success |
45 | 38 | */ |
46 | | - function open( $server, $user, $password, $dbName ) { |
| 39 | + function open( $server, $port, $user, $password, $dbName ) { |
| 40 | + |
47 | 41 | # Test for PostgreSQL support, to avoid suppressed fatal error |
48 | 42 | if ( !function_exists( 'pg_connect' ) ) { |
49 | 43 | throw new DBConnectionError( $this, "PostgreSQL functions missing, have you compiled PHP with the --with-pgsql option?\n" ); |
— | — | @@ -56,6 +50,7 @@ |
57 | 51 | $this->mPassword = $password; |
58 | 52 | $this->mDBname = $dbName; |
59 | 53 | $this->mSchemas = array($wgDBschema,'public'); |
| 54 | + $this->mPort = $port; |
60 | 55 | |
61 | 56 | $success = false; |
62 | 57 | |
— | — | @@ -65,6 +60,9 @@ |
66 | 61 | if ($server!=false && $server!="") { |
67 | 62 | $hstring="host=$server "; |
68 | 63 | } |
| 64 | + if ($port!=false && $port != '') { |
| 65 | + $hstring .= "port=$port "; |
| 66 | + } |
69 | 67 | |
70 | 68 | @$this->mConn = pg_connect("$hstring dbname=$dbName user=$user password=$password"); |
71 | 69 | if ( $this->mConn == false ) { |
— | — | @@ -197,7 +195,7 @@ |
198 | 196 | $n = pg_num_fields( $res ); |
199 | 197 | for( $i = 0; $i < $n; $i++ ) { |
200 | 198 | // FIXME |
201 | | - throw new DBUnexpectedError($this, "Database::fieldInfo() error : mysql_fetch_field() not implemented for postgre" ); |
| 199 | + throw new DBUnexpectedError($this, "Database::fieldInfo() error : mysql_fetch_field() not implemented for postgres" ); |
202 | 200 | $meta = mysql_fetch_field( $res, $i ); |
203 | 201 | if( $field == $meta->name ) { |
204 | 202 | return $meta; |
— | — | @@ -439,6 +437,44 @@ |
440 | 438 | $searchpath=$this->makeList($schemas,LIST_NAMES); |
441 | 439 | $this->query("SET search_path = $searchpath"); |
442 | 440 | } |
| 441 | + |
| 442 | + |
| 443 | + /** |
| 444 | + * Query whether a given table exists |
| 445 | + */ |
| 446 | + function tableExists( $table ) { |
| 447 | + global $wgDBschema; |
| 448 | + $safetable = preg_replace("/'/", "''", $table); |
| 449 | + $SQL = "SELECT 1 FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n WHERE c.relnamespace = n.oid " |
| 450 | + . "AND c.relname = '$safetable' AND n.nspname = '$wgDBschema'"; |
| 451 | + $res = $this->query($SQL); |
| 452 | + if( $res ) { |
| 453 | + $this->freeResult( $res ); |
| 454 | + return true; |
| 455 | + } else { |
| 456 | + return false; |
| 457 | + } |
| 458 | + } |
| 459 | + |
| 460 | + function fieldExists( $table, $field, $fname = 'DatabasePostgres::fieldExists' ) { |
| 461 | + global $wgDBschema; |
| 462 | + $safetable = preg_replace("/'/", "''", $table); |
| 463 | + $safecol = preg_replace("/'/", "''", $field); |
| 464 | + $SQL = "SELECT 1 FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n, pg_attribute a " |
| 465 | + . "WHERE c.relnamespace = n.oid AND c.relname = '$safetable' AND n.nspname = '$wgDBschema' " |
| 466 | + . "AND a.attrelid = c.oid AND a.attname = '$safecol'"; |
| 467 | + $res = $this->query($SQL, $fname); |
| 468 | + if( $res ) { |
| 469 | + $this->freeResult( $res ); |
| 470 | + return true; |
| 471 | + } else { |
| 472 | + return false; |
| 473 | + } |
| 474 | + } |
| 475 | + |
| 476 | + |
| 477 | + |
| 478 | + |
443 | 479 | } |
444 | 480 | |
445 | 481 | ?> |
Index: trunk/phase3/includes/DefaultSettings.php |
— | — | @@ -433,12 +433,13 @@ |
434 | 434 | $wgDBserver = 'localhost'; |
435 | 435 | /** name of the database */ |
436 | 436 | $wgDBname = 'wikidb'; |
| 437 | +/** port number for databases that use them (e.g. postgres) */ |
| 438 | +$wgDBport = 5432; |
437 | 439 | /** */ |
438 | 440 | $wgDBconnection = ''; |
439 | 441 | /** Database username */ |
440 | 442 | $wgDBuser = 'wikiuser'; |
441 | 443 | /** Database type |
442 | | - * "mysql" for working code and "PostgreSQL" for development/broken code |
443 | 444 | */ |
444 | 445 | $wgDBtype = "mysql"; |
445 | 446 | /** Search type |
Index: trunk/phase3/includes/Database.php |
— | — | @@ -240,7 +240,7 @@ |
241 | 241 | |
242 | 242 | protected $mLastQuery = ''; |
243 | 243 | |
244 | | - protected $mServer, $mUser, $mPassword, $mConn = null, $mDBname; |
| 244 | + protected $mServer, $mPort, $mUser, $mPassword, $mConn = null, $mDBname; |
245 | 245 | protected $mOut, $mOpened = false; |
246 | 246 | |
247 | 247 | protected $mFailFunction; |
— | — | @@ -371,6 +371,7 @@ |
372 | 372 | |
373 | 373 | /**@{{ |
374 | 374 | * @param string $server database server host |
| 375 | + * @param string $port database server port |
375 | 376 | * @param string $user database user name |
376 | 377 | * @param string $password database user password |
377 | 378 | * @param string $dbname database name |
— | — | @@ -381,8 +382,8 @@ |
382 | 383 | * @param $flags |
383 | 384 | * @param $tablePrefix String: database table prefixes. By default use the prefix gave in LocalSettings.php |
384 | 385 | */ |
385 | | - function __construct( $server = false, $user = false, $password = false, $dbName = false, |
386 | | - $failFunction = false, $flags = 0, $tablePrefix = 'get from global' ) { |
| 386 | + function __construct( $server = false, $port = false, $user = false, $password = false, $dbName = false, |
| 387 | + $failFunction = false, $flags = 0, $tablePrefix = 'get from global') { |
387 | 388 | |
388 | 389 | global $wgOut, $wgDBprefix, $wgCommandLineMode; |
389 | 390 | # Can't get a reference if it hasn't been set yet |
— | — | @@ -416,8 +417,8 @@ |
417 | 418 | $this->mTablePrefix = $tablePrefix; |
418 | 419 | } |
419 | 420 | |
420 | | - if ( $server ) { |
421 | | - $this->open( $server, $user, $password, $dbName ); |
| 421 | + if ( $server or $port) { |
| 422 | + $this->open( $server, $port, $user, $password, $dbName ); |
422 | 423 | } |
423 | 424 | } |
424 | 425 | |
— | — | @@ -426,17 +427,17 @@ |
427 | 428 | * @param failFunction |
428 | 429 | * @param $flags |
429 | 430 | */ |
430 | | - static function newFromParams( $server, $user, $password, $dbName, |
| 431 | + static function newFromParams( $server, $port, $user, $password, $dbName, |
431 | 432 | $failFunction = false, $flags = 0 ) |
432 | 433 | { |
433 | | - return new Database( $server, $user, $password, $dbName, $failFunction, $flags ); |
| 434 | + return new Database( $server, $port, $user, $password, $dbName, $failFunction, $flags ); |
434 | 435 | } |
435 | 436 | |
436 | 437 | /** |
437 | 438 | * Usually aborts on failure |
438 | 439 | * If the failFunction is set to a non-zero integer, returns success |
439 | 440 | */ |
440 | | - function open( $server, $user, $password, $dbName ) { |
| 441 | + function open( $server, $port, $user, $password, $dbName ) { |
441 | 442 | global $wguname; |
442 | 443 | |
443 | 444 | # Test for missing mysql.so |
— | — | @@ -1923,7 +1924,7 @@ |
1924 | 1925 | */ |
1925 | 1926 | protected function replaceVars( $ins ) { |
1926 | 1927 | $varnames = array( |
1927 | | - 'wgDBserver', 'wgDBname', 'wgDBintlname', 'wgDBuser', |
| 1928 | + 'wgDBserver', 'wgDBport', 'wgDBname', 'wgDBintlname', 'wgDBuser', |
1928 | 1929 | 'wgDBpassword', 'wgDBsqluser', 'wgDBsqlpassword', |
1929 | 1930 | 'wgDBadminuser', 'wgDBadminpassword', |
1930 | 1931 | ); |