r13603 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r13602‎ | r13603 | r13604 >
Date:08:15, 12 April 2006
Author:brion
Status:old
Tags:
Comment:
* (bug 385) Installer support for PostgreSQL, fixes for PG compatibility
Applied from: http://bugzilla.wikimedia.org/attachment.cgi?id=1517&action=view
I haven't tested it with PG personally yet, but it doesn't appear to interfere with other functionality.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/config/index.php (modified) (history)
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/Database.php (modified) (history)
  • /trunk/phase3/includes/Export.php (modified) (history)
  • /trunk/phase3/includes/LoadBalancer.php (modified) (history)
  • /trunk/phase3/includes/Revision.php (modified) (history)
  • /trunk/phase3/includes/SpecialAncientpages.php (modified) (history)
  • /trunk/phase3/includes/SpecialBrokenRedirects.php (modified) (history)
  • /trunk/phase3/includes/SpecialDisambiguations.php (modified) (history)
  • /trunk/phase3/includes/SpecialListusers.php (modified) (history)
  • /trunk/phase3/includes/SpecialMostcategories.php (modified) (history)
  • /trunk/phase3/includes/SpecialMostlinked.php (modified) (history)
  • /trunk/phase3/includes/SpecialMostrevisions.php (modified) (history)
  • /trunk/phase3/includes/SpecialRecentchanges.php (modified) (history)
  • /trunk/phase3/includes/SpecialShortpages.php (modified) (history)
  • /trunk/phase3/includes/SpecialWatchlist.php (modified) (history)
  • /trunk/phase3/install-utils.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/config/index.php
