public function updateUserGroups($user, $addgroup = array(), $removegroup = array()) { wfProfileIn(__METHOD__); if (!$user instanceof User) { wfProfileOut(__METHOD__); return true; } $user_id = $user->getID(); $dbr = wfGetDB(DB_SLAVE, array(), $this->mDBh); $where = array("user_id" => $user_id, "wiki_id" => $this->mCityId); $oRow = $dbr->selectRow(array($this->mTable), array("all_groups"), $where, __METHOD__); $groups = array(); if ($oRow !== false) { $tmp = explode(";", $oRow->all_groups); if (!empty($tmp)) { foreach ($tmp as $g) { if (!empty($g)) { $groups[] = $g; } } } } $central_groups = array(); if (class_exists('UserRights')) { if (!UserRights::isCentralWiki()) { $central_groups = UserRights::getGlobalGroups($user); } } # add groups if (!empty($addgroup)) { $groups = array_unique(array_merge($groups, $addgroup)); } # remove groups if (!empty($removegroup)) { $groups = array_unique(array_diff($groups, $removegroup)); } #central groups if (!empty($central_groups)) { $groups = array_unique(array_merge($groups, $central_groups)); } if (!empty($groups)) { sort($groups); } $elements = count($groups); $singlegroup = $elements > 0 ? $groups[$elements - 1] : ""; $allgroups = $elements > 0 ? implode(";", $groups) : ""; $dbw = wfGetDB(DB_MASTER, array(), $this->mDBh); if (empty($oRow)) { $edits = User::edits($user_id); $dbr = wfGetDB(DB_SLAVE); $revRow = $dbr->selectRow('revision', array('rev_id', 'rev_timestamp'), array('rev_user' => $user_id), __METHOD__, array('ORDER BY' => 'rev_timestamp DESC')); if (empty($revRow)) { $editdate = '0000-00-00 00:00:00'; $lastrev = 0; } else { $editdate = wfTimestamp(TS_DB, $revRow->rev_timestamp); $lastrev = $revRow->rev_id; } $dbw->replace($this->mTable, array('wiki_id', 'user_id', 'user_name'), array("wiki_id" => $this->mCityId, "user_id" => $user_id, "user_name" => $user->getName(), "last_ip" => 0, "edits" => $edits, "editdate" => $editdate, "last_revision" => intval($lastrev), "cnt_groups" => $elements, "single_group" => $singlegroup, "all_groups" => $allgroups), __METHOD__); } else { $dbw->update($this->mTable, array("cnt_groups" => $elements, "single_group" => $singlegroup, "all_groups" => $allgroups), $where, __METHOD__); } wfProfileOut(__METHOD__); return true; }
/** * Checks if removal of a property should remove a group * and if a user still has a PowerUser type that qualifies him * to have the 'poweruser' group * * @param string $sProperty One of the types in consts * @return bool */ public function isGroupForRemoval($sProperty) { foreach (self::$aPowerUserProperties as $sPowerUserProperty) { if ($sPowerUserProperty !== $sProperty && $this->oUser->isSpecificPowerUser($sPowerUserProperty)) { return false; } } return in_array(self::GROUP_NAME, \UserRights::getGlobalGroups($this->oUser)); }