X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2FUser.php;h=dd199ee5b5d6463d594873eafab6ea1dd552102c;hb=4d22e6ff4e13ebf34f45de935cc181fbd24e523f;hp=62f7ec0cf08021a31a813ccc33eb77e3ffd89f6e;hpb=152cd9e470b104284394ecf35eb085425ef57654;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/User.php b/includes/User.php index 62f7ec0cf0..dd199ee5b5 100644 --- a/includes/User.php +++ b/includes/User.php @@ -1706,7 +1706,6 @@ class User implements IDBAccessObject { } global $wgMemc; - wfProfileIn( __METHOD__ . '-' . $action ); $limits = $wgRateLimits[$action]; $keys = array(); @@ -1787,7 +1786,6 @@ class User implements IDBAccessObject { } } - wfProfileOut( __METHOD__ . '-' . $action ); return $triggered; } @@ -3010,20 +3008,24 @@ class User implements IDBAccessObject { * Add the user to the given group. * This takes immediate effect. * @param string $group Name of the group to add + * @return bool */ public function addGroup( $group ) { - if ( Hooks::run( 'UserAddGroup', array( $this, &$group ) ) ) { - $dbw = wfGetDB( DB_MASTER ); - if ( $this->getId() ) { - $dbw->insert( 'user_groups', - array( - 'ug_user' => $this->getID(), - 'ug_group' => $group, - ), - __METHOD__, - array( 'IGNORE' ) ); - } + if ( !Hooks::run( 'UserAddGroup', array( $this, &$group ) ) ) { + return false; } + + $dbw = wfGetDB( DB_MASTER ); + if ( $this->getId() ) { + $dbw->insert( 'user_groups', + array( + 'ug_user' => $this->getID(), + 'ug_group' => $group, + ), + __METHOD__, + array( 'IGNORE' ) ); + } + $this->loadGroups(); $this->mGroups[] = $group; // In case loadGroups was not called before, we now have the right twice. @@ -3036,31 +3038,39 @@ class User implements IDBAccessObject { $this->mRights = null; $this->invalidateCache(); + + return true; } /** * Remove the user from the given group. * This takes immediate effect. * @param string $group Name of the group to remove + * @return bool */ public function removeGroup( $group ) { $this->load(); - if ( Hooks::run( 'UserRemoveGroup', array( $this, &$group ) ) ) { - $dbw = wfGetDB( DB_MASTER ); - $dbw->delete( 'user_groups', - array( - 'ug_user' => $this->getID(), - 'ug_group' => $group, - ), __METHOD__ ); - // Remember that the user was in this group - $dbw->insert( 'user_former_groups', - array( - 'ufg_user' => $this->getID(), - 'ufg_group' => $group, - ), - __METHOD__, - array( 'IGNORE' ) ); + if ( !Hooks::run( 'UserRemoveGroup', array( $this, &$group ) ) ) { + return false; } + + $dbw = wfGetDB( DB_MASTER ); + $dbw->delete( 'user_groups', + array( + 'ug_user' => $this->getID(), + 'ug_group' => $group, + ), __METHOD__ + ); + // Remember that the user was in this group + $dbw->insert( 'user_former_groups', + array( + 'ufg_user' => $this->getID(), + 'ufg_group' => $group, + ), + __METHOD__, + array( 'IGNORE' ) + ); + $this->loadGroups(); $this->mGroups = array_diff( $this->mGroups, array( $group ) ); @@ -3070,6 +3080,8 @@ class User implements IDBAccessObject { $this->mRights = null; $this->invalidateCache(); + + return true; } /** @@ -3794,7 +3806,6 @@ class User implements IDBAccessObject { public function checkPassword( $password ) { global $wgAuth, $wgLegacyEncoding; - $this->loadPasswords(); // Certain authentication plugins do NOT want to save @@ -4742,7 +4753,7 @@ class User implements IDBAccessObject { if ( $action === true ) { $action = 'byemail'; } elseif ( $action === false ) { - if ( $this->getName() == $wgUser->getName() ) { + if ( $this->equals( $wgUser ) ) { $action = 'create'; } else { $action = 'create2'; @@ -5027,4 +5038,15 @@ class User implements IDBAccessObject { return Status::newFatal( 'badaccess-group0' ); } } + + /** + * Checks if two user objects point to the same user. + * + * @since 1.25 + * @param User $user + * @return bool + */ + public function equals( User $user ) { + return $this->getName() === $user->getName(); + } }