From 144cbe5bd6c4cad4d66d5bbd9ee0931f8b26c9df Mon Sep 17 00:00:00 2001 From: Gabriel Wicke Date: Fri, 30 Jan 2004 17:07:50 +0000 Subject: [PATCH] Squid integration changes --- LocalSettings.sample | 11 +++ includes/Article.php | 159 +++++++++++++++++++++++----------- includes/DefaultSettings.php | 11 +++ includes/EditPage.php | 8 +- includes/GlobalFunctions.php | 81 +++++++++++++++++ includes/OutputPage.php | 24 +++-- includes/Setup.php | 23 ++--- includes/Skin.php | 12 +-- includes/SpecialUserlogin.php | 11 ++- includes/UpdateClasses.php | 1 + includes/User.php | 35 +++++--- wiki.phtml | 6 ++ 12 files changed, 285 insertions(+), 97 deletions(-) diff --git a/LocalSettings.sample b/LocalSettings.sample index b79131f9e7..4e976dca16 100644 --- a/LocalSettings.sample +++ b/LocalSettings.sample @@ -127,4 +127,15 @@ $wgOutputEncoding = "ISO-8859-1"; # $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'); ?> diff --git a/includes/Article.php b/includes/Article.php index d496e39503..93e48715cb 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -405,7 +405,7 @@ class Article { $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) { @@ -544,7 +544,14 @@ class Article { $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 @@ -988,42 +995,7 @@ class Article { } } - # 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() { @@ -1234,33 +1206,122 @@ class Article { # # 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); } } } diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index bf5c75584e..67e6e1f965 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -138,6 +138,17 @@ $wgFileCacheDirectory = "{$wgUploadDirectory}/cache"; $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 = ""; diff --git a/includes/EditPage.php b/includes/EditPage.php index fdee8411ce..e58f217631 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -349,7 +349,7 @@ $wgLang->recodeForEdit( $wpTextbox1 ) . function blockedIPpage() { - global $wgOut, $wgUser, $wgLang; + global $wgOut, $wgUser, $wgLang, $wgIP; $wgOut->setPageTitle( wfMsg( "blockedtitle" ) ); $wgOut->setRobotpolicy( "noindex,nofollow" ); @@ -357,9 +357,9 @@ $wgLang->recodeForEdit( $wpTextbox1 ) . $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}]]"; diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 782fb7b575..3a93b4e17e 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -739,4 +739,85 @@ function wfArrayToCGI( $array1, $array2 = NULL ) 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; +} ?> diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 2585c5de4c..03c50c9bd4 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -63,8 +63,10 @@ class OutputPage { 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"] ) ) { @@ -79,8 +81,6 @@ class OutputPage { 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(); @@ -248,23 +248,21 @@ class OutputPage { } 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 diff --git a/includes/Setup.php b/includes/Setup.php index 1d67e77ec5..4a210d356e 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -17,6 +17,16 @@ if ( $wgProfiling and (0 == rand() % $wgProfileSampleRate ) ) { 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; @@ -119,17 +129,8 @@ if ( $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(); diff --git a/includes/Skin.php b/includes/Skin.php index bc2eb5e908..3cd3445f65 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -528,15 +528,15 @@ class Skin { 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}", @@ -579,7 +579,7 @@ class Skin { { global $search; - $s = "
" . "\n" @@ -684,7 +684,7 @@ class Skin { else { $a = ""; } $mp = wfMsg( "mainpage" ); - $s = "getLogo() . "\" alt=\"" . "[{$mp}]\">"; return $s; @@ -2200,7 +2200,7 @@ class Skin { 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 "{$head}"; } diff --git a/includes/SpecialUserlogin.php b/includes/SpecialUserlogin.php index 186521b9da..0451b9bdda 100644 --- a/includes/SpecialUserlogin.php +++ b/includes/SpecialUserlogin.php @@ -4,7 +4,10 @@ function wfSpecialUserlogin() { 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" ); @@ -212,7 +215,7 @@ function wfSpecialUserlogin() /* private */ function mailPasswordInternal( $u ) { global $wpName, $wgDeferredUpdateList, $wgOutputEncoding; - global $wgPasswordSender, $wgDBname; + global $wgPasswordSender, $wgDBname, $wgIP; if ( "" == $u->getEmail() ) { mainLoginForm( wfMsg( "noemail", $u->getName() ) ); @@ -224,8 +227,8 @@ function wfSpecialUserlogin() 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 ); diff --git a/includes/UpdateClasses.php b/includes/UpdateClasses.php index 8e2e17c6cc..10e11a36f6 100644 --- a/includes/UpdateClasses.php +++ b/includes/UpdateClasses.php @@ -6,5 +6,6 @@ include_once( "SiteStatsUpdate.php" ); include_once( "LinksUpdate.php" ); include_once( "SearchUpdate.php" ); include_once( "UserTalkUpdate.php" ); +include_once( "SquidUpdate.php" ); ?> diff --git a/includes/User.php b/includes/User.php index b0f0db7936..a528e3aea4 100644 --- a/includes/User.php +++ b/includes/User.php @@ -70,11 +70,11 @@ class User { 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(); @@ -94,7 +94,7 @@ class User { /* private */ function getBlockedStatus() { - global $wgBadRanges, $wgBadUserAgents, $wgRangeBlockUser, $wgRangeBlockReason; + global $wgBadRanges, $wgBadUserAgents, $wgRangeBlockUser, $wgRangeBlockReason, $wgIP; if ( -1 != $this->mBlockedby ) { return; } @@ -105,7 +105,7 @@ class User { 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] ); @@ -125,8 +125,8 @@ class User { # 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; } @@ -152,6 +152,21 @@ class User { 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; @@ -572,6 +587,7 @@ class User { 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"; @@ -587,8 +603,7 @@ class User { } # 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(); @@ -596,8 +611,8 @@ class User { } # 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 ); diff --git a/wiki.phtml b/wiki.phtml index 86605c8fb6..fa0374085b 100644 --- a/wiki.phtml +++ b/wiki.phtml @@ -55,6 +55,9 @@ wfProfileOut( "main-misc-setup" ); 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 ) { @@ -93,6 +96,9 @@ if( !$wgTitle or $wgTitle->getInterwiki() != "" or $wgTitle->getDBkey() == "" ) 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(); -- 2.20.1