* @return Bool True if the user is logged in, false otherwise.
*/
private function loadFromSession() {
- global $wgExternalAuthType, $wgAutocreatePolicy;
-
$result = null;
wfRunHooks( 'UserLoadFromSession', array( $this, &$result ) );
if ( $result !== null ) {
return $result;
}
- if ( $wgExternalAuthType && $wgAutocreatePolicy == 'view' ) {
- $extUser = ExternalUser::newFromCookie();
- if ( $extUser ) {
- # TODO: Automatically create the user here (or probably a bit
- # lower down, in fact)
- }
- }
-
$request = $this->getRequest();
$cookieId = $request->getCookie( 'UserID' );
* done against master.
*/
private function getBlockedStatus( $bFromSlave = true ) {
- global $wgProxyWhitelist, $wgUser;
+ global $wgProxyWhitelist, $wgUser, $wgApplyIpBlocksToXff;
if ( -1 != $this->mBlockedby ) {
return;
}
}
+ # (bug 23343) Apply IP blocks to the contents of XFF headers, if enabled
+ if ( !$block instanceof Block
+ && $wgApplyIpBlocksToXff
+ && $ip !== null
+ && !$this->isAllowed( 'proxyunbannable' )
+ && !in_array( $ip, $wgProxyWhitelist )
+ ) {
+ $xff = $this->getRequest()->getHeader( 'X-Forwarded-For' );
+ $xff = array_map( 'trim', explode( ',', $xff ) );
+ $xff = array_diff( $xff, array( $ip ) );
+ $xffblocks = Block::getBlocksForIPList( $xff, $this->isAnon(), !$bFromSlave );
+ $block = Block::chooseBlock( $xffblocks, $xff );
+ if ( $block instanceof Block ) {
+ # Mangle the reason to alert the user that the block
+ # originated from matching the X-Forwarded-For header.
+ $block->mReason = wfMessage( 'xffblockreason', $block->mReason )->text();
+ }
+ }
+
if ( $block instanceof Block ) {
wfDebug( __METHOD__ . ": Found block.\n" );
$this->mBlock = $block;
$this->mAllowUsertalk = false;
}
- # Extensions
+ // Extensions
wfRunHooks( 'GetBlockedStatus', array( &$this ) );
wfProfileOut( __METHOD__ );
* for reload on the next hit.
*/
public function invalidateCache() {
- if( wfReadOnly() ) {
+ if ( wfReadOnly() ) {
return;
}
$this->load();
- if( $this->mId ) {
+ if ( $this->mId ) {
$this->mTouched = self::newTouchedTimestamp();
$dbw = wfGetDB( DB_MASTER );
-
- // Prevent contention slams by checking user_touched first
- $now = $dbw->timestamp( $this->mTouched );
- $needsPurge = $dbw->selectField( 'user', '1',
- array( 'user_id' => $this->mId, 'user_touched < ' . $dbw->addQuotes( $now ) )
- );
- if ( $needsPurge ) {
- $dbw->update( 'user',
- array( 'user_touched' => $now ),
- array( 'user_id' => $this->mId, 'user_touched < ' . $dbw->addQuotes( $now ) ),
- __METHOD__
- );
- }
-
+ $userid = $this->mId;
+ $touched = $this->mTouched;
+ $dbw->onTransactionIdle( function() use ( $dbw, $userid, $touched ) {
+ // Prevent contention slams by checking user_touched first
+ $encTouched = $dbw->addQuotes( $dbw->timestamp( $touched ) );
+ $needsPurge = $dbw->selectField( 'user', '1',
+ array( 'user_id' => $userid, 'user_touched < ' . $encTouched ) );
+ if ( $needsPurge ) {
+ $dbw->update( 'user',
+ array( 'user_touched' => $dbw->timestamp( $touched ) ),
+ array( 'user_id' => $userid, 'user_touched < ' . $encTouched ),
+ __METHOD__
+ );
+ }
+ } );
$this->clearSharedCache();
}
}
* @todo document
*/
protected function saveOptions() {
- global $wgAllowPrefChange;
-
$this->loadOptions();
// Not using getOptions(), to keep hidden preferences in database
return;
}
- $extuser = ExternalUser::newFromUser( $this );
$userId = $this->getId();
$insert_rows = array();
foreach( $saveOptions as $key => $value ) {
'up_value' => $value,
);
}
- if ( $extuser && isset( $wgAllowPrefChange[$key] ) ) {
- switch ( $wgAllowPrefChange[$key] ) {
- case 'local':
- case 'message':
- break;
- case 'semiglobal':
- case 'global':
- $extuser->setPref( $key, $value );
- }
- }
}
$dbw = wfGetDB( DB_MASTER );