本文整理汇总了PHP中User::getAllGroups方法的典型用法代码示例。如果您正苦于以下问题:PHP User::getAllGroups方法的具体用法?PHP User::getAllGroups怎么用?PHP User::getAllGroups使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类User
的用法示例。
在下文中一共展示了User::getAllGroups方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPageHeader
/**
* Show a drop down list to select a group as well as a user name
* search box.
* @todo localize
*/
function getPageHeader()
{
global $wgScript;
// Various variables used for the form
$action = htmlspecialchars($wgScript);
$title = Title::makeTitle(NS_SPECIAL, 'Listusers');
$special = htmlspecialchars($title->getPrefixedDBkey());
// form header
$out = '<form method="get" action="' . $action . '">' . '<input type="hidden" name="title" value="' . $special . '" />' . wfMsgHtml('groups-editgroup-name') . '<select name="group">';
// get all group names and IDs
$groups = User::getAllGroups();
// we want a default empty group
$out .= '<option value=""></option>';
// build the dropdown list menu using datas from the database
foreach ($groups as $group) {
$selected = $group == $this->requestedGroup;
$out .= wfElement('option', array_merge(array('value' => $group), $selected ? array('selected' => 'selected') : array()), User::getGroupName($group));
}
$out .= '</select> ';
$out .= wfMsgHtml('specialloguserlabel') . '<input type="text" name="username" /> ';
// OK button, end of form.
$out .= '<input type="submit" /></form>';
// congratulations the form is now build
return $out;
}
示例2: changeableGroups
function changeableGroups()
{
global $wgUser;
if ($wgUser->isAllowed('userrights-global')) {
// all groups can be added globally
$all = array_merge(User::getAllGroups());
return array('add' => $all, 'remove' => $all, 'add-self' => array(), 'remove-self' => array());
} else {
return array();
}
}
示例3: parseOptions
private static function parseOptions($opts)
{
$options = array();
$segments = explode('|', $opts);
foreach ($segments as $opt) {
// Extract key=value pair
$exploded = explode('=', $opt, 2);
$key = $exploded[0];
$value = isset($exploded[1]) ? $exploded[1] : '';
switch ($key) {
case 'replace':
// Replace the text instead of marking as spam
$options['replace'] = $value;
break;
default:
if (in_array($key, \User::getAllRights())) {
// If the name is a user right
if (isset($options['right'])) {
$options['right'][] = $key;
} else {
$options['right'] = array($key);
}
} else {
if (in_array($key, \User::getAllGroups())) {
// If the name is a user group
if (isset($options['group'])) {
$options['group'][] = $key;
} else {
$options['group'] = array($key);
}
}
}
}
}
return $options;
}
示例4: execute
public function execute()
{
$username = $this->getArg(0);
$password = $this->getArg(1);
$force = $this->hasOption('force');
$inGroups = [];
$user = User::newFromName($username);
if (!is_object($user)) {
$this->error("invalid username.", true);
}
$exists = 0 !== $user->idForName();
if ($exists && !$force) {
$this->error("Account exists. Perhaps you want the --force option?", true);
} elseif (!$exists && !$password) {
$this->error("Argument <password> required!", false);
$this->maybeHelp(true);
} elseif ($exists) {
$inGroups = $user->getGroups();
}
$groups = array_filter(self::$permitRoles, [$this, 'hasOption']);
if ($this->hasOption('custom-groups')) {
$allGroups = array_flip(User::getAllGroups());
$customGroupsText = $this->getOption('custom-groups');
if ($customGroupsText !== '') {
$customGroups = explode(',', $customGroupsText);
foreach ($customGroups as $customGroup) {
if (isset($allGroups[$customGroup])) {
$groups[] = trim($customGroup);
} else {
$this->output("{$customGroup} is not a valid group, ignoring!\n");
}
}
}
}
$promotions = array_diff($groups, $inGroups);
if ($exists && !$password && count($promotions) === 0) {
$this->output("Account exists and nothing to do.\n");
return;
} elseif (count($promotions) !== 0) {
$promoText = "User:{$username} into " . implode(', ', $promotions) . "...\n";
if ($exists) {
$this->output(wfWikiID() . ": Promoting {$promoText}");
} else {
$this->output(wfWikiID() . ": Creating and promoting {$promoText}");
}
}
if (!$exists) {
# Insert the account into the database
$user->addToDatabase();
$user->saveSettings();
}
if ($password) {
# Try to set the password
try {
$user->setPassword($password);
if ($exists) {
$this->output("Password set.\n");
$user->saveSettings();
}
} catch (PasswordError $pwe) {
$this->error($pwe->getText(), true);
}
}
# Promote user
array_map([$user, 'addGroup'], $promotions);
if (!$exists) {
# Increment site_stats.ss_users
$ssu = new SiteStatsUpdate(0, 0, 0, 0, 1);
$ssu->doUpdate();
}
$this->output("done.\n");
}
示例5: changeableGroups
/**
* Returns an array of groups that this user can add and remove
* @return Array array( 'add' => array( addablegroups ),
* 'remove' => array( removablegroups ),
* 'add-self' => array( addablegroups to self),
* 'remove-self' => array( removable groups from self) )
*/
public function changeableGroups()
{
if ($this->isAllowed('userrights')) {
// This group gives the right to modify everything (reverse-
// compatibility with old "userrights lets you change
// everything")
// Using array_merge to make the groups reindexed
$all = array_merge(User::getAllGroups());
return array('add' => $all, 'remove' => $all, 'add-self' => array(), 'remove-self' => array());
}
// Okay, it's not so simple, we will have to go through the arrays
$groups = array('add' => array(), 'remove' => array(), 'add-self' => array(), 'remove-self' => array());
$addergroups = $this->getEffectiveGroups();
foreach ($addergroups as $addergroup) {
$groups = array_merge_recursive($groups, $this->changeableByGroup($addergroup));
$groups['add'] = array_unique($groups['add']);
$groups['remove'] = array_unique($groups['remove']);
$groups['add-self'] = array_unique($groups['add-self']);
$groups['remove-self'] = array_unique($groups['remove-self']);
}
return $groups;
}
示例6: getAllowedParams
public function getAllowedParams()
{
return array('user' => array(ApiBase::PARAM_TYPE => 'string', ApiBase::PARAM_REQUIRED => true), 'add' => array(ApiBase::PARAM_TYPE => User::getAllGroups(), ApiBase::PARAM_ISMULTI => true), 'remove' => array(ApiBase::PARAM_TYPE => User::getAllGroups(), ApiBase::PARAM_ISMULTI => true), 'token' => array(ApiBase::PARAM_TYPE => 'string', ApiBase::PARAM_REQUIRED => true), 'reason' => array(ApiBase::PARAM_DFLT => ''));
}
示例7: getAllowedParams
public function getAllowedParams()
{
$userGroups = User::getAllGroups();
return array('from' => null, 'to' => null, 'prefix' => null, 'dir' => array(ApiBase::PARAM_DFLT => 'ascending', ApiBase::PARAM_TYPE => array('ascending', 'descending')), 'group' => array(ApiBase::PARAM_TYPE => $userGroups, ApiBase::PARAM_ISMULTI => true), 'excludegroup' => array(ApiBase::PARAM_TYPE => $userGroups, ApiBase::PARAM_ISMULTI => true), 'rights' => array(ApiBase::PARAM_TYPE => User::getAllRights(), ApiBase::PARAM_ISMULTI => true), 'prop' => array(ApiBase::PARAM_ISMULTI => true, ApiBase::PARAM_TYPE => array('blockinfo', 'groups', 'implicitgroups', 'rights', 'editcount', 'registration')), 'limit' => array(ApiBase::PARAM_DFLT => 10, ApiBase::PARAM_TYPE => 'limit', ApiBase::PARAM_MIN => 1, ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1, ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2), 'witheditsonly' => false, 'activeusers' => false);
}
示例8: getPageHeader
/**
* Show a drop down list to select a group as well as a user name
* search box.
* @todo localize
*/
function getPageHeader()
{
$self = $this->getTitle();
# Form tag
$out = wfOpenElement('form', array('method' => 'post', 'action' => $self->getLocalUrl()));
# Group drop-down list
$out .= wfElement('label', array('for' => 'group'), wfMsg('group')) . ' ';
$out .= wfOpenElement('select', array('name' => 'group'));
$out .= wfElement('option', array('value' => ''), wfMsg('group-all'));
# Item for "all groups"
$groups = User::getAllGroups();
foreach ($groups as $group) {
$attribs = array('value' => $group);
if ($group == $this->requestedGroup) {
$attribs['selected'] = 'selected';
}
$out .= wfElement('option', $attribs, User::getGroupName($group));
}
$out .= wfCloseElement('select') . ' ';
# . wfElement( 'br' );
# Username field
$out .= wfElement('label', array('for' => 'username'), wfMsg('specialloguserlabel')) . ' ';
$out .= wfElement('input', array('type' => 'text', 'id' => 'username', 'name' => 'username', 'value' => $this->requestedUser)) . ' ';
# Preserve offset and limit
if ($this->offset) {
$out .= wfElement('input', array('type' => 'hidden', 'name' => 'offset', 'value' => $this->offset));
}
if ($this->limit) {
$out .= wfElement('input', array('type' => 'hidden', 'name' => 'limit', 'value' => $this->limit));
}
# Submit button and form bottom
$out .= wfElement('input', array('type' => 'submit', 'value' => wfMsg('allpagessubmit')));
$out .= wfCloseElement('form');
return $out;
}
示例9: setGroups
/**
* Helper function for updateUser() and initUser(). Adds users into MediaWiki security groups
* based upon groups retreived from LDAP.
*
* @param User $user
* @access private
*/
function setGroups(&$user)
{
global $wgGroupPermissions;
// TODO: this is *really* ugly code. clean it up!
$this->printDebug("Entering setGroups.", NONSENSITIVE);
# Add ldap groups as local groups
if ($this->getConf('GroupsPrevail')) {
$this->printDebug("Adding all groups to wgGroupPermissions: ", SENSITIVE, $this->allLDAPGroups);
foreach ($this->allLDAPGroups["short"] as $ldapgroup) {
if (!array_key_exists($ldapgroup, $wgGroupPermissions)) {
$wgGroupPermissions[$ldapgroup] = array();
}
}
}
# add groups permissions
$localAvailGrps = $user->getAllGroups();
$localUserGrps = $user->getEffectiveGroups();
$defaultLocallyManagedGrps = array('bot', 'sysop', 'bureaucrat');
$locallyManagedGrps = $this->getConf('LocallyManagedGroups');
if ($locallyManagedGrps) {
$locallyManagedGrps = array_unique(array_merge($defaultLocallyManagedGrps, $locallyManagedGrps));
$this->printDebug("Locally managed groups: ", SENSITIVE, $locallyManagedGrps);
} else {
$locallyManagedGrps = $defaultLocallyManagedGrps;
$this->printDebug("Locally managed groups is unset, using defaults: ", SENSITIVE, $locallyManagedGrps);
}
$this->printDebug("Available groups are: ", NONSENSITIVE, $localAvailGrps);
$this->printDebug("Effective groups are: ", NONSENSITIVE, $localUserGrps);
# note: $localUserGrps does not need to be updated with $cGroup added,
# as $localAvailGrps contains $cGroup only once.
foreach ($localAvailGrps as $cGroup) {
# did we once add the user to the group?
if (in_array($cGroup, $localUserGrps)) {
$this->printDebug("Checking to see if we need to remove user from: {$cGroup}", NONSENSITIVE);
if (!$this->hasLDAPGroup($cGroup) && !in_array($cGroup, $locallyManagedGrps)) {
$this->printDebug("Removing user from: {$cGroup}", NONSENSITIVE);
# the ldap group overrides the local group
# so as the user is currently not a member of the ldap group, he shall be removed from the local group
$user->removeGroup($cGroup);
}
} else {
# no, but maybe the user has recently been added to the ldap group?
$this->printDebug("Checking to see if user is in: {$cGroup}", NONSENSITIVE);
if ($this->hasLDAPGroup($cGroup)) {
$this->printDebug("Adding user to: {$cGroup}", NONSENSITIVE);
$user->addGroup($cGroup);
}
}
}
}
示例10: doGET
function doGET()
{
global $wgLang, $wgOut, $wgUser, $wgAuth;
$this->validateGETParams();
$groupsHTML = '';
foreach (User::getAllGroups() as $groupName) {
$localName = User::getGroupMember($groupName);
$groupsHTML .= <<<EOT
<input id="grp{$groupName}" type="checkbox" name="groups[]" value="{$groupName}"/> <label for="grp{$groupName}">{$localName}</label><br/>
EOT;
}
$pwdtitleHref = Title::newFromText('passwordremindertitle', NS_MEDIAWIKI)->getLocalURL();
$pwdtextHref = Title::newFromText('passwordremindertext', NS_MEDIAWIKI)->getLocalURL();
$welcomeTitleHref = Title::newFromText('createaccount-title', NS_MEDIAWIKI)->getLocalURL();
$welcomeTextHref = Title::newFromText('createaccount-text', NS_MEDIAWIKI)->getLocalURL();
$returnToHTML = '';
if (!empty($this->returnto)) {
$returnToHTML = self::parse(wfMsg('uadm-returntomsg', $this->returnto));
}
$postURL = $this->getURL($this->mParams);
$editToken = $wgUser->editToken('adduser' . $wgUser->getName());
$previewPasswordEmailHref = $this->getURL(array('preview' => 'password') + $this->mParams);
$previewWelcomeEmailHref = $this->getURL(array('preview' => 'welcome') + $this->mParams);
$previewPasswordEmailHTML = '';
$previewWelcomeEmailHTML = '';
$setPasswordChecked = 'checked';
$emailPasswordChecked = '';
$emailWelcomeChecked = '';
if (!empty($this->preview)) {
$tempUser = new User();
$tempUser->setName($this->username);
$tempUser->setRealName($this->realname);
$tempUser->setEmail($this->email);
switch ($this->preview) {
case 'welcome':
list($subject, $body) = $this->getWelcomeMailMessage($tempUser);
break;
}
$previewHTML = <<<EOT
<table>
<tr>
<td>{$this->subjectlabel}</td>
<td><input value="{$subject}" size="70" disabled="disabled"/></td>
<tr>
<td colspan="2"><textarea rows="10" cols="80" disabled="disabled">{$body}</textarea></td>
</tr>
</table>
EOT;
switch ($this->preview) {
case 'welcome':
$previewWelcomeEmailHTML = $previewHTML;
$setPasswordChecked = '';
$emailWelcomeChecked = 'checked';
break;
}
}
# Hack to detect if domain is needed
$domainHTML = '';
$template = new UsercreateTemplate();
$temp = 'signup';
// Bug fix. This does nothing.
$wgAuth->autoCreate();
// The first time wgAuth is called, some PHP auto-magic involving StubObject
// occurs to "unstub" wgAuth AND call the function invoked. If the below
// call is made as written, the call is actually made by calling
// call_user_func_array and the arguments are passed by value even though
// the modifyUITemplate expects them to be by reference.
// This use to be a non issue since call-time pass-by-reference was allowed
// $wgAuth->modifyUITemplate(&$template, &$temp);
// This generates warnings now. Solution is to perform a no-op call to
// wgAuth to "unstub" it so that the below call will be made directly and
// not by call_user_func_array
$wgAuth->modifyUITemplate($template, $temp);
if (isset($template->data['usedomain']) && $template->data['usedomain'] == true) {
$domainHTML = <<<EOT
<tr>
<td><label for="domain">{$this->domainfield}</label></td>
<td><input id="domain" type="text" name="domain" size="30" value="{$this->domain}"/><br/></td>
</tr>
EOT;
}
return <<<EOT
<form id="adduserform" name="input" action="{$postURL}" method="post" class="visualClear">
<input type="hidden" name="edittoken" value="{$editToken}"/>
<fieldset>
<legend>{$this->adduserlabel}</legend>
<table>
<tr>
<td><label for="username">{$this->usernamefield}</label></td>
<td><input id="username" type="text" name="username" size="30" value="{$this->username}"/> {$this->requiredlabel}<br/></td>
</tr>
{$domainHTML}
<tr>
<td><label for="realname">{$this->realnamefield}</label></td>
<td><input id="realname" type="text" name="realname" size="30" value="{$this->realname}"/><br/></td>
</tr>
<tr>
<td><label for="email">{$this->emailfield}</label></td>
<td><input id="email" type="text" name="email" size="30" value="{$this->email}"/> {$this->requiredlabel}<br/></td>
</tr>
//.........这里部分代码省略.........
示例11: prefixSearchSubpages
/**
* Return an array of subpages beginning with $search that this special page will accept.
*
* @param string $search Prefix to search for
* @param int $limit Maximum number of results to return
* @return string[] Matching subpages
*/
public function prefixSearchSubpages($search, $limit = 10)
{
$subpages = User::getAllGroups();
return self::prefixSearchArray($search, $limit, $subpages);
}
示例12: setGroups
/**
* Helper function for updateUser() and initUser(). Adds users into MediaWiki security groups
* based upon groups retreived from LDAP.
*
* @param User $user
* @access private
*/
function setGroups(&$user)
{
$this->printDebug("Pulling groups from LDAP.", 1);
# add groups permissions
$localAvailGrps = $user->getAllGroups();
$localUserGrps = $user->getEffectiveGroups();
$this->printDebug("Available groups are: " . implode(",", $localAvailGrps) . "", 1);
$this->printDebug("Effective groups are: " . implode(",", $localUserGrps) . "", 1);
# note: $localUserGrps does not need to be updated with $cGroup added,
# as $localAvailGrps contains $cGroup only once.
foreach ($localAvailGrps as $cGroup) {
# did we once add the user to the group?
if (in_array($cGroup, $localUserGrps)) {
$this->printDebug("Checking to see if we need to remove user from: {$cGroup}", 1);
if (!$this->hasLDAPGroup($cGroup) && $this->isLDAPGroup($cGroup)) {
$this->printDebug("Removing user from: {$cGroup}", 1);
# the ldap group overrides the local group
# so as the user is currently not a member of the ldap group, he shall be removed from the local group
$user->removeGroup($cGroup);
}
} else {
# no, but maybe the user has recently been added to the ldap group?
$this->printDebug("Checking to see if user is in: {$cGroup}", 1);
if ($this->hasLDAPGroup($cGroup)) {
$this->printDebug("Adding user to: {$cGroup}", 1);
# so use the addGroup function
$user->addGroup($cGroup);
# completedfor $cGroup.
}
}
}
}
示例13: loadGroups
private function loadGroups()
{
global $wgContLang, $wgMemc;
wfProfileIn(__METHOD__);
$memkey = wfForeignMemcKey($this->mCityId, null, Listusers::TITLE, "groups", $wgContLang->getCode());
$cached = $wgMemc->get($memkey);
if (empty($cached)) {
$this->mGroups[Listusers::DEF_GROUP_NAME] = array('name' => wfMsg('listusersnogroup'), 'count' => 0);
$groups = User::getAllGroups();
if (is_array($groups) && !empty($groups)) {
foreach ($groups as $group) {
$this->mGroups[$group] = array('name' => User::getGroupName($group), 'count' => 0);
}
}
if (!empty($this->mGroups)) {
$records = $this->groupRecords();
if (!empty($records)) {
foreach ($records as $key => $count) {
$this->mGroups[$key]['count'] = $count;
}
}
}
} else {
$this->mGroups = $cached;
}
wfProfileOut(__METHOD__);
return $this->mGroups;
}
示例14: changeableByGroup
/**
* Returns an array of the groups that a particular group can add/remove.
*
* @param String $group The group to check for whether it can add/remove
* @return Array array( 'add' => array( addablegroups ), 'remove' => array( removablegroups ) )
*/
private function changeableByGroup($group)
{
global $wgGroupPermissions, $wgAddGroups, $wgRemoveGroups;
if (empty($wgGroupPermissions[$group]['userrights'])) {
// This group doesn't give the right to modify anything
return array('add' => array(), 'remove' => array());
}
if (empty($wgAddGroups[$group]) and empty($wgRemoveGroups[$group])) {
// This group gives the right to modify everything (reverse-
// compatibility with old "userrights lets you change
// everything")
return array('add' => User::getAllGroups(), 'remove' => User::getAllGroups());
}
// Okay, it's not so simple, we have to go through the arrays
$groups = array('add' => array(), 'remove' => array());
if (empty($wgAddGroups[$group])) {
// Don't add anything to $groups
} elseif ($wgAddGroups[$group] === true) {
// You get everything
$groups['add'] = User::getAllGroups();
} elseif (is_array($wgAddGroups[$group])) {
$groups['add'] = $wgAddGroups[$group];
}
// Same thing for remove
if (empty($wgRemoveGroups[$group])) {
} elseif ($wgRemoveGroups[$group] === true) {
$groups['remove'] = User::getAllGroups();
} elseif (is_array($wgRemoveGroups[$group])) {
$groups['remove'] = $wgRemoveGroups[$group];
}
return $groups;
}
示例15: getAllGroups
/**
* Returns an array of all groups that may be edited
* @return array Array of groups that may be edited.
*/
protected static function getAllGroups()
{
// add our wikiHow staff groups [sc - 1/16/2014]
global $wgGroupPermissions;
$wgGroupPermissions['staff_widget'] = $wgGroupPermissions['user'];
$wgGroupPermissions['translator'] = $wgGroupPermissions['user'];
return User::getAllGroups();
}