Merge "Protected function UploadBase->validateName changed to public"
[lhc/web/wiklou.git] / includes / User.php
index 2b7c787..0ac79d6 100644 (file)
@@ -921,22 +921,12 @@ class User {
         * @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' );
@@ -1271,7 +1261,7 @@ class User {
         *                    done against master.
         */
        private function getBlockedStatus( $bFromSlave = true ) {
-               global $wgProxyWhitelist, $wgUser;
+               global $wgProxyWhitelist, $wgUser, $wgApplyIpBlocksToXff;
 
                if ( -1 != $this->mBlockedby ) {
                        return;
@@ -1317,6 +1307,25 @@ class User {
                        }
                }
 
+               # (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;
@@ -1330,7 +1339,7 @@ class User {
                        $this->mAllowUsertalk = false;
                }
 
-               # Extensions
+               // Extensions
                wfRunHooks( 'GetBlockedStatus', array( &$this ) );
 
                wfProfileOut( __METHOD__ );
@@ -1950,28 +1959,29 @@ class User {
         * 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();
                }
        }
@@ -4389,8 +4399,6 @@ class User {
         * @todo document
         */
        protected function saveOptions() {
-               global $wgAllowPrefChange;
-
                $this->loadOptions();
 
                // Not using getOptions(), to keep hidden preferences in database
@@ -4402,7 +4410,6 @@ class User {
                        return;
                }
 
-               $extuser = ExternalUser::newFromUser( $this );
                $userId = $this->getId();
                $insert_rows = array();
                foreach( $saveOptions as $key => $value ) {
@@ -4417,16 +4424,6 @@ class User {
                                                '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 );