Introduce PageHistoryPager::doBatchLookups hook.
[lhc/web/wiklou.git] / includes / User.php
index f23d7dd..f862953 100644 (file)
@@ -102,6 +102,7 @@ class User implements IDBAccessObject {
         */
        protected static $mCoreRights = array(
                'apihighlimits',
+               'applychangetags',
                'autoconfirmed',
                'autopatrol',
                'bigdelete',
@@ -109,6 +110,7 @@ class User implements IDBAccessObject {
                'blockemail',
                'bot',
                'browsearchive',
+               'changetags',
                'createaccount',
                'createpage',
                'createtalk',
@@ -2202,6 +2204,8 @@ class User implements IDBAccessObject {
         *   page. Ignored if null or !$val.
         */
        public function setNewtalk( $val, $curRev = null ) {
+               global $wgMemc;
+
                if ( wfReadOnly() ) {
                        return;
                }
@@ -2216,7 +2220,6 @@ class User implements IDBAccessObject {
                        $field = 'user_id';
                        $id = $this->getId();
                }
-               global $wgMemc;
 
                if ( $val ) {
                        $changed = $this->updateNewtalk( $field, $id, $curRev );
@@ -2268,37 +2271,13 @@ class User implements IDBAccessObject {
        }
 
        /**
-        * Immediately touch the user data cache for this account.
-        * Updates user_touched field, and removes account data from memcached
-        * for reload on the next hit.
+        * Immediately touch the user data cache for this account
+        *
+        * Calls touch() and removes account data from memcached
         */
        public function invalidateCache() {
-               if ( wfReadOnly() ) {
-                       return;
-               }
-               $this->load();
-               if ( $this->mId ) {
-                       $this->mTouched = $this->newTouchedTimestamp();
-
-                       $dbw = wfGetDB( DB_MASTER );
-                       $userid = $this->mId;
-                       $touched = $this->mTouched;
-                       $method = __METHOD__;
-                       $dbw->onTransactionIdle( function () use ( $dbw, $userid, $touched, $method ) {
-                               // 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();
-               }
+               $this->touch();
+               $this->clearSharedCache();
        }
 
        /**
@@ -3654,7 +3633,8 @@ class User implements IDBAccessObject {
                if ( !$dbw->affectedRows() ) {
                        // User was changed in the meantime or loaded with stale data
                        MWExceptionHandler::logException( new MWException(
-                               "CAS update failed on user_touched for user ID '{$this->mId}'."
+                               "CAS update failed on user_touched for user ID '{$this->mId}';" .
+                               "the version of the user to be saved is older than the current version."
                        ) );
                        // Maybe the problem was a missed cache update; clear it to be safe
                        $this->clearSharedCache();
@@ -4760,38 +4740,51 @@ class User implements IDBAccessObject {
                return $groups;
        }
 
+       /**
+        * Deferred version of incEditCountImmediate()
+        */
+       public function incEditCount() {
+               $that = $this;
+               wfGetDB( DB_MASTER )->onTransactionPreCommitOrIdle( function() use ( $that ) {
+                       $that->incEditCountImmediate();
+               } );
+       }
+
        /**
         * Increment the user's edit-count field.
         * Will have no effect for anonymous users.
+        * @since 1.26
         */
-       public function incEditCount() {
-               if ( !$this->isAnon() ) {
-                       $dbw = wfGetDB( DB_MASTER );
-                       $dbw->update(
-                               'user',
-                               array( 'user_editcount=user_editcount+1' ),
-                               array( 'user_id' => $this->getId() ),
-                               __METHOD__
-                       );
+       public function incEditCountImmediate() {
+               if ( $this->isAnon() ) {
+                       return;
+               }
 
-                       // Lazy initialization check...
-                       if ( $dbw->affectedRows() == 0 ) {
-                               // Now here's a goddamn hack...
-                               $dbr = wfGetDB( DB_SLAVE );
-                               if ( $dbr !== $dbw ) {
-                                       // If we actually have a slave server, the count is
-                                       // at least one behind because the current transaction
-                                       // has not been committed and replicated.
-                                       $this->initEditCount( 1 );
-                               } else {
-                                       // But if DB_SLAVE is selecting the master, then the
-                                       // count we just read includes the revision that was
-                                       // just added in the working transaction.
-                                       $this->initEditCount();
-                               }
+               $dbw = wfGetDB( DB_MASTER );
+               // No rows will be "affected" if user_editcount is NULL
+               $dbw->update(
+                       'user',
+                       array( 'user_editcount=user_editcount+1' ),
+                       array( 'user_id' => $this->getId() ),
+                       __METHOD__
+               );
+               // Lazy initialization check...
+               if ( $dbw->affectedRows() == 0 ) {
+                       // Now here's a goddamn hack...
+                       $dbr = wfGetDB( DB_SLAVE );
+                       if ( $dbr !== $dbw ) {
+                               // If we actually have a slave server, the count is
+                               // at least one behind because the current transaction
+                               // has not been committed and replicated.
+                               $this->initEditCount( 1 );
+                       } else {
+                               // But if DB_SLAVE is selecting the master, then the
+                               // count we just read includes the revision that was
+                               // just added in the working transaction.
+                               $this->initEditCount();
                        }
                }
-               // edit count in user cache too
+               // Edit count in user cache too
                $this->invalidateCache();
        }