* User::getCanonicalName(), except that true is accepted as an alias
* for 'valid', for BC.
*
- * @return User object, or false if the username is invalid
+ * @return User|bool User object, or false if the username is invalid
* (e.g. if it contains illegal characters or is an IP address). If the
* username is not present in the database, the result will be a user object
* with a name, zero user ID and default settings.
}
if ( is_array( $data ) ) {
- if ( is_array( $data['user_groups'] ) ) {
+ if ( isset( $data['user_groups'] ) && is_array( $data['user_groups'] ) ) {
$this->mGroups = $data['user_groups'];
}
- if ( is_array( $data['user_properties'] ) ) {
+ if ( isset( $data['user_properties'] ) && is_array( $data['user_properties'] ) ) {
$this->loadOptions( $data['user_properties'] );
}
}
$this->mRights = self::getGroupPermissions( $this->getEffectiveGroups() );
wfRunHooks( 'UserGetRights', array( $this, &$this->mRights ) );
// Force reindexation of rights when a hook has unset one of them
- $this->mRights = array_values( $this->mRights );
+ $this->mRights = array_values( array_unique( $this->mRights ) );
}
return $this->mRights;
}
) );
# Hook for additional groups
wfRunHooks( 'UserEffectiveGroups', array( &$this, &$this->mEffectiveGroups ) );
+ // Force reindexation of groups when a hook has unset one of them
+ $this->mEffectiveGroups = array_values( array_unique( $this->mEffectiveGroups ) );
wfProfileOut( __METHOD__ );
}
return $this->mEffectiveGroups;
* @return Int
*/
public function getEditCount() {
- if( $this->getId() ) {
- if ( !isset( $this->mEditCount ) ) {
- /* Populate the count, if it has not been populated yet */
- 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 ( !$this->getId() ) {
+ return null;
+ }
- if( $count === null ) {
- // it has not been initialized. do so.
- $count = $this->initEditCount();
- }
- wfProfileOut( __METHOD__ );
- $this->mEditCount = $count;
+ if ( !isset( $this->mEditCount ) ) {
+ /* Populate the count, if it has not been populated yet */
+ 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.
+ $count = $this->initEditCount();
}
- return $this->mEditCount;
- } else {
- /* nil */
- return null;
+ $this->mEditCount = intval( $count );
+ wfProfileOut( __METHOD__ );
}
+ return $this->mEditCount;
}
/**
// Pull from a slave to be less cruel to servers
// Accuracy isn't the point anyway here
$dbr = wfGetDB( DB_SLAVE );
- $count = $dbr->selectField(
+ $count = (int) $dbr->selectField(
'revision',
'COUNT(rev_user)',
array( 'rev_user' => $this->getId() ),