4 * Created on Mar 24, 2009
5 * API for MediaWiki 1.8+
7 * Copyright (C) 2009 Roan Kattouw <Firstname>.<Lastname>@home.nl
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 * http://www.gnu.org/copyleft/gpl.html
25 if ( !defined( 'MEDIAWIKI' ) ) {
26 // Eclipse helper - will be ignored in production
27 require_once ( "ApiBase.php" );
33 class ApiUserrights extends ApiBase {
35 public function __construct( $main, $action ) {
36 parent :: __construct( $main, $action );
39 public function execute() {
40 $params = $this->extractRequestParams();
42 // User already validated in call to getTokenSalt from Main
43 $form = new UserrightsPage;
44 $user = $form->fetchUser( $params['user'] );
46 $r['user'] = $user->getName();
47 list( $r['added'], $r['removed'] ) =
48 $form->doSaveUserGroups(
49 $user, (array)$params['add'],
50 (array)$params['remove'], $params['reason'] );
52 $this->getResult()->setIndexedTagName( $r['added'], 'group' );
53 $this->getResult()->setIndexedTagName( $r['removed'], 'group' );
54 $this->getResult()->addValue( null, $this->getModuleName(), $r );
57 public function mustBePosted() {
61 public function isWriteMode() {
65 public function getAllowedParams() {
69 ApiBase :: PARAM_TYPE => User::getAllGroups(),
70 ApiBase :: PARAM_ISMULTI => true
73 ApiBase :: PARAM_TYPE => User::getAllGroups(),
74 ApiBase :: PARAM_ISMULTI => true
78 ApiBase :: PARAM_DFLT => ''
83 public function getParamDescription() {
85 'user' => 'User name',
86 'add' => 'Add the user to these groups',
87 'remove' => 'Remove the user from these groups',
88 'token' => 'A userrights token previously retrieved through list=users',
89 'reason' => 'Reason for the change',
93 public function getDescription() {
95 'Add/remove a user to/from groups',
99 public function getPossibleErrors() {
100 return array_merge( parent::getPossibleErrors(), array(
101 array( 'missingparam', 'user' ),
105 public function needsToken() {
109 public function getTokenSalt() {
110 $params = $this->extractRequestParams();
111 if ( is_null( $params['user'] ) )
112 $this->dieUsageMsg( array( 'missingparam', 'user' ) );
114 $form = new UserrightsPage;
115 $user = $form->fetchUser( $params['user'] );
116 if ( $user instanceof WikiErrorMsg )
117 $this->dieUsageMsg( array_merge(
118 (array)$user->getMessageKey(), $user->getMessageArgs() ) );
120 return $user->getName();
123 protected function getExamples() {
125 'api.php?action=userrights&user=FooBot&add=bot&remove=sysop|bureaucrat&token=123ABC'
129 public function getVersion() {
130 return __CLASS__ . ': $Id: ApiUserrights.php 74217 2010-10-03 15:53:07Z reedy $';