/**
* 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();
}
/**
}
/**
- * 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.
$this->mEffectiveGroups = null;
$this->mImplicitGroups = null;
$this->mOptions = null;
+ $this->mOptionsLoaded = false;
$this->mEditCount = null;
if ( $reloadFrom ) {
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 {
}
/**
- * 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
* }
* // 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
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 ) {