Merge "Remove a bunch of trailing spaces and unneeded newlines"
[lhc/web/wiklou.git] / includes / User.php
index f80319d..3b1e034 100644 (file)
@@ -817,39 +817,16 @@ class User {
 
        /**
         * Count the number of edits of a user
-        * @todo It should not be static and some day should be merged as proper member function / deprecated -- domas
         *
         * @param $uid Int User ID to check
         * @return Int the user's edit count
+        *
+        * @deprecated since 1.21 in favour of User::getEditCount
         */
        public static function edits( $uid ) {
-               wfProfileIn( __METHOD__ );
-               $dbr = wfGetDB( DB_SLAVE );
-               // check if the user_editcount field has been initialized
-               $field = $dbr->selectField(
-                       'user', 'user_editcount',
-                       array( 'user_id' => $uid ),
-                       __METHOD__
-               );
-
-               if( $field === null ) { // it has not been initialized. do so.
-                       $dbw = wfGetDB( DB_MASTER );
-                       $count = $dbr->selectField(
-                               'revision', 'count(*)',
-                               array( 'rev_user' => $uid ),
-                               __METHOD__
-                       );
-                       $dbw->update(
-                               'user',
-                               array( 'user_editcount' => $count ),
-                               array( 'user_id' => $uid ),
-                               __METHOD__
-                       );
-               } else {
-                       $count = $field;
-               }
-               wfProfileOut( __METHOD__ );
-               return $count;
+               wfDeprecated( __METHOD__, '1.21' );
+               $user = self::newFromId( $uid );
+               return $user->getEditCount();
        }
 
        /**
@@ -1191,7 +1168,9 @@ class User {
        }
 
        /**
-        * Clear various cached data stored in this object.
+        * Clear various cached data stored in this object. The cache of the user table
+        * data (i.e. self::$mCacheVars) is not cleared unless $reloadFrom is given.
+        *
         * @param $reloadFrom bool|String Reload user and user_groups table data from a
         *   given source. May be "name", "id", "defaults", "session", or false for
         *   no reload.
@@ -1205,6 +1184,7 @@ class User {
                $this->mEffectiveGroups = null;
                $this->mImplicitGroups = null;
                $this->mOptions = null;
+               $this->mOptionsLoaded = false;
                $this->mEditCount = null;
 
                if ( $reloadFrom ) {
@@ -2466,7 +2446,32 @@ class User {
                if( $this->getId() ) {
                        if ( !isset( $this->mEditCount ) ) {
                                /* Populate the count, if it has not been populated yet */
-                               $this->mEditCount = User::edits( $this->mId );
+                               wfProfileIn( __METHOD__ );
+                               $dbr = wfGetDB( DB_SLAVE );
+                               // check if the user_editcount field has been initialized
+                               $count = $dbr->selectField(
+                                       'user', 'user_editcount',
+                                       array( 'user_id' => $this->mId ),
+                                       __METHOD__
+                               );
+
+                               if( $count === null ) {
+                                       // it has not been initialized. do so.
+                                       $dbw = wfGetDB( DB_MASTER );
+                                       $count = $dbr->selectField(
+                                               'revision', 'count(*)',
+                                               array( 'rev_user' => $this->mId ),
+                                               __METHOD__
+                                       );
+                                       $dbw->update(
+                                               'user',
+                                               array( 'user_editcount' => $count ),
+                                               array( 'user_id' => $this->mId ),
+                                               __METHOD__
+                                       );
+                               }
+                               wfProfileOut( __METHOD__ );
+                               $this->mEditCount = $count;
                        }
                        return $this->mEditCount;
                } else {
@@ -3008,8 +3013,8 @@ class User {
        }
 
        /**
-        * Add this existing user object to the database. If the user already 
-        * exists, a fatal status object is returned, and the user object is 
+        * Add this existing user object to the database. If the user already
+        * exists, a fatal status object is returned, and the user object is
         * initialised with the data from the database.
         *
         * Previously, this function generated a DB error due to a key conflict
@@ -3022,12 +3027,12 @@ class User {
         *   }
         *   // do something with $user...
         *
-        * However, this was vulnerable to a race condition (bug 16020). By 
+        * However, this was vulnerable to a race condition (bug 16020). By
         * initialising the user object if the user exists, we aim to support this
         * calling sequence as far as possible.
         *
         * Note that if the user exists, this function will acquire a write lock,
-        * so it is still advisable to make the call conditional on isLoggedIn(), 
+        * so it is still advisable to make the call conditional on isLoggedIn(),
         * and to commit the transaction after calling.
         *
         * @return Status
@@ -3057,7 +3062,7 @@ class User {
                        array( 'IGNORE' )
                );
                if ( !$dbw->affectedRows() ) {
-                       $this->mId = $dbw->selectField( 'user', 'user_id', 
+                       $this->mId = $dbw->selectField( 'user', 'user_id',
                                array( 'user_name' => $this->mName ), __METHOD__ );
                        $loaded = false;
                        if ( $this->mId ) {