@@ -486,7 +486,7 @@
487487 $wgCommandLineMode = false;
488488 chdir( ".." );
489489 eval($local);
490 - if (!in_array($conf->DBtype, array("mysql", "oracle"))) {
 490+ if (!in_array($conf->DBtype, array("mysql", "oracle", "postgres"))) {
491491 $errs["DBtype"] = "Unknown database type.";
492492 continue;
493493 }
@@ -505,16 +505,16 @@
506506 require_once( "maintenance/InitialiseMessages.inc" );
507507
508508 $wgTitle = Title::newFromText( "Installation script" );
509 - $mysqlOldClient = version_compare( mysql_get_client_info(), "4.1.0", "lt" );
510 - if( $mysqlOldClient ) {
511 - print "<li><b>PHP is linked with old MySQL client libraries. If you are
512 - using a MySQL 4.1 server and have problems connecting to the database,
513 - see <a href='http://dev.mysql.com/doc/mysql/en/old-client.html'
514 - >http://dev.mysql.com/doc/mysql/en/old-client.html</a> for help.</b></li>\n";
515 - }
516509 $dbc = new $dbclass;
517 -
 510+
518511 if( $conf->DBtype == 'mysql' ) {
 512+ $mysqlOldClient = version_compare( mysql_get_client_info(), "4.1.0", "lt" );
 513+ if( $mysqlOldClient ) {
 514+ print "<li><b>PHP is linked with old MySQL client libraries. If you are
 515+ using a MySQL 4.1 server and have problems connecting to the database,
 516+ see <a href='http://dev.mysql.com/doc/mysql/en/old-client.html'
 517+ >http://dev.mysql.com/doc/mysql/en/old-client.html</a> for help.</b></li>\n";
 518+ }
519519 $ok = true; # Let's be optimistic
520520
521521 # Decide if we're going to use the superuser or the regular database user
@@ -575,13 +575,13 @@
576576 if( !$ok ) { continue; }
577577
578578 } else /* not mysql */ {
579 - print "<li>Connecting to SQL server...";
 579+ echo( "<li>Attempting to connect to database server as $wgDBuser..." );
580580 $wgDatabase = $dbc->newFromParams($wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1);
581581 if (!$wgDatabase->isOpen()) {
582582 print " error: " . $wgDatabase->lastError() . "</li>\n";
583583 } else {
584584 $wgDatabase->ignoreErrors(true);
585 - $myver = get_db_version();
 585+ $myver = $wgDatabase->getServerVersion();
586586 }
587587 }
588588
@@ -591,27 +591,27 @@
592592 }
593593
594594 print "<li>Connected to $myver";
595 - if( version_compare( $myver, "4.0.0" ) < 0 ) {
596 - die( " -- mysql 4.0 or later required. Aborting." );
597 - }
598 - $mysqlNewAuth = version_compare( $myver, "4.1.0", "ge" );
599 - if( $mysqlNewAuth && $mysqlOldClient ) {
600 - print "; <b class='error'>You are using MySQL 4.1 server, but PHP is linked
601 - to old client libraries; if you have trouble with authentication, see
602 - <a href='http://dev.mysql.com/doc/mysql/en/old-client.html'
603 - >http://dev.mysql.com/doc/mysql/en/old-client.html</a> for help.</b>";
604 - }
605 - if( $wgDBmysql5 ) {
606 - if( $mysqlNewAuth ) {
607 - print "; enabling MySQL 4.1/5.0 charset mode";
608 - } else {
609 - print "; <b class='error'>MySQL 4.1/5.0 charset mode enabled,
610 - but older version detected; will likely fail.</b>";
 595+ if ($conf->DBtype == 'mysql') {
 596+ if( version_compare( $myver, "4.0.0" ) < 0 ) {
 597+ die( " -- mysql 4.0 or later required. Aborting." );
611598 }
612 - }
613 - print "</li>\n";
 599+ $mysqlNewAuth = version_compare( $myver, "4.1.0", "ge" );
 600+ if( $mysqlNewAuth && $mysqlOldClient ) {
 601+ print "; <b class='error'>You are using MySQL 4.1 server, but PHP is linked
 602+ to old client libraries; if you have trouble with authentication, see
 603+ <a href='http://dev.mysql.com/doc/mysql/en/old-client.html'
 604+ >http://dev.mysql.com/doc/mysql/en/old-client.html</a> for help.</b>";
 605+ }
 606+ if( $wgDBmysql5 ) {
 607+ if( $mysqlNewAuth ) {
 608+ print "; enabling MySQL 4.1/5.0 charset mode";
 609+ } else {
 610+ print "; <b class='error'>MySQL 4.1/5.0 charset mode enabled,
 611+ but older version detected; will likely fail.</b>";
 612+ }
 613+ }
 614+ print "</li>\n";
614615
615 - if ($conf->DBtype == 'mysql') {
616616 @$sel = mysql_select_db( $wgDBname, $wgDatabase->mConn );
617617 if( $sel ) {
618618 print "<li>Database <tt>" . htmlspecialchars( $wgDBname ) . "</tt> exists</li>\n";
@@ -640,7 +640,7 @@
641641
642642 # Create user if required
643643 if ( $conf->Root ) {
644 - $conn = Database::newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1 );
 644+ $conn = $dbc->newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1 );
645645 if ( $conn->isOpen() ) {
646646 print "<li>DB user account ok</li>\n";
647647 $conn->close();
@@ -673,6 +673,9 @@
674674 dbsource( "../maintenance/tables.sql", $wgDatabase );
675675 }
676676 dbsource( "../maintenance/interwiki.sql", $wgDatabase );
 677+ } else if ($conf->DBtype == 'postgres') {
 678+ dbsource( "../maintenance/postgres/tables.sql", $wgDatabase );
 679+ $wgDatabase->update_interwiki();
677680 } else {
678681 dbsource( "../maintenance/oracle/tables.sql", $wgDatabase );
679682 dbsource( "../maintenance/oracle/interwiki.sql", $wgDatabase );
@@ -690,7 +693,7 @@
691694 # Set up the "regular user" account *if we can, and if we need to*
692695 if( $conf->Root ) {
693696 # See if we need to
694 - $wgDatabase2 = Database::newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1 );
 697+ $wgDatabase2 = $dbc->newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1 );
695698 if( $wgDatabase2->isOpen() ) {
696699 # Nope, just close the test connection and continue
697700 $wgDatabase2->close();
@@ -973,6 +976,7 @@
974977 <ul class='plain'>
975978 <li><?php aField( $conf, "DBtype", "MySQL", "radio", "mysql"); ?></li>
976979 <li><?php aField( $conf, "DBtype", "Oracle (experimental)", "radio", "oracle" ); ?></li>
 980+ <li><?php aField( $conf, "DBtype", "PostgreSQL", "radio", "postgres" ); ?></li>
977981 </ul>
978982 </div>
979983
@@ -981,7 +985,7 @@
982986 ?></div>
983987 <p class="config-desc">
984988 If your database server isn't on your web server, enter the name
985 - or IP address here. MySQL only.
 989+ or IP address here. MySQL and PostgreSQL only. If using a port for PostgreSQL, enter the number here.
986990 </p>
987991
988992 <div class="config-input"><?php
Index: trunk/phase3/includes/Article.php
@@ -2483,7 +2483,7 @@
24842484 */
24852485 function incViewCount( $id ) {
24862486 $id = intval( $id );
2487 - global $wgHitcounterUpdateFreq;
 2487+ global $wgHitcounterUpdateFreq, $wgDBtype;
24882488
24892489 $dbw =& wfGetDB( DB_MASTER );
24902490 $pageTable = $dbw->tableName( 'page' );
@@ -2514,12 +2514,15 @@
25152515 wfProfileIn( 'Article::incViewCount-collect' );
25162516 $old_user_abort = ignore_user_abort( true );
25172517
2518 - $dbw->query("LOCK TABLES $hitcounterTable WRITE");
2519 - $dbw->query("CREATE TEMPORARY TABLE $acchitsTable TYPE=HEAP ".
 2518+ if ($wgDBtype == 'mysql')
 2519+ $dbw->query("LOCK TABLES $hitcounterTable WRITE");
 2520+ $tabletype = $wgDBtype == 'mysql' ? "ENGINE=HEAP " : '';
 2521+ $dbw->query("CREATE TEMPORARY TABLE $acchitsTable $tabletype".
25202522 "SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable ".
25212523 'GROUP BY hc_id');
25222524 $dbw->query("DELETE FROM $hitcounterTable");
2523 - $dbw->query('UNLOCK TABLES');
 2525+ if ($wgDBtype == 'mysql')
 2526+ $dbw->query('UNLOCK TABLES');
25242527 $dbw->query("UPDATE $pageTable,$acchitsTable SET page_counter=page_counter + hc_n ".
25252528 'WHERE page_id = hc_id');
25262529 $dbw->query("DROP TABLE $acchitsTable");
Index: trunk/phase3/includes/SpecialDisambiguations.php
@@ -47,7 +47,7 @@
4848 wfDebug("Mediawiki:disambiguationspage message does not refer to a template!\n");
4949 }
5050
51 - $sql = "SELECT 'Disambiguations' AS 'type', pa.page_namespace AS namespace,"
 51+ $sql = "SELECT 'Disambiguations' AS \"type\", pa.page_namespace AS namespace,"
5252 ." pa.page_title AS title, la.pl_from AS value"
5353 ." FROM {$templatelinks} AS lb, {$page} AS pa, {$pagelinks} AS la"
5454 ." WHERE lb.tl_namespace = $dns AND lb.tl_title = $dtitle" # disambiguation template
Index: trunk/phase3/includes/SpecialMostrevisions.php
@@ -36,7 +36,7 @@
3737 FROM $revision
3838 LEFT JOIN $page ON page_id = rev_page
3939 WHERE page_namespace = " . NS_MAIN . "
40 - GROUP BY rev_page
 40+ GROUP BY rev_page, page_namespace, page_title
4141 HAVING COUNT(*) > 1
4242 ";
4343 }
Index: trunk/phase3/includes/SpecialMostcategories.php
@@ -34,7 +34,7 @@
3535 FROM $categorylinks
3636 LEFT JOIN $page ON cl_from = page_id
3737 WHERE page_namespace = " . NS_MAIN . "
38 - GROUP BY cl_from
 38+ GROUP BY cl_from, page_namespace, page_title
3939 HAVING COUNT(*) > 1
4040 ";
4141 }
Index: trunk/phase3/includes/SpecialRecentchanges.php
@@ -16,7 +16,7 @@
1717 * Constructor
1818 */
1919 function wfSpecialRecentchanges( $par, $specialPage ) {
20 - global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol;
 20+ global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol, $wgDBtype;
2121 global $wgRCShowWatchingUsers, $wgShowUpdatedMarker;
2222 global $wgAllowCategorizedRecentChanges ;
2323 $fname = 'wfSpecialRecentchanges';
@@ -162,7 +162,8 @@
163163 $uid = $wgUser->getID();
164164
165165 // Perform query
166 - $sql2 = "SELECT * FROM $recentchanges FORCE INDEX (rc_timestamp) " .
 166+ $forceclause = $dbr->useIndexClause("rc_timestamp");
 167+ $sql2 = "SELECT * FROM $recentchanges $forceclause".
167168 ($uid ? "LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") .
168169 "WHERE rc_timestamp >= '{$cutoff}' {$hidem} " .
169170 "ORDER BY rc_timestamp DESC";
Index: trunk/phase3/includes/Export.php
@@ -187,8 +187,7 @@
188188 }
189189 if( $cond == '' ) {
190190 // Optimization hack for full-database dump
191 - $pageindex = 'FORCE INDEX (PRIMARY)';
192 - $revindex = 'FORCE INDEX (PRIMARY)';
 191+ $revindex = $pageindex = $this->db->useIndexClause("PRIMARY");
193192 $straight = ' /*! STRAIGHT_JOIN */ ';
194193 } else {
195194 $pageindex = '';
Index: trunk/phase3/includes/SpecialWatchlist.php
@@ -269,13 +269,13 @@
270270 }
271271
272272 $sql = "SELECT
273 - rc_namespace page_namespace,rc_title page_title,
274 - rc_comment rev_comment, rc_cur_id page_id,
275 - rc_user rev_user,rc_user_text rev_user_text,
276 - rc_timestamp rev_timestamp,rc_minor rev_minor_edit,
277 - rc_this_oldid rev_id,
 273+ rc_namespace AS page_namespace, rc_title AS page_title,
 274+ rc_comment AS rev_comment, rc_cur_id AS page_id,
 275+ rc_user AS rev_user, rc_user_text AS rev_user_text,
 276+ rc_timestamp AS rev_timestamp, rc_minor AS rev_minor_edit,
 277+ rc_this_oldid AS rev_id,
278278 rc_last_oldid,
279 - rc_new page_is_new,wl_notificationtimestamp
 279+ rc_new AS page_is_new,wl_notificationtimestamp
280280 FROM $watchlist,$recentchanges,$page
281281 WHERE wl_user=$uid
282282 AND wl_namespace=rc_namespace
Index: trunk/phase3/includes/SpecialMostlinked.php
@@ -34,11 +34,10 @@
3535 pl_namespace AS namespace,
3636 pl_title AS title,
3737 COUNT(*) AS value,
38 -
3938 page_namespace
4039 FROM $pagelinks
4140 LEFT JOIN $page ON pl_namespace=page_namespace AND pl_title=page_title
42 - GROUP BY pl_namespace,pl_title
 41+ GROUP BY pl_namespace,pl_title,page_namespace
4342 HAVING COUNT(*) > 1";
4443 }
4544
Index: trunk/phase3/includes/Revision.php
@@ -644,7 +644,6 @@
645645 );
646646
647647 $this->mId = !is_null($rev_id) ? $rev_id : $dbw->insertId();
648 -
649648 wfProfileOut( $fname );
650649 return $this->mId;
651650 }
Index: trunk/phase3/includes/SpecialBrokenRedirects.php
@@ -38,12 +38,10 @@
3939 p1.page_title AS title,
4040 pl_namespace,
4141 pl_title
42 - FROM ($pagelinks, $page AS p1)
43 - LEFT JOIN $page AS p2
44 - ON pl_namespace=p2.page_namespace AND pl_title=p2.page_title
45 - WHERE p1.page_is_redirect=1
46 - AND pl_from=p1.page_id
47 - AND p2.page_namespace IS NULL";
 42+ FROM $pagelinks AS pl
 43+ JOIN $page p1 ON (p1.page_is_redirect=1 AND pl.pl_from=p1.page_id)
 44+ LEFT JOIN $page AS p2 ON (pl_namespace=p2.page_namespace AND pl_title=p2.page_title
 45+ AND p2.page_namespace IS NULL)";
