* (bug 5537) Add stub language file for Samogitian (bat-smg); inherits Lithuanian (lt)
* Don't force edit summaries when a user is editing their own user/talk page
* (bug 5510) Warning produced when using {{SUBPAGENAME}} in some namespaces
+* (bug 385) Installer support for PostgreSQL, fixes for PG compatibility
+
== Compatibility ==
$wgCommandLineMode = false;
chdir( ".." );
eval($local);
- if (!in_array($conf->DBtype, array("mysql", "oracle"))) {
+ if (!in_array($conf->DBtype, array("mysql", "oracle", "postgres"))) {
$errs["DBtype"] = "Unknown database type.";
continue;
}
require_once( "maintenance/InitialiseMessages.inc" );
$wgTitle = Title::newFromText( "Installation script" );
- $mysqlOldClient = version_compare( mysql_get_client_info(), "4.1.0", "lt" );
- if( $mysqlOldClient ) {
- print "<li><b>PHP is linked with old MySQL client libraries. If you are
- using a MySQL 4.1 server and have problems connecting to the database,
- see <a href='http://dev.mysql.com/doc/mysql/en/old-client.html'
- >http://dev.mysql.com/doc/mysql/en/old-client.html</a> for help.</b></li>\n";
- }
$dbc = new $dbclass;
-
+
if( $conf->DBtype == 'mysql' ) {
+ $mysqlOldClient = version_compare( mysql_get_client_info(), "4.1.0", "lt" );
+ if( $mysqlOldClient ) {
+ print "<li><b>PHP is linked with old MySQL client libraries. If you are
+ using a MySQL 4.1 server and have problems connecting to the database,
+ see <a href='http://dev.mysql.com/doc/mysql/en/old-client.html'
+ >http://dev.mysql.com/doc/mysql/en/old-client.html</a> for help.</b></li>\n";
+ }
$ok = true; # Let's be optimistic
# Decide if we're going to use the superuser or the regular database user
if( !$ok ) { continue; }
} else /* not mysql */ {
- print "<li>Connecting to SQL server...";
+ echo( "<li>Attempting to connect to database server as $wgDBuser..." );
$wgDatabase = $dbc->newFromParams($wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1);
if (!$wgDatabase->isOpen()) {
print " error: " . $wgDatabase->lastError() . "</li>\n";
} else {
$wgDatabase->ignoreErrors(true);
- $myver = get_db_version();
+ $myver = $wgDatabase->getServerVersion();
}
}
}
print "<li>Connected to $myver";
- if( version_compare( $myver, "4.0.0" ) < 0 ) {
- die( " -- mysql 4.0 or later required. Aborting." );
- }
- $mysqlNewAuth = version_compare( $myver, "4.1.0", "ge" );
- if( $mysqlNewAuth && $mysqlOldClient ) {
- print "; <b class='error'>You are using MySQL 4.1 server, but PHP is linked
- to old client libraries; if you have trouble with authentication, see
- <a href='http://dev.mysql.com/doc/mysql/en/old-client.html'
- >http://dev.mysql.com/doc/mysql/en/old-client.html</a> for help.</b>";
- }
- if( $wgDBmysql5 ) {
- if( $mysqlNewAuth ) {
- print "; enabling MySQL 4.1/5.0 charset mode";
- } else {
- print "; <b class='error'>MySQL 4.1/5.0 charset mode enabled,
- but older version detected; will likely fail.</b>";
+ if ($conf->DBtype == 'mysql') {
+ if( version_compare( $myver, "4.0.0" ) < 0 ) {
+ die( " -- mysql 4.0 or later required. Aborting." );
}
- }
- print "</li>\n";
+ $mysqlNewAuth = version_compare( $myver, "4.1.0", "ge" );
+ if( $mysqlNewAuth && $mysqlOldClient ) {
+ print "; <b class='error'>You are using MySQL 4.1 server, but PHP is linked
+ to old client libraries; if you have trouble with authentication, see
+ <a href='http://dev.mysql.com/doc/mysql/en/old-client.html'
+ >http://dev.mysql.com/doc/mysql/en/old-client.html</a> for help.</b>";
+ }
+ if( $wgDBmysql5 ) {
+ if( $mysqlNewAuth ) {
+ print "; enabling MySQL 4.1/5.0 charset mode";
+ } else {
+ print "; <b class='error'>MySQL 4.1/5.0 charset mode enabled,
+ but older version detected; will likely fail.</b>";
+ }
+ }
+ print "</li>\n";
- if ($conf->DBtype == 'mysql') {
@$sel = mysql_select_db( $wgDBname, $wgDatabase->mConn );
if( $sel ) {
print "<li>Database <tt>" . htmlspecialchars( $wgDBname ) . "</tt> exists</li>\n";
# Create user if required
if ( $conf->Root ) {
- $conn = Database::newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1 );
+ $conn = $dbc->newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1 );
if ( $conn->isOpen() ) {
print "<li>DB user account ok</li>\n";
$conn->close();
dbsource( "../maintenance/tables.sql", $wgDatabase );
}
dbsource( "../maintenance/interwiki.sql", $wgDatabase );
+ } else if ($conf->DBtype == 'postgres') {
+ dbsource( "../maintenance/postgres/tables.sql", $wgDatabase );
+ $wgDatabase->update_interwiki();
} else {
dbsource( "../maintenance/oracle/tables.sql", $wgDatabase );
dbsource( "../maintenance/oracle/interwiki.sql", $wgDatabase );
# Set up the "regular user" account *if we can, and if we need to*
if( $conf->Root ) {
# See if we need to
- $wgDatabase2 = Database::newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1 );
+ $wgDatabase2 = $dbc->newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1 );
if( $wgDatabase2->isOpen() ) {
# Nope, just close the test connection and continue
$wgDatabase2->close();
<ul class='plain'>
<li><?php aField( $conf, "DBtype", "MySQL", "radio", "mysql"); ?></li>
<li><?php aField( $conf, "DBtype", "Oracle (experimental)", "radio", "oracle" ); ?></li>
+ <li><?php aField( $conf, "DBtype", "PostgreSQL", "radio", "postgres" ); ?></li>
</ul>
</div>
?></div>
<p class="config-desc">
If your database server isn't on your web server, enter the name
- or IP address here. MySQL only.
+ or IP address here. MySQL and PostgreSQL only. If using a port for PostgreSQL, enter the number here.
</p>
<div class="config-input"><?php
*/
function incViewCount( $id ) {
$id = intval( $id );
- global $wgHitcounterUpdateFreq;
+ global $wgHitcounterUpdateFreq, $wgDBtype;
$dbw =& wfGetDB( DB_MASTER );
$pageTable = $dbw->tableName( 'page' );
wfProfileIn( 'Article::incViewCount-collect' );
$old_user_abort = ignore_user_abort( true );
- $dbw->query("LOCK TABLES $hitcounterTable WRITE");
- $dbw->query("CREATE TEMPORARY TABLE $acchitsTable TYPE=HEAP ".
+ if ($wgDBtype == 'mysql')
+ $dbw->query("LOCK TABLES $hitcounterTable WRITE");
+ $tabletype = $wgDBtype == 'mysql' ? "ENGINE=HEAP " : '';
+ $dbw->query("CREATE TEMPORARY TABLE $acchitsTable $tabletype".
"SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable ".
'GROUP BY hc_id');
$dbw->query("DELETE FROM $hitcounterTable");
- $dbw->query('UNLOCK TABLES');
+ if ($wgDBtype == 'mysql')
+ $dbw->query('UNLOCK TABLES');
$dbw->query("UPDATE $pageTable,$acchitsTable SET page_counter=page_counter + hc_n ".
'WHERE page_id = hc_id');
$dbw->query("DROP TABLE $acchitsTable");
$cmd = "";
$done = false;
+ $dollarquote = false;
while ( ! feof( $fp ) ) {
$line = trim( fgets( $fp, 1024 ) );
if ( $sl < 0 ) { continue; }
if ( '-' == $line{0} && '-' == $line{1} ) { continue; }
- if ( ';' == $line{$sl} && ($sl < 2 || ';' != $line{$sl - 1})) {
- $done = true;
- $line = substr( $line, 0, $sl );
+ ## Allow dollar quoting for function declarations
+ if (substr($line,0,4) == '$mw$') {
+ if ($dollarquote) {
+ $dollarquote = false;
+ $done = true;
+ }
+ else {
+ $dollarquote = true;
+ }
+ }
+ else if (!$dollarquote) {
+ if ( ';' == $line{$sl} && ($sl < 2 || ';' != $line{$sl - 1})) {
+ $done = true;
+ $line = substr( $line, 0, $sl );
+ }
}
if ( '' != $cmd ) { $cmd .= ' '; }
}
if( $cond == '' ) {
// Optimization hack for full-database dump
- $pageindex = 'FORCE INDEX (PRIMARY)';
- $revindex = 'FORCE INDEX (PRIMARY)';
+ $revindex = $pageindex = $this->db->useIndexClause("PRIMARY");
$straight = ' /*! STRAIGHT_JOIN */ ';
} else {
$pageindex = '';
*/
function &getConnection( $i, $fail = true, $groups = array() )
{
+ global $wgDBtype;
$fname = 'LoadBalancer::getConnection';
wfProfileIn( $fname );
}
}
+ # For now, only go through all this for mysql databases
+ if ($wgDBtype != 'mysql') {
+ $i = $this->getWriterIndex();
+ }
# Operation-based index
- if ( $i == DB_SLAVE ) {
+ elseif ( $i == DB_SLAVE ) {
$i = $this->getReaderIndex();
} elseif ( $i == DB_MASTER ) {
$i = $this->getWriterIndex();
);
$this->mId = !is_null($rev_id) ? $rev_id : $dbw->insertId();
-
wfProfileOut( $fname );
return $this->mId;
}
function isSyndicated() { return false; }
function getSQL() {
+ global $wgDBtype;
$db =& wfGetDB( DB_SLAVE );
$page = $db->tableName( 'page' );
$revision = $db->tableName( 'revision' );
#$use_index = $db->useIndexClause( 'cur_timestamp' ); # FIXME! this is gone
+ $epoch = $wgDBtype == 'mysql' ? 'UNIX_TIMESTAMP(rev_timestamp)' :
+ 'EXTRACT(epoch FROM rev_timestamp)';
return
"SELECT 'Ancientpages' as type,
page_namespace as namespace,
page_title as title,
- UNIX_TIMESTAMP(rev_timestamp) as value
+ $epoch as value
FROM $page, $revision
WHERE page_namespace=".NS_MAIN." AND page_is_redirect=0
AND page_latest=rev_id";
p1.page_title AS title,
pl_namespace,
pl_title
- FROM ($pagelinks, $page AS p1)
- LEFT JOIN $page AS p2
- ON pl_namespace=p2.page_namespace AND pl_title=p2.page_title
- WHERE p1.page_is_redirect=1
- AND pl_from=p1.page_id
- AND p2.page_namespace IS NULL";
+ FROM $pagelinks AS pl
+ JOIN $page p1 ON (p1.page_is_redirect=1 AND pl.pl_from=p1.page_id)
+ LEFT JOIN $page AS p2 ON (pl_namespace=p2.page_namespace AND pl_title=p2.page_title
+ AND p2.page_namespace IS NULL)";
return $sql;
}
wfDebug("Mediawiki:disambiguationspage message does not refer to a template!\n");
}
- $sql = "SELECT 'Disambiguations' AS 'type', pa.page_namespace AS namespace,"
+ $sql = "SELECT 'Disambiguations' AS \"type\", pa.page_namespace AS namespace,"
." pa.page_title AS title, la.pl_from AS value"
." FROM {$templatelinks} AS lb, {$page} AS pa, {$pagelinks} AS la"
." WHERE lb.tl_namespace = $dns AND lb.tl_title = $dtitle" # disambiguation template
"FROM $user ".
"LEFT JOIN $user_groups ON user_id=ug_user " .
$this->userQueryWhere( $dbr ) .
- " GROUP BY user_name";
+ " GROUP BY user_name, user_id";
return $sql;
}
FROM $categorylinks
LEFT JOIN $page ON cl_from = page_id
WHERE page_namespace = " . NS_MAIN . "
- GROUP BY cl_from
+ GROUP BY cl_from, page_namespace, page_title
HAVING COUNT(*) > 1
";
}
pl_namespace AS namespace,
pl_title AS title,
COUNT(*) AS value,
-
page_namespace
FROM $pagelinks
LEFT JOIN $page ON pl_namespace=page_namespace AND pl_title=page_title
- GROUP BY pl_namespace,pl_title
+ GROUP BY pl_namespace,pl_title,page_namespace
HAVING COUNT(*) > 1";
}
FROM $revision
LEFT JOIN $page ON page_id = rev_page
WHERE page_namespace = " . NS_MAIN . "
- GROUP BY rev_page
+ GROUP BY rev_page, page_namespace, page_title
HAVING COUNT(*) > 1
";
}
* Constructor
*/
function wfSpecialRecentchanges( $par, $specialPage ) {
- global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol;
+ global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol, $wgDBtype;
global $wgRCShowWatchingUsers, $wgShowUpdatedMarker;
global $wgAllowCategorizedRecentChanges ;
$fname = 'wfSpecialRecentchanges';
$uid = $wgUser->getID();
// Perform query
- $sql2 = "SELECT * FROM $recentchanges FORCE INDEX (rc_timestamp) " .
+ $forceclause = $dbr->useIndexClause("rc_timestamp");
+ $sql2 = "SELECT * FROM $recentchanges $forceclause".
($uid ? "LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") .
"WHERE rc_timestamp >= '{$cutoff}' {$hidem} " .
"ORDER BY rc_timestamp DESC";
$page = $dbr->tableName( 'page' );
$name = $dbr->addQuotes( $this->getName() );
+ $forceindex = $dbr->useIndexClause("page_len");
return
"SELECT $name as type,
page_namespace as namespace,
page_title as title,
page_len AS value
- FROM $page FORCE INDEX (page_len)
+ FROM $page $forceindex
WHERE page_namespace=".NS_MAIN." AND page_is_redirect=0";
}
}
$sql = "SELECT
- rc_namespace page_namespace,rc_title page_title,
- rc_comment rev_comment, rc_cur_id page_id,
- rc_user rev_user,rc_user_text rev_user_text,
- rc_timestamp rev_timestamp,rc_minor rev_minor_edit,
- rc_this_oldid rev_id,
+ rc_namespace AS page_namespace, rc_title AS page_title,
+ rc_comment AS rev_comment, rc_cur_id AS page_id,
+ rc_user AS rev_user, rc_user_text AS rev_user_text,
+ rc_timestamp AS rev_timestamp, rc_minor AS rev_minor_edit,
+ rc_this_oldid AS rev_id,
rc_last_oldid,
- rc_new page_is_new,wl_notificationtimestamp
+ rc_new AS page_is_new,wl_notificationtimestamp
FROM $watchlist,$recentchanges,$page
WHERE wl_user=$uid
AND wl_namespace=rc_namespace
die( -1 );
}
- if (!extension_loaded('mysql')) {
- if (!dl('mysql.so')) {
- print 'Could not load MySQL driver! Please compile '.
- "php --with-mysql or install the mysql.so module.\n";
+ $gotdatabase = 0;
+ ## XXX We should quiet the warnings thrown here
+ if (extension_loaded('mysql') or dl('mysql.so')) {
+ $gotdatabase = 'mysql';
+ }
+ else if (extension_loaded('pgsql') or dl('pgsql.so')) {
+ $gotdatabase = 'pg';
+ }
+ if (!$gotdatabase) {
+ print "Could not load the MySQL or the PostgreSQL driver! Please compile ".
+ "php with either --with-mysql or --with-pgsql, or install the mysql.so or pg.so module.\n";
exit;
- }
}
global $wgCommandLineMode;