Removed unexisting parameter from doc
[mediawiki.git] / includes / api / ApiUserrights.php
blobdeb11f793046f3cb99e2339b76b5ad9211fc5b99
1 <?php
3 /**
4 * API for MediaWiki 1.8+
6 * Created on Mar 24, 2009
8 * Copyright © 2009 Roan Kattouw <Firstname>.<Lastname>@home.nl
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 if ( !defined( 'MEDIAWIKI' ) ) {
29 // Eclipse helper - will be ignored in production
30 require_once( "ApiBase.php" );
33 /**
34 * @ingroup API
36 class ApiUserrights extends ApiBase {
38 public function __construct( $main, $action ) {
39 parent::__construct( $main, $action );
42 private $mUser = null;
44 public function execute() {
45 $params = $this->extractRequestParams();
47 $user = $this->getUser();
49 $form = new UserrightsPage;
50 $r['user'] = $user->getName();
51 list( $r['added'], $r['removed'] ) =
52 $form->doSaveUserGroups(
53 $user, (array)$params['add'],
54 (array)$params['remove'], $params['reason'] );
56 $this->getResult()->setIndexedTagName( $r['added'], 'group' );
57 $this->getResult()->setIndexedTagName( $r['removed'], 'group' );
58 $this->getResult()->addValue( null, $this->getModuleName(), $r );
61 private function getUser() {
62 if ( $this->mUser !== null ) {
63 return $this->mUser;
66 $params = $this->extractRequestParams();
68 $form = new UserrightsPage;
69 $status = $form->fetchUser( $params['user'] );
70 if ( !$status->isOK() ) {
71 $errors = $status->getErrorsArray();
72 $this->dieUsageMsg( $errors[0] );
73 } else {
74 $user = $status->value;
77 $this->mUser = $user;
78 return $user;
81 public function mustBePosted() {
82 return true;
85 public function isWriteMode() {
86 return true;
89 public function getAllowedParams() {
90 return array (
91 'user' => array(
92 ApiBase::PARAM_TYPE => 'string',
93 ApiBase::PARAM_REQUIRED => true
95 'add' => array(
96 ApiBase::PARAM_TYPE => User::getAllGroups(),
97 ApiBase::PARAM_ISMULTI => true
99 'remove' => array(
100 ApiBase::PARAM_TYPE => User::getAllGroups(),
101 ApiBase::PARAM_ISMULTI => true
103 'token' => null,
104 'reason' => array(
105 ApiBase::PARAM_DFLT => ''
110 public function getParamDescription() {
111 return array(
112 'user' => 'User name',
113 'add' => 'Add the user to these groups',
114 'remove' => 'Remove the user from these groups',
115 'token' => 'A userrights token previously retrieved through list=users',
116 'reason' => 'Reason for the change',
120 public function getDescription() {
121 return 'Add/remove a user to/from groups';
124 public function needsToken() {
125 return true;
128 public function getTokenSalt() {
129 return $this->getUser()->getName();
132 protected function getExamples() {
133 return array(
134 'api.php?action=userrights&user=FooBot&add=bot&remove=sysop|bureaucrat&token=123ABC'
138 public function getVersion() {
139 return __CLASS__ . ': $Id$';