4846 return $sql;
4947 }
5048
Index: trunk/phase3/includes/LoadBalancer.php
@@ -334,6 +334,7 @@
335335 */
336336 function &getConnection( $i, $fail = true, $groups = array() )
337337 {
 338+ global $wgDBtype;
338339 $fname = 'LoadBalancer::getConnection';
339340 wfProfileIn( $fname );
340341
@@ -354,8 +355,12 @@
355356 }
356357 }
357358
 359+ # For now, only go through all this for mysql databases
 360+ if ($wgDBtype != 'mysql') {
 361+ $i = $this->getWriterIndex();
 362+ }
358363 # Operation-based index
359 - if ( $i == DB_SLAVE ) {
 364+ elseif ( $i == DB_SLAVE ) {
360365 $i = $this->getReaderIndex();
361366 } elseif ( $i == DB_MASTER ) {
362367 $i = $this->getWriterIndex();
Index: trunk/phase3/includes/SpecialShortpages.php
@@ -38,12 +38,13 @@
3939 $page = $dbr->tableName( 'page' );
4040 $name = $dbr->addQuotes( $this->getName() );
4141
 42+ $forceindex = $dbr->useIndexClause("page_len");
4243 return
4344 "SELECT $name as type,
4445 page_namespace as namespace,
4546 page_title as title,
4647 page_len AS value
47 - FROM $page FORCE INDEX (page_len)
 48+ FROM $page $forceindex
4849 WHERE page_namespace=".NS_MAIN." AND page_is_redirect=0";
4950 }
5051
Index: trunk/phase3/includes/SpecialListusers.php
@@ -135,7 +135,7 @@
136136 "FROM $user ".
137137 "LEFT JOIN $user_groups ON user_id=ug_user " .
138138 $this->userQueryWhere( $dbr ) .
139 - " GROUP BY user_name";
 139+ " GROUP BY user_name, user_id";
140140
141141 return $sql;
142142 }
Index: trunk/phase3/includes/SpecialAncientpages.php
@@ -28,15 +28,18 @@
2929 function isSyndicated() { return false; }
3030
3131 function getSQL() {
 32+ global $wgDBtype;
3233 $db =& wfGetDB( DB_SLAVE );
3334 $page = $db->tableName( 'page' );
3435 $revision = $db->tableName( 'revision' );
3536 #$use_index = $db->useIndexClause( 'cur_timestamp' ); # FIXME! this is gone
 37+ $epoch = $wgDBtype == 'mysql' ? 'UNIX_TIMESTAMP(rev_timestamp)' :
 38+ 'EXTRACT(epoch FROM rev_timestamp)';
3639 return
3740 "SELECT 'Ancientpages' as type,
3841 page_namespace as namespace,
3942 page_title as title,
40 - UNIX_TIMESTAMP(rev_timestamp) as value
 43+ $epoch as value
4144 FROM $page, $revision
4245 WHERE page_namespace=".NS_MAIN." AND page_is_redirect=0
4346 AND page_latest=rev_id";
Index: trunk/phase3/includes/Database.php
@@ -1687,6 +1687,7 @@
16881688
16891689 $cmd = "";
16901690 $done = false;
 1691+ $dollarquote = false;
16911692
16921693 while ( ! feof( $fp ) ) {
16931694 $line = trim( fgets( $fp, 1024 ) );
@@ -1695,10 +1696,22 @@
16961697 if ( $sl < 0 ) { continue; }
16971698 if ( '-' == $line{0} && '-' == $line{1} ) { continue; }
16981699
1699 - if ( ';' == $line{$sl} && ($sl < 2 || ';' != $line{$sl - 1})) {
1700 - $done = true;
1701 - $line = substr( $line, 0, $sl );
 1700+ ## Allow dollar quoting for function declarations
 1701+ if (substr($line,0,4) == '$mw$') {
 1702+ if ($dollarquote) {
 1703+ $dollarquote = false;
 1704+ $done = true;
 1705+ }
 1706+ else {
 1707+ $dollarquote = true;
 1708+ }
17021709 }
 1710+ else if (!$dollarquote) {
 1711+ if ( ';' == $line{$sl} && ($sl < 2 || ';' != $line{$sl - 1})) {
 1712+ $done = true;
 1713+ $line = substr( $line, 0, $sl );
 1714+ }
 1715+ }
17031716
17041717 if ( '' != $cmd ) { $cmd .= ' '; }
17051718 $cmd .= "$line\n";
Index: trunk/phase3/RELEASE-NOTES
@@ -52,7 +52,9 @@
5353 * (bug 5537) Add stub language file for Samogitian (bat-smg); inherits Lithuanian (lt)
5454 * Don't force edit summaries when a user is editing their own user/talk page
5555 * (bug 5510) Warning produced when using {{SUBPAGENAME}} in some namespaces
 56+* (bug 385) Installer support for PostgreSQL, fixes for PG compatibility
5657
 58+
5759 == Compatibility ==
5860
5961 Older PHP 4.2 and 4.1 releases are no longer supported; PHP 4 users must
Index: trunk/phase3/install-utils.inc
@@ -15,12 +15,18 @@
1616 die( -1 );
1717 }
1818
19 - if (!extension_loaded('mysql')) {
20 - if (!dl('mysql.so')) {
21 - print 'Could not load MySQL driver! Please compile '.
22 - "php --with-mysql or install the mysql.so module.\n";
 19+ $gotdatabase = 0;
 20+ ## XXX We should quiet the warnings thrown here
 21+ if (extension_loaded('mysql') or dl('mysql.so')) {
 22+ $gotdatabase = 'mysql';
 23+ }
 24+ else if (extension_loaded('pgsql') or dl('pgsql.so')) {
 25+ $gotdatabase = 'pg';
 26+ }
 27+ if (!$gotdatabase) {
 28+ print "Could not load the MySQL or the PostgreSQL driver! Please compile ".
 29+ "php with either --with-mysql or --with-pgsql, or install the mysql.so or pg.so module.\n";
2330 exit;
24 - }
2531 }
2632
2733 global $wgCommandLineMode;

Status & tagging log