# $wgWhitelistEdit = true;
# $wgWhitelistRead = false;
# $wgWhitelistAccount = array ( "user" => 0, "sysop" => 1, "developer" => 1 );
+
+
+# Squid-related settings
+#
+# Enable/disable Squid
+# $wgUseSquid = true;
+# Internal server name as known to Squid, if different
+# $wgInternalServer = 'http://yourinternal.tld.:8000';
+# A list of proxy servers (ips if possible) to purge on changes
+# don't specify ports here (80 is default)
+# $wgSquidServers = array('127.0.0.1');
?>
$newid = wfInsertId();
$this->mTitle->resetArticleID( $newid );
- Article::onArticleCreate( $this->mTitle );
+ Article::onArticleCreate( $this->mTitle, $text );
RecentChange::notifyNew( $now, $this->mTitle, $isminor, $wgUser, $summary );
if ($watchthis) {
$wgOut = new OutputPage();
$wgOut->addWikiText( $text );
- $this->editUpdates( $text );
+ # Every 1000th edit, prune the recent changes table.
+ wfSeedRandom();
+ if ( 0 == mt_rand( 0, 999 ) ) {
+ $cutoff = wfUnix2Timestamp( time() - ( 7 * 86400 ) );
+ $sql = "DELETE FROM recentchanges WHERE rc_timestamp < '{$cutoff}'";
+ wfQuery( $sql, DB_WRITE );
+ }
+
if( $wgMwRedir->matchStart( $text ) )
$r = "redirect=no";
else
}
}
- # Do standard deferred updates after page edit.
- # Every 1000th edit, prune the recent changes table.
- /* private */ function editUpdates( $text )
- {
- global $wgDeferredUpdateList, $wgDBname, $wgMemc;
- global $wgMessageCache;
-
- wfSeedRandom();
- if ( 0 == mt_rand( 0, 999 ) ) {
- $cutoff = wfUnix2Timestamp( time() - ( 7 * 86400 ) );
- $sql = "DELETE FROM recentchanges WHERE rc_timestamp < '{$cutoff}'";
- wfQuery( $sql, DB_WRITE );
- }
- $id = $this->getID();
- $title = $this->mTitle->getPrefixedDBkey();
- $shortTitle = $this->mTitle->getDBkey();
-
- $adj = $this->mCountAdjustment;
-
- if ( 0 != $id ) {
- $u = new LinksUpdate( $id, $title );
- array_push( $wgDeferredUpdateList, $u );
- $u = new SiteStatsUpdate( 0, 1, $adj );
- array_push( $wgDeferredUpdateList, $u );
- $u = new SearchUpdate( $id, $title, $text );
- array_push( $wgDeferredUpdateList, $u );
-
- $u = new UserTalkUpdate( 1, $this->mTitle->getNamespace(), $shortTitle );
- array_push( $wgDeferredUpdateList, $u );
-
- if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
- $wgMessageCache->replace( $shortTitle, $text );
- }
- }
- }
/* private */ function setOldSubtitle()
{
#
# This is a good place to put code to clear caches, for instance.
- /* static */ function onArticleCreate($title_obj){
- global $wgEnablePersistentLC, $wgEnableParserCache;
+ /* static */ function onArticleCreate($title_obj,$text=''){
+ global $wgEnablePersistentLC, $wgEnableParserCache, $wgUseSquid;
+ global $wgDeferredUpdateList, $wgDBname, $wgMemc;
+ global $wgMessageCache, $wgInternalServer;
+ # Do standard deferred updates after page edit.
+ $id = $title_obj->getArticleID();
+ $title = $title_obj->getPrefixedDBkey();
+ $shortTitle = $title_obj->getDBkey();
+
+ $adj = $this->mCountAdjustment;
+
+ if ( 0 != $id ) {
+ $u = new LinksUpdate( $id, $title );
+ array_push( $wgDeferredUpdateList, $u );
+ $u = new SiteStatsUpdate( 0, 1, $adj );
+ array_push( $wgDeferredUpdateList, $u );
+ $u = new SearchUpdate( $id, $title, $text );
+ array_push( $wgDeferredUpdateList, $u );
+
+ $u = new UserTalkUpdate( 1, $this->mTitle->getNamespace(), $shortTitle );
+ array_push( $wgDeferredUpdateList, $u );
+
+ if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
+ $wgMessageCache->replace( $shortTitle, $text );
+ }
+ }
if ( $wgEnablePersistentLC ) {
- LinkCache::linksccClearBrokenLinksTo( $title_obj->getPrefixedDBkey() );
+ LinkCache::linksccClearBrokenLinksTo( $title );
}
if ( $wgEnableParserCache ) {
- OutputPage::parsercacheClearBrokenLinksTo( $title_obj->getPrefixedDBkey() );
+ OutputPage::parsercacheClearBrokenLinksTo( $title );
+ }
+ if ( $wgUseSquid ) {
+ $urlArr = Array(
+ $wgInternalServer.wfLocalUrl( $title_obj->getPrefixedURL())
+ );
+ wfPurgeSquidServers($urlArr);
+ /* this needs to be done after LinksUpdate */
+ $u = new SquidUpdate($title_obj);
+ array_push( $wgDeferredUpdateList, $u );
}
}
- /* static */ function onArticleDelete($title_obj){
- global $wgEnablePersistentLC, $wgEnableParserCache;
+ /* static */ function onArticleDelete($title_obj,$text=''){
+ global $wgEnablePersistentLC, $wgEnableParserCache, $wgUseSquid, $wgDeferredUpdateList;
+ global $wgDeferredUpdateList, $wgDBname, $wgMemc;
+ global $wgMessageCache, $wgInternalServer;
+
+ $id = $title_obj->getArticleID();
+ $title = $title_obj->getPrefixedDBkey();
+ $shortTitle = $title_obj->getDBkey();
+
if ( $wgEnablePersistentLC ) {
- LinkCache::linksccClearLinksTo( $title_obj->getArticleID() );
+ LinkCache::linksccClearLinksTo( $id );
}
if ( $wgEnableParserCache ) {
- OutputPage::parsercacheClearLinksTo( $title_obj->getArticleID() );
+ OutputPage::parsercacheClearLinksTo( $id );
+ }
+ if ( $wgUseSquid ) {
+ $urlArr = Array(
+ $wgInternalServer.wfLocalUrl( $title_obj->getPrefixedURL())
+ );
+ wfPurgeSquidServers($urlArr);
+
+ /* prepare the list of urls to purge */
+ $sql = "SELECT l_from FROM links WHERE l_to={$id}" ;
+ $res = wfQuery ( $sql, DB_READ ) ;
+ while ( $BL = wfFetchObject ( $res ) )
+ {
+ $t = Title::newFromDBkey( $BL->l_from) ;
+ $blurlArr[] = $wgInternalServer.wfLocalUrl( $t->getPrefixedURL() );
+ }
+ wfFreeResult ( $res ) ;
+ $u = new SquidUpdate( $title_obj, $blurlArr );
+ array_push( $wgDeferredUpdateList, $u );
+
}
}
- /* static */ function onArticleEdit($title_obj){
- global $wgEnablePersistentLC, $wgEnableParserCache;
+ /* static */ function onArticleEdit($title_obj,$text=''){
+ global $wgEnablePersistentLC, $wgEnableParserCache, $wgUseSquid;
+ global $wgDeferredUpdateList, $wgDBname, $wgMemc;
+ global $wgMessageCache, $wgInternalServer;
+
+ $id = $title_obj->getArticleID();
+ $title = $title_obj->getPrefixedDBkey();
+ $shortTitle = $title_obj->getDBkey();
+
+ $adj = $this->mCountAdjustment;
+
+ if ( 0 != $id ) {
+ $u = new LinksUpdate( $id, $title );
+ array_push( $wgDeferredUpdateList, $u );
+ $u = new SiteStatsUpdate( 0, 1, $adj );
+ array_push( $wgDeferredUpdateList, $u );
+ $u = new SearchUpdate( $id, $title, $text );
+ array_push( $wgDeferredUpdateList, $u );
+
+ $u = new UserTalkUpdate( 1, $this->mTitle->getNamespace(), $shortTitle );
+ array_push( $wgDeferredUpdateList, $u );
+
+ if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
+ $wgMessageCache->replace( $shortTitle, $text );
+ }
+ }
if ( $wgEnablePersistentLC ) {
- LinkCache::linksccClearPage( $title_obj->getArticleID() );
+ LinkCache::linksccClearPage( $id );
}
if ( $wgEnableParserCache ) {
- OutputPage::parsercacheClearPage( $title_obj->getArticleID() );
+ OutputPage::parsercacheClearPage( $id );
+ }
+ if ( $wgUseSquid ) {
+ $urlArr = Array(
+ $wgInternalServer.wfLocalUrl( $title_obj->getPrefixedURL()),
+ );
+ wfPurgeSquidServers($urlArr);
}
}
}
$wgCookieExpiration = 2592000;
+# Squid-related settings
+#
+# Enable/disable Squid
+ $wgUseSquid = false;
+# Internal server name as known to Squid, if different
+# $wgInternalServer = 'http://yourinternal.tld.:8000';
+ $wgInternalServer = $wgServer;
+# A list of proxy servers (ips if possible) to purge on changes
+# don't specify ports here (80 is default)
+# $wgSquidServers = array('127.0.0.1');
+
# Set to set an explicit domain on the login cookies
# eg, "justthis.domain.org" or ".any.subdomain.net"
$wgCookieDomain = "";
function blockedIPpage()
{
- global $wgOut, $wgUser, $wgLang;
+ global $wgOut, $wgUser, $wgLang, $wgIP;
$wgOut->setPageTitle( wfMsg( "blockedtitle" ) );
$wgOut->setRobotpolicy( "noindex,nofollow" );
$id = $wgUser->blockedBy();
$reason = $wgUser->blockedFor();
- $ip = getenv( "REMOTE_ADDR" );
-
- $name = User::whoIs( $id );
+ $ip = $wgIP;
+
+ $name = User::whoIs( $id );
$link = "[[" . $wgLang->getNsText( Namespace::getUser() ) .
":{$name}|{$name}]]";
return $cgi;
}
+/* Purges a list of Squids defined in $wgSquidServers.
+$urlArr should contain the full URLs to purge as values
+(example: $urlArr[] = 'http://my.host/something')
+XXX report broken Squids per mail or log */
+
+function wfPurgeSquidServers ($urlArr) {
+ global $wgSquidServers;
+ $maxsocketspersquid = 8; // socket cap per Squid
+ $urlspersocket = 400; // 400 seems to be a good tradeoff, opening a socket takes a while
+ $sockspersq = ceil(count($urlArr) / $urlspersocket );
+ if ($sockspersq == 1) {
+ /* the most common case */
+ $urlspersocket = count($urlArr);
+ } else if ($sockspersq > $maxsocketspersquid ) {
+ $urlspersocket = ceil(count($urlArr) / $maxsocketspersquid);
+ $sockspersq = $maxsocketspersquid;
+ }
+ $totalsockets = count($wgSquidServers) * $sockspersq;
+ $sockets = Array();
+ $t = microtime(1);
+
+ /* this sets up the sockets and tests the first socket for each server. */
+ for ($ss=0;$ss < count($wgSquidServers);$ss++) {
+ $failed = false;
+ $so = 0;
+ while ($so < $sockspersq && !$failed) {
+ if ($so == 0) {
+ /* first socket for this server, do the tests */
+ $socket = @fsockopen($wgSquidServers[$ss], 80, $error, $errstr, 3);
+ if (!$socket) {
+ $failed = true;
+ $totalsockets -= $sockspersq;
+ } else {
+ @fputs($socket,"PURGE " . $urlArr[0] . " HTTP/1.0\r\n".
+ "Connection: Keep-Alive\r\n\r\n");
+ $res = '';
+ while (strlen($res) < 230 ) {
+ $res .= @fread($socket,512);
+ }
+ /* Squid only returns http headers with 200 or 404 status,
+ if there's more returned something's wrong */
+ if (strlen($res) > 250) {
+ fclose($socket);
+ $failed = true;
+ $totalsockets -= $sockspersq;
+ } else {
+ @stream_set_blocking($socket,false);
+ $sockets[] = $socket;
+ }
+ }
+ } else {
+ /* open the remaining sockets for this server */
+ $sockets[] = @fsockopen($wgSquidServers[$ss], 80, $error, $errstr, 2);
+ @stream_set_blocking($sockets[$s],false);
+ }
+ $so++;
+ }
+ }
+
+ if ($urlspersocket > 1) {
+ /* now do the heavy lifting. The fread() relies on Squid returning only the headers */
+ for ($r=0;$r < $urlspersocket;$r++) {
+ for ($s=0;$s < $totalsockets;$s++) {
+ if($r != 0) {
+ $res = '';
+ while (strlen($res) < 230 ) {
+ $res .= @fread($sockets[$s],512);
+ }
+ }
+ $urindex = $r + $urlspersocket * ($s - $sockspersq * floor($s / $sockspersq));
+ @fputs($sockets[$s],"PURGE " . $urlArr[$urindex] . " HTTP/1.0\r\n".
+ "Connection: Keep-Alive\r\n\r\n");
+ }
+ }
+ }
+
+ foreach ($sockets as $socket) {
+ @fclose($sockets);
+ }
+ return;
+}
?>
wfDebug( "USER DISABLED CACHE\n", false );
return;
}
-
- $lastmod = gmdate( "D, j M Y H:i:s", wfTimestamp2Unix(
+
+ $this->sendCacheControl();
+
+ $lastmod = gmdate( "D, j M Y H:i:s", wfTimestamp2Unix(
max( $timestamp, $wgUser->mTouched ) ) ) . " GMT";
if( !empty( $_SERVER["HTTP_IF_MODIFIED_SINCE"] ) ) {
if( ($ismodsince >= $timestamp ) and $wgUser->validateCache( $ismodsince ) ) {
# Make sure you're in a place you can leave when you call us!
header( "HTTP/1.0 304 Not Modified" );
- header( "Expires: Mon, 15 Jan 2001 00:00:00 GMT" ); # Cachers always validate the page!
- header( "Cache-Control: private, must-revalidate, max-age=0" );
header( "Last-Modified: {$lastmod}" );
wfDebug( "CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
$this->disable();
}
function sendCacheControl() {
- global $wgUseGzip;
+ header( "Vary: Accept-Encoding, Cookie" );
if( $this->mLastModified != "" ) {
- wfDebug( "** private caching; {$this->mLastModified} **\n", false );
- header( "Cache-Control: private, must-revalidate, max-age=0" );
+ wfDebug( "** private caching; {$this->mLastModified} **\n", false );
+ if (isset($_COOKIE[ini_get("session.name")] )){
+ header( "Cache-Control: no-cache, must-revalidate, max-age=0" );
+ } else {
+ header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
+ }
header( "Last-modified: {$this->mLastModified}" );
- if( $wgUseGzip ) {
- # We should put in Accept-Encoding, but IE chokes on anything but
- # User-Agent in a Vary: header (at least through 6.0)
- header( "Vary: User-Agent" );
- }
} else {
wfDebug( "** no caching **\n", false );
header( "Cache-Control: no-cache" ); # Experimental - see below
header( "Pragma: no-cache" );
header( "Last-modified: " . gmdate( "D, j M Y H:i:s" ) . " GMT" );
}
- header( "Expires: Mon, 15 Jan 2001 00:00:00 GMT" ); # Cachers always validate the page!
}
# Finally, all the text has been munged and accumulated into
function wfProfileClose() {}
}
+
+
+/* collect the originating ips */
+if ($_SERVER["HTTP_X_FORWARDED_FOR"]) {
+ $wgIP = trim(preg_replace("/^(.*, )?([^,]+)$/", "$2",
+ $_SERVER['HTTP_X_FORWARDED_FOR']));
+} else {
+ $wgIP = getenv("REMOTE_ADDR");
+}
+
$fname = "Setup.php";
wfProfileIn( $fname );
global $wgUseDynamicDates;
$wgDateFormatter = new DateFormatter;
}
-if( !$wgCommandLineMode ) {
- if( $wgSessionsInMemcached ) {
- include_once( "MemcachedSessions.php" );
- }
- session_set_cookie_params( 0, $wgCookiePath, $wgCookieDomain );
- session_cache_limiter( "private, must-revalidate" );
- session_start();
- session_register( "wsUserID" );
- session_register( "wsUserName" );
- session_register( "wsUserPassword" );
- session_register( "wsUploadFiles" );
+if( !$wgCommandLineMode && isset( $_COOKIE[ini_get("session.name")] ) ) {
+ User::SetupSession();
}
$wgUser = User::loadFromSession();
function nameAndLogin()
{
- global $wgUser, $wgTitle, $wgLang, $wgShowIPinHeader;
+ global $wgUser, $wgTitle, $wgLang, $wgShowIPinHeader, $wgIP;
$li = $wgLang->specialPage( "Userlogin" );
$lo = $wgLang->specialPage( "Userlogout" );
$s = "";
if ( 0 == $wgUser->getID() ) {
- if( $wgShowIPinHeader ) {
- $n = getenv( "REMOTE_ADDR" );
+ if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
+ $n = $wgIP;
$tl = $this->makeKnownLink( $wgLang->getNsText(
Namespace::getTalk( Namespace::getUser() ) ) . ":{$n}",
{
global $search;
- $s = "<form name='search' class='inline' method=get action=\""
+ $s = "<form name='search' class='inline' method=post action=\""
. wfLocalUrl( "" ) . "\">"
. "<input type=text name=\"search\" size=19 value=\""
. htmlspecialchars(substr($search,0,256)) . "\">\n"
else { $a = ""; }
$mp = wfMsg( "mainpage" );
- $s = "<a href=\"" . wfLocalUrlE( urlencode( $mp ) )
+ $s = "<a href=\"" . wfLocalUrlE( urlencode( str_replace(' ','_',$mp) ) )
. "\"><img{$a} border=0 src=\""
. $this->getLogo() . "\" alt=\"" . "[{$mp}]\"></a>";
return $s;
global $wgTitle,$wgUser,$oldid;
if($oldid) return $head;
- $url = wfLocalUrlE(urlencode($wgTitle->getPrefixedText()),"action=edit§ion=$section");
+ $url = wfLocalUrlE(urlencode(str_replace(' ','_',$wgTitle->getPrefixedText())),"action=edit§ion=$section");
return "<span onContextMenu='document.location=\"".$url."\";return false;'>{$head}</span>";
}
{
global $wpCreateaccount, $wpCreateaccountMail;
global $wpLoginattempt, $wpMailmypassword;
- global $action, $_REQUEST;
+ global $action, $_REQUEST, $wgCommandLineMode;
+ if( !$wgCommandLineMode && !isset( $_COOKIE[ini_get("session.name")] ) ) {
+ User::SetupSession();
+ }
$fields = array( "wpName", "wpPassword", "wpName",
"wpPassword", "wpRetype", "wpEmail" );
/* private */ function mailPasswordInternal( $u )
{
global $wpName, $wgDeferredUpdateList, $wgOutputEncoding;
- global $wgPasswordSender, $wgDBname;
+ global $wgPasswordSender, $wgDBname, $wgIP;
if ( "" == $u->getEmail() ) {
mainLoginForm( wfMsg( "noemail", $u->getName() ) );
setcookie( "{$wgDBname}Password", "", time() - 3600, $wgCookiePath, $wgCookieDomain );
$u->saveSettings();
- $ip = getenv( "REMOTE_ADDR" );
- if ( "" == $ip ) { $ip = "(Unknown)"; }
+ $ip = $wgIP;
+ if ( "" == $ip ) { $ip = "(Unknown)"; }
$m = wfMsg( "passwordremindertext", $ip, $u->getName(), $np );
include_once( "LinksUpdate.php" );
include_once( "SearchUpdate.php" );
include_once( "UserTalkUpdate.php" );
+include_once( "SquidUpdate.php" );
?>
function loadDefaults()
{
- global $wgLang ;
+ global $wgLang, $wgIP;
global $wgNamespacesToBeSearchedDefault;
$this->mId = $this->mNewtalk = 0;
- $this->mName = getenv( "REMOTE_ADDR" );
+ $this->mName = $wgIP;
$this->mEmail = "";
$this->mPassword = $this->mNewpassword = "";
$this->mRights = array();
/* private */ function getBlockedStatus()
{
- global $wgBadRanges, $wgBadUserAgents, $wgRangeBlockUser, $wgRangeBlockReason;
+ global $wgBadRanges, $wgBadUserAgents, $wgRangeBlockUser, $wgRangeBlockReason, $wgIP;
if ( -1 != $this->mBlockedby ) { return; }
array_key_exists( getenv( "HTTP_USER_AGENT" ), $wgBadUserAgents ) ) &&
is_array( $wgBadRanges ) )
{
- $iIp = ip2long( getenv( "REMOTE_ADDR" ) );
+ $iIp = ip2long( $wgIP );
foreach ( $wgBadRanges as $range ) {
$start = ip2long( $range[0] );
$end = ip2long( $range[1] );
# User/IP blocking
$block = new Block();
- if ( !$block->load( getenv( "REMOTE_ADDR" ), $this->mId ) ) {
- wfDebug( getenv( "REMOTE_ADDR" ) ." is not blocked\n" );
+ if ( !$block->load( $wgIP , $this->mId ) ) {
+ wfDebug( $wgIP ." is not blocked\n" );
$this->mBlockedby = 0;
return;
}
return $this->mBlockreason;
}
+ function SetupSession() {
+ global $wgSessionsInMemcached, $wgCookiePath, $wgCookieDomain;
+ global $wsUserID, $wsUserName, $wsUserPassword, $wsUploadFiles;
+ if( $wgSessionsInMemcached ) {
+ include_once( "MemcachedSessions.php" );
+ }
+ session_set_cookie_params( 0, $wgCookiePath, $wgCookieDomain );
+ session_cache_limiter( "private, must-revalidate" );
+ session_start();
+ session_register( "wsUserID" );
+ session_register( "wsUserName" );
+ session_register( "wsUserPassword" );
+ session_register( "wsUploadFiles" );
+ }
+
/* static */ function loadFromSession()
{
global $HTTP_COOKIE_VARS, $wsUserID, $wsUserName, $wsUserPassword;
function spreadBlock()
{
+ global $wgIP;
# If the (non-anonymous) user is blocked, this function will block any IP address
# that they successfully log on from.
$fname = "User::spreadBlock";
}
# Check if this IP address is already blocked
- $addr = getenv( "REMOTE_ADDR" );
- $ipblock = Block::newFromDB( $addr );
+ $ipblock = Block::newFromDB( $wgIP );
if ( $ipblock->isValid() ) {
# Just update the timestamp
$ipblock->updateTimestamp();
}
# Make a new block object with the desired properties
- wfDebug( "Autoblocking {$this->mUserName}@{$addr}\n" );
- $ipblock->mAddress = $addr;
+ wfDebug( "Autoblocking {$this->mUserName}@{$wgIP}\n" );
+ $ipblock->mAddress = $wgIP;
$ipblock->mUser = 0;
$ipblock->mBy = $userblock->mBy;
$ipblock->mReason = wfMsg( "autoblocker", $this->getName(), $userblock->mReason );
if( !$wgTitle or $wgTitle->getInterwiki() != "" or $wgTitle->getDBkey() == "" ) {
$wgTitle = Title::newFromText( wfMsg( "badtitle" ) );
$wgOut->errorpage( "badtitle", "badtitletext" );
+} else if ( $wgTitle->getPrefixedDBKey() != $title ) {
+ /* redirect to canonical url */
+ $wgOut->redirect( wfLocalUrl( $wgTitle->getPrefixedURL() ) );
} else if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) {
wfSpecialPage();
} else if ( "" != $search ) {
break;
case "edit":
case "submit":
+ if( !$wgCommandLineMode && !isset( $_COOKIE[ini_get("session.name")] ) ) {
+ User::SetupSession();
+ }
include_once( "EditPage.php" );
$editor = new EditPage( $wgArticle );
$editor->$action();