SpecialMergeHistory: add redirect=no on target parameter on success message
[lhc/web/wiklou.git] / includes / User.php
index 22c90cd..029f5cf 100644 (file)
@@ -129,7 +129,7 @@ class User implements IDBAccessObject {
                'editmyuserjs',
                'editmywatchlist',
                'editsemiprotected',
-               'editusercssjs', #deprecated
+               'editusercssjs', # deprecated
                'editusercss',
                'edituserjs',
                'hideuser',
@@ -184,7 +184,7 @@ class User implements IDBAccessObject {
        protected static $mAllRights = false;
 
        /** Cache variables */
-       //@{
+       // @{
        public $mId;
        /** @var string */
        public $mName;
@@ -228,19 +228,19 @@ class User implements IDBAccessObject {
        protected $mOptionOverrides;
        /** @var string */
        protected $mPasswordExpires;
-       //@}
+       // @}
 
        /**
         * Bool Whether the cache variables have been loaded.
         */
-       //@{
+       // @{
        public $mOptionsLoaded;
 
        /**
         * Array with already loaded items or true if all items have been loaded.
         */
        protected $mLoadedItems = array();
-       //@}
+       // @}
 
        /**
         * String Initialization data source if mLoadedItems!==true. May be one of:
@@ -458,11 +458,12 @@ class User implements IDBAccessObject {
                $data['mVersion'] = self::VERSION;
                $key = wfMemcKey( 'user', 'id', $this->mId );
 
-               ObjectCache::getMainWANInstance()->set( $key, $data, 3600 );
+               $opts = array( 'since' => wfGetDB( DB_SLAVE )->trxTimestamp() );
+               ObjectCache::getMainWANInstance()->set( $key, $data, 3600, $opts );
        }
 
        /** @name newFrom*() static factory methods */
-       //@{
+       // @{
 
        /**
         * Static factory method for creation from username.
@@ -573,7 +574,7 @@ class User implements IDBAccessObject {
                return $user;
        }
 
-       //@}
+       // @}
 
        /**
         * Get the username corresponding to a given user ID
@@ -799,7 +800,7 @@ class User implements IDBAccessObject {
         * @return bool
         */
        public function isValidPassword( $password ) {
-               //simple boolean wrapper for getPasswordValidity
+               // simple boolean wrapper for getPasswordValidity
                return $this->getPasswordValidity( $password ) === true;
        }
 
@@ -856,7 +857,7 @@ class User implements IDBAccessObject {
                );
 
                $status = Status::newGood();
-               $result = false; //init $result to false for the internal checks
+               $result = false; // init $result to false for the internal checks
 
                if ( !Hooks::run( 'isValidPassword', array( $password, &$result, $this ) ) ) {
                        $status->error( $result );
@@ -870,7 +871,7 @@ class User implements IDBAccessObject {
                        return $status;
                } else {
                        $status->error( $result );
-                       return $status; //the isValidPassword hook set a string $result and returned true
+                       return $status; // the isValidPassword hook set a string $result and returned true
                }
        }
 
@@ -1203,18 +1204,15 @@ class User implements IDBAccessObject {
                        return false;
                }
 
-               $db = ( $flags & self::READ_LATEST )
-                       ? wfGetDB( DB_MASTER )
-                       : wfGetDB( DB_SLAVE );
+               list( $index, $options ) = DBAccessObjectUtils::getDBOptions( $flags );
+               $db = wfGetDB( $index );
 
                $s = $db->selectRow(
                        'user',
                        self::selectFields(),
                        array( 'user_id' => $this->mId ),
                        __METHOD__,
-                       ( ( $flags & self::READ_LOCKING ) == self::READ_LOCKING )
-                               ? array( 'LOCK IN SHARE MODE' )
-                               : array()
+                       $options
                );
 
                $this->queryFlagsUsed = $flags;
@@ -1484,11 +1482,12 @@ class User implements IDBAccessObject {
 
                if ( $success ) {
                        $this->mTouched = $newTouched;
+                       $this->clearSharedCache();
+               } else {
+                       // Clears on failure too since that is desired if the cache is stale
+                       $this->clearSharedCache( 'refresh' );
                }
 
-               // Clears on failure too since that is desired if the cache is stale
-               $this->clearSharedCache();
-
                return $success;
        }
 
@@ -1694,6 +1693,7 @@ class User implements IDBAccessObject {
                        foreach ( (array)$bases as $base ) {
                                // Make hostname
                                // If we have an access key, use that too (ProjectHoneypot, etc.)
+                               $basename = $base;
                                if ( is_array( $base ) ) {
                                        if ( count( $base ) >= 2 ) {
                                                // Access key is 1, base URL is 0
@@ -1701,6 +1701,7 @@ class User implements IDBAccessObject {
                                        } else {
                                                $host = "$ipReversed.{$base[0]}";
                                        }
+                                       $basename = $base[0];
                                } else {
                                        $host = "$ipReversed.$base";
                                }
@@ -1709,11 +1710,11 @@ class User implements IDBAccessObject {
                                $ipList = gethostbynamel( $host );
 
                                if ( $ipList ) {
-                                       wfDebugLog( 'dnsblacklist', "Hostname $host is {$ipList[0]}, it's a proxy says $base!" );
+                                       wfDebugLog( 'dnsblacklist', "Hostname $host is {$ipList[0]}, it's a proxy says $basename!" );
                                        $found = true;
                                        break;
                                } else {
-                                       wfDebugLog( 'dnsblacklist', "Requested $host, not found in $base." );
+                                       wfDebugLog( 'dnsblacklist', "Requested $host, not found in $basename." );
                                }
                        }
                }
@@ -2280,17 +2281,28 @@ class User implements IDBAccessObject {
        }
 
        /**
-        * Clear user data from memcached.
-        * Use after applying fun updates to the database; caller's
+        * Clear user data from memcached
+        *
+        * Use after applying updates to the database; caller's
         * responsibility to update user_touched if appropriate.
         *
         * Called implicitly from invalidateCache() and saveSettings().
+        *
+        * @param string $mode Use 'refresh' to clear now; otherwise before DB commit
         */
-       public function clearSharedCache() {
+       public function clearSharedCache( $mode = 'changed' ) {
                $id = $this->getId();
-               if ( $id ) {
-                       $key = wfMemcKey( 'user', 'id', $id );
-                       ObjectCache::getMainWANInstance()->delete( $key );
+               if ( !$id ) {
+                       return;
+               }
+
+               $key = wfMemcKey( 'user', 'id', $id );
+               if ( $mode === 'refresh' ) {
+                       ObjectCache::getMainWANInstance()->delete( $key, 1 );
+               } else {
+                       wfGetDB( DB_MASTER )->onTransactionPreCommitOrIdle( function() use ( $key ) {
+                               ObjectCache::getMainWANInstance()->delete( $key );
+                       } );
                }
        }
 
@@ -3696,7 +3708,7 @@ class User implements IDBAccessObject {
 
                if ( !$dbw->affectedRows() ) {
                        // Maybe the problem was a missed cache update; clear it to be safe
-                       $this->clearSharedCache();
+                       $this->clearSharedCache( 'refresh' );
                        // User was changed in the meantime or loaded with stale data
                        $from = ( $this->queryFlagsUsed & self::READ_LATEST ) ? 'master' : 'slave';
                        throw new MWException(
@@ -5203,7 +5215,7 @@ class User implements IDBAccessObject {
                # is b0rked anyway in some browsers, just return nothing.  When it's
                # re-enabled, fix this code to not output required for e-mail
                # registration.
-               #$ret = array( 'required' );
+               # $ret = array( 'required' );
                $ret = array();
 
                # We can't actually do this right now, because Opera 9.6 will print out