Fixed spacing in db/debug/diff/externalstore/objectcache folder
[mediawiki.git] / includes / api / ApiUserrights.php
blob80db29becc4327a6ba42d2073e80f095eb4c04ea
1 <?php
3 /**
6 * Created on Mar 24, 2009
8 * Copyright © 2009 Roan Kattouw "<Firstname>.<Lastname>@gmail.com"
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 * http://www.gnu.org/copyleft/gpl.html
25 * @file
28 /**
29 * @ingroup API
31 class ApiUserrights extends ApiBase {
33 private $mUser = null;
35 public function execute() {
36 $params = $this->extractRequestParams();
38 $user = $this->getUrUser();
40 $form = new UserrightsPage;
41 $r['user'] = $user->getName();
42 $r['userid'] = $user->getId();
43 list( $r['added'], $r['removed'] ) =
44 $form->doSaveUserGroups(
45 $user, (array)$params['add'],
46 (array)$params['remove'], $params['reason'] );
48 $result = $this->getResult();
49 $result->setIndexedTagName( $r['added'], 'group' );
50 $result->setIndexedTagName( $r['removed'], 'group' );
51 $result->addValue( null, $this->getModuleName(), $r );
54 /**
55 * @return User
57 private function getUrUser() {
58 if ( $this->mUser !== null ) {
59 return $this->mUser;
62 $params = $this->extractRequestParams();
64 $form = new UserrightsPage;
65 $status = $form->fetchUser( $params['user'] );
66 if ( !$status->isOK() ) {
67 $errors = $status->getErrorsArray();
68 $this->dieUsageMsg( $errors[0] );
69 } else {
70 $user = $status->value;
73 $this->mUser = $user;
74 return $user;
77 public function mustBePosted() {
78 return true;
81 public function isWriteMode() {
82 return true;
85 public function getAllowedParams() {
86 return array(
87 'user' => array(
88 ApiBase::PARAM_TYPE => 'string',
89 ApiBase::PARAM_REQUIRED => true
91 'add' => array(
92 ApiBase::PARAM_TYPE => User::getAllGroups(),
93 ApiBase::PARAM_ISMULTI => true
95 'remove' => array(
96 ApiBase::PARAM_TYPE => User::getAllGroups(),
97 ApiBase::PARAM_ISMULTI => true
99 'token' => array(
100 ApiBase::PARAM_TYPE => 'string',
101 ApiBase::PARAM_REQUIRED => true
103 'reason' => array(
104 ApiBase::PARAM_DFLT => ''
109 public function getParamDescription() {
110 return array(
111 'user' => 'User name',
112 'add' => 'Add the user to these groups',
113 'remove' => 'Remove the user from these groups',
114 'token' => 'A userrights token previously retrieved through list=users',
115 'reason' => 'Reason for the change',
119 public function getDescription() {
120 return 'Add/remove a user to/from groups';
123 public function needsToken() {
124 return true;
127 public function getTokenSalt() {
128 return $this->getUrUser()->getName();
131 public function getExamples() {
132 return array(
133 'api.php?action=userrights&user=FooBot&add=bot&remove=sysop|bureaucrat&token=123ABC'
137 public function getHelpUrls() {
138 return 'https://www.mediawiki.org/wiki/API:User_group_membership';