Merge "(Bug 38439) Attempt on fixing the suicidal LangObjCache"
[lhc/web/wiklou.git] / includes / User.php
index f02cc29..28ff630 100644 (file)
@@ -370,7 +370,7 @@ class User {
         *    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.
@@ -1102,10 +1102,10 @@ class User {
                }
 
                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'] );
                        }
                }
@@ -2357,7 +2357,7 @@ class User {
                        $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;
        }
@@ -2389,6 +2389,8 @@ class User {
                        ) );
                        # 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;
@@ -2452,30 +2454,29 @@ class User {
         * @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 = intval( $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;
        }
 
        /**
@@ -3033,6 +3034,7 @@ class User {
         * so it is still advisable to make the call conditional on isLoggedIn(),
         * and to commit the transaction after calling.
         *
+        * @throws MWException
         * @return Status
         */
        public function addToDatabase() {
@@ -3979,7 +3981,7 @@ class User {
                // 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() ),