$this->edittime = $this->mArticle->getTimestamp();
$this->textbox1 = $this->mArticle->getContent( true );
$this->summary = '';
- $this->proxyCheck();
+ wfProxyCheck();
}
/**
* @todo document
*/
function blockedIPpage() {
- global $wgOut, $wgUser, $wgContLang, $wgIP;
+ global $wgOut, $wgUser, $wgContLang;
$wgOut->setPageTitle( wfMsg( 'blockedtitle' ) );
$wgOut->setRobotpolicy( 'noindex,nofollow' );
$id = $wgUser->blockedBy();
$reason = $wgUser->blockedFor();
- $ip = $wgIP;
+ $ip = wfGetIP();
if ( is_numeric( $id ) ) {
$name = User::whoIs( $id );
$wgOut->returnToMain( false );
}
- /**
- * Forks processes to scan the originating IP for an open proxy server
- * MemCached can be used to skip IPs that have already been scanned
- */
- function proxyCheck() {
- global $wgBlockOpenProxies, $wgProxyPorts, $wgProxyScriptPath;
- global $wgIP, $wgUseMemCached, $wgMemc, $wgDBname, $wgProxyMemcExpiry;
-
- if ( !$wgBlockOpenProxies ) {
- return;
- }
-
- # Get MemCached key
- $skip = false;
- if ( $wgUseMemCached ) {
- $mcKey = $wgDBname.':proxy:ip:'.$wgIP;
- $mcValue = $wgMemc->get( $mcKey );
- if ( $mcValue ) {
- $skip = true;
- }
- }
-
- # Fork the processes
- if ( !$skip ) {
- $title = Title::makeTitle( NS_SPECIAL, 'Blockme' );
- $iphash = md5( $wgIP . $wgProxyKey );
- $url = $title->getFullURL( 'ip='.$iphash );
-
- foreach ( $wgProxyPorts as $port ) {
- $params = implode( ' ', array(
- escapeshellarg( $wgProxyScriptPath ),
- escapeshellarg( $wgIP ),
- escapeshellarg( $port ),
- escapeshellarg( $url )
- ));
- exec( "php $params &>/dev/null &" );
- }
- # Set MemCached key
- if ( $wgUseMemCached ) {
- $wgMemc->set( $mcKey, 1, $wgProxyMemcExpiry );
- }
- }
- }
-
/**
* @access private
* @todo document
/** Work out the IP address based on various globals */
function wfGetIP() {
- global $wgSquidServers, $wgSquidServersNoPurge;
+ global $wgSquidServers, $wgSquidServersNoPurge, $wgIP;
+
+ # Return cached result
+ if ( !empty( $wgIP ) ) {
+ return $wgIP;
+ }
/* collect the originating ips */
# Client connecting to this webserver
}
}
+ wfDebug( "IP: $ip\n" );
+ $wgIP = $ip;
return $ip;
}
}
return true;
}
+
+/**
+ * Forks processes to scan the originating IP for an open proxy server
+ * MemCached can be used to skip IPs that have already been scanned
+ */
+function wfProxyCheck() {
+ global $wgBlockOpenProxies, $wgProxyPorts, $wgProxyScriptPath;
+ global $wgUseMemCached, $wgMemc, $wgDBname, $wgProxyMemcExpiry;
+
+ if ( !$wgBlockOpenProxies ) {
+ return;
+ }
+
+ $ip = wfGetIP();
+ # Get MemCached key
+ $skip = false;
+ if ( $wgUseMemCached ) {
+ $mcKey = "$wgDBname:proxy:ip:$ip";
+ $mcValue = $wgMemc->get( $mcKey );
+ if ( $mcValue ) {
+ $skip = true;
+ }
+ }
+
+ # Fork the processes
+ if ( !$skip ) {
+ $title = Title::makeTitle( NS_SPECIAL, 'Blockme' );
+ $iphash = md5( $ip . $wgProxyKey );
+ $url = $title->getFullURL( 'ip='.$iphash );
+
+ foreach ( $wgProxyPorts as $port ) {
+ $params = implode( ' ', array(
+ escapeshellarg( $wgProxyScriptPath ),
+ escapeshellarg( $ip ),
+ escapeshellarg( $port ),
+ escapeshellarg( $url )
+ ));
+ exec( "php $params &>/dev/null &" );
+ }
+ # Set MemCached key
+ if ( $wgUseMemCached ) {
+ $wgMemc->set( $mcKey, 1, $wgProxyMemcExpiry );
+ }
+ }
+}
+
?>
function addNewAccountInternal() {
global $wgUser, $wgOut;
global $wgUseLatin1, $wgEnableSorbs, $wgProxyWhitelist;
- global $wgMemc, $wgAccountCreationThrottle, $wgDBname, $wgIP;
+ global $wgMemc, $wgAccountCreationThrottle, $wgDBname;
global $wgAuth;
// If the user passes an invalid domain, something is fishy
return false;
}
- if ( $wgEnableSorbs && !in_array( $wgIP, $wgProxyWhitelist ) &&
- $wgUser->inSorbsBlacklist( $wgIP ) )
+ $ip = wfGetIP();
+ if ( $wgEnableSorbs && !in_array( $ip, $wgProxyWhitelist ) &&
+ $wgUser->inSorbsBlacklist( $ip ) )
{
- $this->mainLoginForm( wfMsg( 'sorbs_create_account_reason' ) . ' (' . htmlspecialchars( $wgIP ) . ')' );
+ $this->mainLoginForm( wfMsg( 'sorbs_create_account_reason' ) . ' (' . htmlspecialchars( $ip ) . ')' );
return;
}
}
if ( $wgAccountCreationThrottle ) {
- $key = $wgDBname.':acctcreate:ip:'.$wgIP;
+ $key = $wgDBname.':acctcreate:ip:'.$ip;
$value = $wgMemc->incr( $key );
if ( !$value ) {
$wgMemc->set( $key, 1, 86400 );
* @access private
*/
function mailPasswordInternal( $u ) {
- global $wgPasswordSender, $wgDBname, $wgIP;
+ global $wgPasswordSender, $wgDBname;
global $wgCookiePath, $wgCookieDomain;
if ( '' == $u->getEmail() ) {
$u->saveSettings();
- $ip = $wgIP;
+ $ip = wfGetIP();
if ( '' == $ip ) { $ip = '(Unknown)'; }
$m = wfMsg( 'passwordremindertext', $ip, $u->getName(), $np );
$fname = 'User::loadDefaults' . $n;
wfProfileIn( $fname );
- global $wgContLang, $wgIP, $wgDBname;
+ global $wgContLang, $wgDBname;
global $wgNamespacesToBeSearchedDefault;
$this->mId = 0;
$this->mNewtalk = -1;
- $this->mName = $wgIP;
+ $this->mName = false;
$this->mRealName = $this->mEmail = '';
$this->mEmailAuthenticated = null;
$this->mPassword = $this->mNewpassword = '';
* And it's cheaper to check slave first, then master if needed, than master always.
*/
function getBlockedStatus( $bFromSlave = true ) {
- global $wgIP, $wgBlockCache, $wgProxyList, $wgEnableSorbs, $wgProxyWhitelist;
+ global $wgBlockCache, $wgProxyList, $wgEnableSorbs, $wgProxyWhitelist;
if ( -1 != $this->mBlockedby ) {
wfDebug( "User::getBlockedStatus: already loaded.\n" );
wfDebug( "$fname: checking...\n" );
$this->mBlockedby = 0;
+ $ip = wfGetIP();
# User/IP blocking
$block = new Block();
$block->forUpdate( $bFromSlave );
- if ( $block->load( $wgIP , $this->mId ) ) {
+ if ( $block->load( $ip , $this->mId ) ) {
wfDebug( "$fname: Found block.\n" );
$this->mBlockedby = $block->mBy;
$this->mBlockreason = $block->mReason;
if ( !$this->mBlockedby ) {
# Check first against slave, and optionally from master.
wfDebug( "$fname: Checking range blocks\n" );
- $block = $wgBlockCache->get( $wgIP, true );
+ $block = $wgBlockCache->get( $ip, true );
if ( !$block && !$bFromSlave )
{
# Not blocked: check against master, to make sure.
$wgBlockCache->clearLocal( );
- $block = $wgBlockCache->get( $wgIP, false );
+ $block = $wgBlockCache->get( $ip, false );
}
if ( $block !== false ) {
$this->mBlockedby = $block->mBy;
}
# Proxy blocking
- if ( !$this->isSysop() && !in_array( $wgIP, $wgProxyWhitelist ) ) {
+ if ( !$this->isSysop() && !in_array( $ip, $wgProxyWhitelist ) ) {
# Local list
- if ( array_key_exists( $wgIP, $wgProxyList ) ) {
+ if ( array_key_exists( $ip, $wgProxyList ) ) {
$this->mBlockedby = wfMsg( 'proxyblocker' );
$this->mBlockreason = wfMsg( 'proxyblockreason' );
}
# DNSBL
if ( !$this->mBlockedby && $wgEnableSorbs && !$this->getID() ) {
- if ( $this->inSorbsBlacklist( $wgIP ) ) {
+ if ( $this->inSorbsBlacklist( $ip ) ) {
$this->mBlockedby = wfMsg( 'sorbs' );
$this->mBlockreason = wfMsg( 'sorbsreason' );
}
return false;
}
- global $wgMemc, $wgIP, $wgDBname, $wgRateLimitLog;
+ global $wgMemc, $wgDBname, $wgRateLimitLog;
$fname = 'User::pingLimiter';
wfProfileIn( $fname );
$limits = $wgRateLimits[$action];
$keys = array();
$id = $this->getId();
+ $ip = wfGetIP();
if( isset( $limits['anon'] ) && $id == 0 ) {
$keys["$wgDBname:limiter:$action:anon"] = $limits['anon'];
$keys["$wgDBname:limiter:$action:user:$id"] = $limits['newbie'];
}
if( isset( $limits['ip'] ) ) {
- $keys["mediawiki:limiter:$action:ip:$wgIP"] = $limits['ip'];
+ $keys["mediawiki:limiter:$action:ip:$ip"] = $limits['ip'];
}
- if( isset( $limits['subnet'] ) && preg_match( '/^(\d+\.\d+\.\d+)\.\d+$/', $wgIP, $matches ) ) {
+ if( isset( $limits['subnet'] ) && preg_match( '/^(\d+\.\d+\.\d+)\.\d+$/', $ip, $matches ) ) {
$subnet = $matches[1];
$keys["mediawiki:limiter:$action:subnet:$subnet"] = $limits['subnet'];
}
}
/**
- * Read datas from session
+ * Create a new user object using data from session
* @static
*/
function loadFromSession() {
function getName() {
$this->loadFromDatabase();
+ if ( $this->mName === false ) {
+ $this->mName = wfGetIP();
+ }
return $this->mName;
}
# entire User object stored in there.
if( !$this->mId ) {
global $wgDBname, $wgMemc;
- $key = "$wgDBname:newtalk:ip:{$this->mName}";
+ $key = "$wgDBname:newtalk:ip:" . $this->getName();
$newtalk = $wgMemc->get( $key );
if( is_integer( $newtalk ) ) {
$this->mNewtalk = $newtalk ? 1 : 0;
}
$dbr->freeResult( $res );
} else {
- $res = $dbr->select( 'user_newtalk', 1, array( 'user_ip' => $this->mName ), $fname );
+ $res = $dbr->select( 'user_newtalk', 1, array( 'user_ip' => $this->getName() ), $fname );
$this->mNewtalk = $dbr->numRows( $res ) > 0 ? 1 : 0;
$dbr->freeResult( $res );
}
$_SESSION['wsUserID'] = $this->mId;
setcookie( $wgDBname.'UserID', $this->mId, $exp, $wgCookiePath, $wgCookieDomain );
- $_SESSION['wsUserName'] = $this->mName;
- setcookie( $wgDBname.'UserName', $this->mName, $exp, $wgCookiePath, $wgCookieDomain );
+ $_SESSION['wsUserName'] = $this->getName();
+ setcookie( $wgDBname.'UserName', $this->getName(), $exp, $wgCookiePath, $wgCookieDomain );
$_SESSION['wsToken'] = $this->mToken;
if ( 1 == $this->getOption( 'rememberpassword' ) ) {
* It will clean the session cookie
*/
function logout() {
- global $wgCookiePath, $wgCookieDomain, $wgDBname, $wgIP;
+ global $wgCookiePath, $wgCookieDomain, $wgDBname;
$this->loadDefaults();
$this->setLoaded( true );
if( !$this->mId ) {
# Anon users have a separate memcache space for newtalk
# since they don't store their own info. Trim...
- $wgMemc->delete( "$wgDBname:newtalk:ip:{$this->mName}" );
+ $wgMemc->delete( "$wgDBname:newtalk:ip:" . $this->getName() );
}
}
} else {
$key = false;
} else {
$field = 'user_ip';
- $value = $this->mName;
- $key = "$wgDBname:newtalk:ip:$this->mName";
+ $value = $this->getName();
+ $key = "$wgDBname:newtalk:ip:$value";
}
$dbr =& wfGetDB( DB_SLAVE );
$fname = 'User::idForName';
$gotid = 0;
- $s = trim( $this->mName );
+ $s = trim( $this->getName() );
if ( 0 == strcmp( '', $s ) ) return 0;
$dbr =& wfGetDB( DB_SLAVE );
}
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
- $ipblock = Block::newFromDB( $wgIP );
+ $ipblock = Block::newFromDB( wfGetIP() );
if ( $ipblock->isValid() ) {
# Just update the timestamp
$ipblock->updateTimestamp();
}
# Make a new block object with the desired properties
- wfDebug( "Autoblocking {$this->mName}@{$wgIP}\n" );
- $ipblock->mAddress = $wgIP;
+ wfDebug( "Autoblocking {$this->mName}@" . wfGetIP() . "\n" );
+ $ipblock->mAddress = wfGetIP();
$ipblock->mUser = 0;
$ipblock->mBy = $userblock->mBy;
$ipblock->mReason = wfMsg( 'autoblocker', $this->getName(), $userblock->mReason );
* @access public
*/
function getUserPage() {
- return Title::makeTitle( NS_USER, $this->mName );
+ return Title::makeTitle( NS_USER, $this->getName() );
}
/**
* @return mixed True on success, a WikiError object on failure.
*/
function sendConfirmationMail() {
- global $wgIP, $wgContLang;
+ global $wgContLang;
$url = $this->confirmationTokenUrl( $expiration );
return $this->sendMail( wfMsg( 'confirmemail_subject' ),
wfMsg( 'confirmemail_body',
- $wgIP,
+ wfGetIP(),
$this->getName(),
$url,
$wgContLang->timeanddate( $expiration, false ) ) );