r15093 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r15092‎ | r15093 | r15094 >
Date:15:37, 27 June 2006
Author:greg
Status:old
Tags:
Comment:
Add concept of a distinct port separate from a server.
Add some functions to DatabasePostgres.php.
Modified paths:
  • /trunk/phase3/config/index.php (modified) (history)
  • /trunk/phase3/includes/Database.php (modified) (history)
  • /trunk/phase3/includes/DatabaseOracle.php (modified) (history)
  • /trunk/phase3/includes/DatabasePostgres.php (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/Setup.php (modified) (history)
  • /trunk/phase3/maintenance/convertLinks.inc (modified) (history)
  • /trunk/phase3/maintenance/rebuildall.php (modified) (history)
  • /trunk/phase3/maintenance/rebuildtextindex.php (modified) (history)
  • /trunk/phase3/maintenance/tables.sql (modified) (history)
  • /trunk/phase3/maintenance/update.php (modified) (history)
  • /trunk/phase3/tests/LocalTestSettings.sample (modified) (history)
  • /trunk/phase3/tests/RunTests.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/update.php
@@ -32,7 +32,7 @@
3333
3434 # Attempt to connect to the database as a privileged user
3535 # 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 );
3737
3838 if( !$wgDatabase->isOpen() ) {
3939 # Appears to have failed
Index: trunk/phase3/maintenance/rebuildall.php
@@ -15,7 +15,7 @@
1616 require_once( "rebuildtextindex.inc" );
1717 require_once( "rebuildrecentchanges.inc" );
1818
19 -$database = Database::newFromParams( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname );
 19+$database = Database::newFromParams( $wgDBserver, $wgDBport, wgDBadminuser, $wgDBadminpassword, $wgDBname );
2020
2121 print "** Rebuilding fulltext search index (if you abort this will break searching; run this script again to fix):\n";
2222 dropTextIndex( $database );
Index: trunk/phase3/maintenance/rebuildtextindex.php
@@ -13,7 +13,7 @@
1414 require_once( "rebuildtextindex.inc" );
1515 $wgTitle = Title::newFromText( "Rebuild text index script" );
1616
17 -$database = Database::newFromParams( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname );
 17+$database = Database::newFromParams( $wgDBserver, $wgDBport, $wgDBadminuser, $wgDBadminpassword, $wgDBname );
1818
1919 dropTextIndex( $database );
2020 rebuildTextIndex( $database );
Index: trunk/phase3/maintenance/convertLinks.inc
@@ -8,14 +8,14 @@
99 /** */
1010 function convertLinks() {
1111 global $wgDBtype;
12 - if( $wgDBtype == 'PostgreSQL' ) {
 12+ if( $wgDBtype == 'Postgres' ) {
1313 print "Links table already ok on PostgreSQL.\n";
1414 return;
1515 }
1616
1717 print "Converting links table to ID-ID...\n";
1818
19 - global $wgLang, $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname;
 19+ global $wgLang, $wgDBserver, $wgDBport, $wgDBadminuser, $wgDBadminpassword, $wgDBname;
2020 global $noKeys, $logPerformance, $fh;
2121
2222 $numRows = $tuplesAdded = $numBadLinks = $curRowsRead = 0; #counters etc
@@ -147,7 +147,7 @@
148148 #--------------------------------------------------------------------
149149
150150 if ( $overwriteLinksTable ) {
151 - $dbConn = Database::newFromParams( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname );
 151+ $dbConn = Database::newFromParams( $wgDBserver, $wgDBport, $wgDBadminuser, $wgDBadminpassword, $wgDBname );
152152 if (!($dbConn->isOpen())) {
153153 print "Opening connection to database failed.\n";
154154 return;
@@ -174,9 +174,9 @@
175175 #--------------------------------------------------------------------
176176
177177 function createTempTable() {
178 - global $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname;
 178+ global $wgDBserver, $wgDBport, $wgDBadminuser, $wgDBadminpassword, $wgDBname;
179179 global $noKeys;
180 - $dbConn = Database::newFromParams( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname );
 180+ $dbConn = Database::newFromParams( $wgDBserver, $wgDBport, $wgDBadminuser, $wgDBadminpassword, $wgDBname );
181181
182182 if (!($dbConn->isOpen())) {
183183 print "Opening connection to database failed.\n";
Index: trunk/phase3/maintenance/tables.sql
@@ -995,4 +995,4 @@
996996
997997 UNIQUE KEY ( qci_type )
998998
999 -) TYPE=InnoDB;
\ No newline at end of file
 999+) TYPE=InnoDB;
Index: trunk/phase3/tests/LocalTestSettings.sample
@@ -12,16 +12,19 @@
1313 $testOptions = array(
1414 'mysql3' => array(
1515 'server' => null,
 16+ 'port' => null,
1617 'user' => null,
1718 'password' => null,
1819 'database' => null ),
1920 'mysql4' => array(
2021 'server' => null,
 22+ 'port' => null,
2123 'user' => null,
2224 'password' => null,
2325 'database' => null ),
2426 'postgres' => array(
2527 'server' => null,
 28+ 'port' => null,
2629 'user' => null,
2730 'password' => null,
2831 'database' => null ),
Index: trunk/phase3/tests/RunTests.php
@@ -14,13 +14,15 @@
1515
1616 $testOptions = array(
1717 'mysql4' => array(
18 - 'server' => null,
19 - 'user' => null,
 18+ 'server' => null,
 19+ 'port' => null,
 20+ 'user' => null,
2021 'password' => null,
2122 'database' => null ),
2223 'postgres' => array(
23 - 'server' => null,
24 - 'user' => null,
 24+ 'server' => null,
 25+ 'port' => null
 26+ 'user' => null,
2527 'password' => null,
2628 'database' => null ),
2729 );
Index: trunk/phase3/config/index.php
@@ -476,13 +476,13 @@
477477
478478 <?php
479479 $conf->DBserver = importPost( "DBserver", "localhost" );
 480+ $conf->DBport = importPost( "DBport", "5432" );
480481 $conf->DBname = importPost( "DBname", "wikidb" );
481482 $conf->DBuser = importPost( "DBuser", "wikiuser" );
482483 $conf->DBpassword = importPost( "DBpassword" );
483484 $conf->DBpassword2 = importPost( "DBpassword2" );
484485 $conf->DBprefix = importPost( "DBprefix" );
485486 $conf->DBschema = importPost( "DBschema", "mediawiki" );
486 - $conf->DBport = importPost( "DBport", "5432" );
487487 $conf->DBmysql5 = (importPost( "DBmysql5" ) == "true") ? "true" : "false";
488488 $conf->RootUser = importPost( "RootUser", "root" );
489489 $conf->RootPW = importPost( "RootPW", "-" );
@@ -620,7 +620,7 @@
621621
622622 # Attempt to connect
623623 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 );
625625
626626 # Check the connection and respond to errors
627627 if( $wgDatabase->isOpen() ) {
@@ -664,7 +664,7 @@
665665
666666 } else /* not mysql */ {
667667 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);
669669 if (!$wgDatabase->isOpen()) {
670670 print " error: " . $wgDatabase->lastError() . "</li>\n";
671671 } else {
@@ -728,7 +728,7 @@
729729
730730 # Create user if required
731731 if ( $conf->Root ) {
732 - $conn = $dbc->newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1 );
 732+ $conn = $dbc->newFromParams( $wgDBserver, $wgDBport, $wgDBuser, $wgDBpassword, $wgDBname, 1 );
733733 if ( $conn->isOpen() ) {
734734 print "<li>DB user account ok</li>\n";
735735 $conn->close();
@@ -785,7 +785,7 @@
786786 # Set up the "regular user" account *if we can, and if we need to*
787787 if( $conf->Root ) {
788788 # See if we need to
789 - $wgDatabase2 = $dbc->newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1 );
 789+ $wgDatabase2 = $dbc->newFromParams( $wgDBserver, $wgDBport, $wgDBuser, $wgDBpassword, $wgDBname, 1 );
790790 if( $wgDatabase2->isOpen() ) {
791791 # Nope, just close the test connection and continue
792792 $wgDatabase2->close();
@@ -1340,6 +1340,7 @@
13411341 \$wgEmailAuthentication = $eauthent;
13421342
13431343 \$wgDBserver = \"{$slconf['DBserver']}\";
 1344+\$wgDBport = \"{$slconf['DBport']}\";
13441345 \$wgDBname = \"{$slconf['DBname']}\";
13451346 \$wgDBuser = \"{$slconf['DBuser']}\";
13461347 \$wgDBpassword = \"{$slconf['DBpassword']}\";
Index: trunk/phase3/includes/DatabaseOracle.php
@@ -40,7 +40,7 @@
4141 Database::Database( $server, $user, $password, $dbName, $failFunction, $flags, $tablePrefix );
4242 }
4343
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,
4545 $failFunction = false, $flags = 0, $tablePrefix = 'get from global' )
4646 {
4747 return new DatabaseOracle( $server, $user, $password, $dbName, $failFunction, $flags, $tablePrefix );
Index: trunk/phase3/includes/Setup.php
@@ -147,6 +147,7 @@
148148 if ( !$wgDBservers ) {
149149 $wgDBservers = array(array(
150150 'host' => $wgDBserver,
 151+ 'port' => $wgDBport,
151152 'user' => $wgDBuser,
152153 'password' => $wgDBpassword,
153154 'dbname' => $wgDBname,
Index: trunk/phase3/includes/DatabasePostgres.php
@@ -7,9 +7,6 @@
88 * than MySQL ones, some of them should be moved to parent
99 * Database class.
1010 *
11 - * STATUS: Working PG implementation of MediaWiki
12 - * TODO: Installer support
13 - *
1411 * @package MediaWiki
1512 */
1613
@@ -18,31 +15,28 @@
1916 */
2017 require_once( 'Database.php' );
2118
22 -/**
23 - *
24 - * @package MediaWiki
25 - */
2619 class DatabasePostgres extends Database {
2720 var $mInsertId = NULL;
2821 var $mLastResult = NULL;
2922
30 - function DatabasePostgres($server = false, $user = false, $password = false, $dbName = false,
 23+ function DatabasePostgres($server = false, $port = false, $user = false, $password = false, $dbName = false,
3124 $failFunction = false, $flags = 0 )
3225 {
33 - Database::__construct( $server, $user, $password, $dbName, $failFunction, $flags );
 26+ Database::__construct( $server, $port, $user, $password, $dbName, $failFunction, $flags );
3427 }
3528
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,
3730 $failFunction = false, $flags = 0)
3831 {
39 - return new DatabasePostgres( $server, $user, $password, $dbName, $failFunction, $flags );
 32+ return new DatabasePostgres( $server, $port, $user, $password, $dbName, $failFunction, $flags );
4033 }
4134
4235 /**
4336 * Usually aborts on failure
4437 * If the failFunction is set to a non-zero integer, returns success
4538 */
46 - function open( $server, $user, $password, $dbName ) {
 39+ function open( $server, $port, $user, $password, $dbName ) {
 40+
4741 # Test for PostgreSQL support, to avoid suppressed fatal error
4842 if ( !function_exists( 'pg_connect' ) ) {
4943 throw new DBConnectionError( $this, "PostgreSQL functions missing, have you compiled PHP with the --with-pgsql option?\n" );
@@ -56,6 +50,7 @@
5751 $this->mPassword = $password;
5852 $this->mDBname = $dbName;
5953 $this->mSchemas = array($wgDBschema,'public');
 54+ $this->mPort = $port;
6055
6156 $success = false;
6257
@@ -65,6 +60,9 @@
6661 if ($server!=false && $server!="") {
6762 $hstring="host=$server ";
6863 }
 64+ if ($port!=false && $port != '') {
 65+ $hstring .= "port=$port ";
 66+ }
6967
7068 @$this->mConn = pg_connect("$hstring dbname=$dbName user=$user password=$password");
7169 if ( $this->mConn == false ) {
@@ -197,7 +195,7 @@
198196 $n = pg_num_fields( $res );
199197 for( $i = 0; $i < $n; $i++ ) {
200198 // 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" );
202200 $meta = mysql_fetch_field( $res, $i );
203201 if( $field == $meta->name ) {
204202 return $meta;
@@ -439,6 +437,44 @@
440438 $searchpath=$this->makeList($schemas,LIST_NAMES);
441439 $this->query("SET search_path = $searchpath");
442440 }
 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+
443479 }
444480
445481 ?>
Index: trunk/phase3/includes/DefaultSettings.php
@@ -433,12 +433,13 @@
434434 $wgDBserver = 'localhost';
435435 /** name of the database */
436436 $wgDBname = 'wikidb';
 437+/** port number for databases that use them (e.g. postgres) */
 438+$wgDBport = 5432;
437439 /** */
438440 $wgDBconnection = '';
439441 /** Database username */
440442 $wgDBuser = 'wikiuser';
441443 /** Database type
442 - * "mysql" for working code and "PostgreSQL" for development/broken code
443444 */
444445 $wgDBtype = "mysql";
445446 /** Search type
Index: trunk/phase3/includes/Database.php
@@ -240,7 +240,7 @@
241241
242242 protected $mLastQuery = '';
243243
244 - protected $mServer, $mUser, $mPassword, $mConn = null, $mDBname;
 244+ protected $mServer, $mPort, $mUser, $mPassword, $mConn = null, $mDBname;
245245 protected $mOut, $mOpened = false;
246246
247247 protected $mFailFunction;
@@ -371,6 +371,7 @@
372372
373373 /**@{{
374374 * @param string $server database server host
 375+ * @param string $port database server port
375376 * @param string $user database user name
376377 * @param string $password database user password
377378 * @param string $dbname database name
@@ -381,8 +382,8 @@
382383 * @param $flags
383384 * @param $tablePrefix String: database table prefixes. By default use the prefix gave in LocalSettings.php
384385 */
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') {
387388
388389 global $wgOut, $wgDBprefix, $wgCommandLineMode;
389390 # Can't get a reference if it hasn't been set yet
@@ -416,8 +417,8 @@
417418 $this->mTablePrefix = $tablePrefix;
418419 }
419420
420 - if ( $server ) {
421 - $this->open( $server, $user, $password, $dbName );
 421+ if ( $server or $port) {
 422+ $this->open( $server, $port, $user, $password, $dbName );
422423 }
423424 }
424425
@@ -426,17 +427,17 @@
427428 * @param failFunction
428429 * @param $flags
429430 */
430 - static function newFromParams( $server, $user, $password, $dbName,
 431+ static function newFromParams( $server, $port, $user, $password, $dbName,
431432 $failFunction = false, $flags = 0 )
432433 {
433 - return new Database( $server, $user, $password, $dbName, $failFunction, $flags );
 434+ return new Database( $server, $port, $user, $password, $dbName, $failFunction, $flags );
434435 }
435436
436437 /**
437438 * Usually aborts on failure
438439 * If the failFunction is set to a non-zero integer, returns success
439440 */
440 - function open( $server, $user, $password, $dbName ) {
 441+ function open( $server, $port, $user, $password, $dbName ) {
441442 global $wguname;
442443
443444 # Test for missing mysql.so
@@ -1923,7 +1924,7 @@
19241925 */
19251926 protected function replaceVars( $ins ) {
19261927 $varnames = array(
1927 - 'wgDBserver', 'wgDBname', 'wgDBintlname', 'wgDBuser',
 1928+ 'wgDBserver', 'wgDBport', 'wgDBname', 'wgDBintlname', 'wgDBuser',
19281929 'wgDBpassword', 'wgDBsqluser', 'wgDBsqlpassword',
19291930 'wgDBadminuser', 'wgDBadminpassword',
19301931 );