2003-04-14 23:10:40 +00:00
|
|
|
<?
|
|
|
|
|
global $IP;
|
|
|
|
|
include_once( "$IP/FulltextStoplist.php" );
|
2003-08-02 10:13:27 +00:00
|
|
|
include_once( "$IP/CacheManager.php" );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2003-09-20 02:30:00 +00:00
|
|
|
define( "DB_READ", -1 );
|
|
|
|
|
define( "DB_WRITE", -2 );
|
2003-09-20 13:24:31 +00:00
|
|
|
define( "DB_LAST", -3 );
|
2003-09-20 02:30:00 +00:00
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
$wgLastDatabaseQuery = "";
|
|
|
|
|
|
2003-08-09 10:08:23 +00:00
|
|
|
function wfGetDB( $altuser = "", $altpassword = "", $altserver = "", $altdb = "" )
|
2003-04-14 23:10:40 +00:00
|
|
|
{
|
|
|
|
|
global $wgDBserver, $wgDBuser, $wgDBpassword;
|
|
|
|
|
global $wgDBname, $wgDBconnection, $wgEmergencyContact;
|
2003-09-21 13:10:10 +00:00
|
|
|
|
|
|
|
|
$noconn = str_replace( "$1", $wgDBserver, wfMsgNoDB( "noconnect" ) );
|
|
|
|
|
$nodb = str_replace( "$1", $wgDBname, wfMsgNoDB( "nodb" ) );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
|
|
|
|
$helpme = "\n<p>If this error persists after reloading and clearing " .
|
|
|
|
|
"your browser cache, please notify the <a href=\"mailto:" .
|
|
|
|
|
$wgEmergencyContact . "\">Wikipedia developers</a>.</p>";
|
|
|
|
|
|
|
|
|
|
if ( $altuser != "" ) {
|
2003-08-09 10:08:23 +00:00
|
|
|
$serve = ($altserver ? $altserver : $wgDBserver );
|
|
|
|
|
$db = ($altdb ? $altdb : $wgDBname );
|
|
|
|
|
$wgDBconnection = mysql_connect( $serve, $altuser, $altpassword )
|
2003-04-14 23:10:40 +00:00
|
|
|
or die( "bad sql user" );
|
2003-08-09 10:25:30 +00:00
|
|
|
mysql_select_db( $db, $wgDBconnection ) or die(
|
2003-04-14 23:10:40 +00:00
|
|
|
htmlspecialchars(mysql_error()) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( ! $wgDBconnection ) {
|
2003-08-02 10:13:27 +00:00
|
|
|
@$wgDBconnection = mysql_pconnect( $wgDBserver, $wgDBuser, $wgDBpassword )
|
|
|
|
|
or wfEmergencyAbort();
|
|
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
if( !mysql_select_db( $wgDBname, $wgDBconnection ) ) {
|
2003-08-02 10:13:27 +00:00
|
|
|
/* Persistent connections may become stuck in an unusable state */
|
2003-04-14 23:10:40 +00:00
|
|
|
wfDebug( "Persistent connection is broken?\n", true );
|
|
|
|
|
|
2003-08-02 10:13:27 +00:00
|
|
|
@$wgDBconnection = mysql_connect( $wgDBserver, $wgDBuser, $wgDBpassword )
|
|
|
|
|
or wfEmergencyAbort();
|
|
|
|
|
|
2003-08-09 10:25:30 +00:00
|
|
|
@mysql_select_db( $wgDBname, $wgDBconnection )
|
2003-08-02 10:13:27 +00:00
|
|
|
or wfEmergencyAbort();
|
|
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
# mysql_ping( $wgDBconnection );
|
|
|
|
|
return $wgDBconnection;
|
|
|
|
|
}
|
|
|
|
|
|
2003-08-02 10:13:27 +00:00
|
|
|
/* Call this function if we couldn't contact the database...
|
|
|
|
|
We'll try to use the cache to display something in the meantime */
|
|
|
|
|
function wfEmergencyAbort( $msg = "" ) {
|
2003-08-09 10:08:23 +00:00
|
|
|
global $wgTitle, $wgUseFileCache, $title, $wgOutputEncoding;
|
2003-08-02 10:13:27 +00:00
|
|
|
|
2003-08-09 10:08:23 +00:00
|
|
|
header( "Content-type: text/html; charset=$wgOutputEncoding" );
|
2003-09-21 13:10:10 +00:00
|
|
|
if($msg == "") $msg = wfMsgNoDB( "noconnect" );
|
2003-08-02 10:13:27 +00:00
|
|
|
$text = $msg;
|
|
|
|
|
|
|
|
|
|
if($wgUseFileCache) {
|
|
|
|
|
if($wgTitle) {
|
|
|
|
|
$t =& $wgTitle;
|
|
|
|
|
} else {
|
|
|
|
|
if($title) {
|
|
|
|
|
$t = Title::newFromURL( $title );
|
|
|
|
|
} else {
|
2003-09-21 13:10:10 +00:00
|
|
|
$t = Title::newFromText( wfMsgNoDB( "mainpage" ) );
|
2003-08-02 10:13:27 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$cache = new CacheManager( $t );
|
|
|
|
|
if( $cache->isFileCached() ) {
|
|
|
|
|
$msg = "<p style='color: red'><b>$msg<br>\n" .
|
2003-09-21 13:10:10 +00:00
|
|
|
wfMsgNoDB( "cachederror" ) . "</b></p>\n";
|
2003-08-02 10:13:27 +00:00
|
|
|
|
|
|
|
|
$tag = "<div id='article'>";
|
|
|
|
|
$text = str_replace(
|
|
|
|
|
$tag,
|
|
|
|
|
$tag . $msg,
|
|
|
|
|
$cache->fetchPageText() );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Don't cache error pages! They cause no end of trouble... */
|
|
|
|
|
header( "Cache-control: none" );
|
|
|
|
|
header( "Pragma: nocache" );
|
|
|
|
|
echo $text;
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2003-09-20 02:30:00 +00:00
|
|
|
# $db: DB_READ = -1 read from slave (or only server)
|
|
|
|
|
# DB_WRITE = -2 write to master (or only server)
|
|
|
|
|
# 0,1,2,... query a database with a specific index
|
|
|
|
|
# Replication is not actually implemented just yet
|
|
|
|
|
function wfQuery( $sql, $db, $fname = "" )
|
2003-04-14 23:10:40 +00:00
|
|
|
{
|
|
|
|
|
global $wgLastDatabaseQuery, $wgOut;
|
|
|
|
|
## wfProfileIn( "wfQuery" );
|
|
|
|
|
$wgLastDatabaseQuery = $sql;
|
|
|
|
|
$conn = wfGetDB();
|
|
|
|
|
$ret = mysql_query( $sql, $conn );
|
|
|
|
|
|
|
|
|
|
if ( "" != $fname ) {
|
|
|
|
|
# wfDebug( "{$fname}:SQL: {$sql}\n", true );
|
|
|
|
|
} else {
|
|
|
|
|
# wfDebug( "SQL: {$sql}\n", true );
|
|
|
|
|
}
|
|
|
|
|
if ( false === $ret ) {
|
|
|
|
|
$wgOut->databaseError( $fname );
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
## wfProfileOut();
|
|
|
|
|
return $ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function wfFreeResult( $res ) { mysql_free_result( $res ); }
|
|
|
|
|
function wfFetchObject( $res ) { return mysql_fetch_object( $res ); }
|
|
|
|
|
function wfNumRows( $res ) { return mysql_num_rows( $res ); }
|
|
|
|
|
function wfNumFields( $res ) { return mysql_num_fields( $res ); }
|
|
|
|
|
function wfFieldName( $res, $n ) { return mysql_field_name( $res, $n ); }
|
|
|
|
|
function wfInsertId() { return mysql_insert_id( wfGetDB() ); }
|
|
|
|
|
function wfDataSeek( $res, $row ) { return mysql_data_seek( $res, $row ); }
|
|
|
|
|
function wfLastErrno() { return mysql_errno(); }
|
|
|
|
|
function wfLastError() { return mysql_error(); }
|
2003-08-17 11:58:33 +00:00
|
|
|
function wfAffectedRows() { return mysql_affected_rows( wfGetDB() ); }
|
2003-04-14 23:10:40 +00:00
|
|
|
|
|
|
|
|
function wfLastDBquery()
|
|
|
|
|
{
|
|
|
|
|
global $wgLastDatabaseQuery;
|
|
|
|
|
return $wgLastDatabaseQuery;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function wfSetSQL( $table, $var, $value, $cond )
|
|
|
|
|
{
|
|
|
|
|
$sql = "UPDATE $table SET $var = '" .
|
|
|
|
|
wfStrencode( $value ) . "' WHERE ($cond)";
|
2003-09-20 02:30:00 +00:00
|
|
|
wfQuery( $sql, DB_WRITE, "wfSetSQL" );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function wfGetSQL( $table, $var, $cond )
|
|
|
|
|
{
|
|
|
|
|
$sql = "SELECT $var FROM $table WHERE ($cond)";
|
2003-09-20 13:24:31 +00:00
|
|
|
$result = wfQuery( $sql, DB_READ, "wfGetSQL" );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
|
|
|
|
$ret = "";
|
|
|
|
|
if ( mysql_num_rows( $result ) > 0 ) {
|
|
|
|
|
$s = mysql_fetch_object( $result );
|
|
|
|
|
$ret = $s->$var;
|
|
|
|
|
mysql_free_result( $result );
|
|
|
|
|
}
|
|
|
|
|
return $ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function wfStrencode( $s )
|
|
|
|
|
{
|
|
|
|
|
return addslashes( $s );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Ideally we'd be using actual time fields in the db
|
|
|
|
|
function wfTimestamp2Unix( $ts ) {
|
2003-06-30 01:33:16 +00:00
|
|
|
return gmmktime( ( (int)substr( $ts, 8, 2) ),
|
2003-04-14 23:10:40 +00:00
|
|
|
(int)substr( $ts, 10, 2 ), (int)substr( $ts, 12, 2 ),
|
|
|
|
|
(int)substr( $ts, 4, 2 ), (int)substr( $ts, 6, 2 ),
|
|
|
|
|
(int)substr( $ts, 0, 4 ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function wfUnix2Timestamp( $unixtime ) {
|
2003-06-30 01:33:16 +00:00
|
|
|
return gmdate( "YmdHis", $unixtime );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function wfTimestampNow() {
|
|
|
|
|
# return NOW
|
2003-06-30 01:33:16 +00:00
|
|
|
return gmdate( "YmdHis" );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Sorting hack for MySQL 3, which doesn't use index sorts for DESC
|
|
|
|
|
function wfInvertTimestamp( $ts ) {
|
|
|
|
|
return strtr(
|
|
|
|
|
$ts,
|
|
|
|
|
"0123456789",
|
|
|
|
|
"9876543210"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|