2009-03-28 19:08:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
2010-02-26 13:18:56 +00:00
|
|
|
/**
|
2009-03-28 19:08:47 +00:00
|
|
|
* Created on Mar 24, 2009
|
|
|
|
|
* API for MediaWiki 1.8+
|
|
|
|
|
*
|
2010-02-26 13:18:56 +00:00
|
|
|
* Copyright © 2009 Roan Kattouw <Firstname>.<Lastname>@home.nl
|
2009-03-28 19:08:47 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*/
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( !defined( 'MEDIAWIKI' ) ) {
|
2009-03-28 19:08:47 +00:00
|
|
|
// Eclipse helper - will be ignored in production
|
2010-02-26 13:18:56 +00:00
|
|
|
require_once( "ApiBase.php" );
|
2009-03-28 19:08:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @ingroup API
|
|
|
|
|
*/
|
|
|
|
|
class ApiUserrights extends ApiBase {
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
public function __construct( $main, $action ) {
|
2010-02-26 13:18:56 +00:00
|
|
|
parent::__construct( $main, $action );
|
2009-03-28 19:08:47 +00:00
|
|
|
}
|
|
|
|
|
|
2010-04-10 13:33:24 +00:00
|
|
|
private $mUser = null;
|
|
|
|
|
|
2009-03-28 19:08:47 +00:00
|
|
|
public function execute() {
|
|
|
|
|
$params = $this->extractRequestParams();
|
2010-02-26 13:18:56 +00:00
|
|
|
|
2010-04-10 13:33:24 +00:00
|
|
|
$user = $this->getUser();
|
2010-02-26 13:18:56 +00:00
|
|
|
|
2010-04-17 02:43:13 +00:00
|
|
|
$form = new UserrightsPage;
|
2009-03-28 19:08:47 +00:00
|
|
|
$r['user'] = $user->getName();
|
2010-01-11 15:55:52 +00:00
|
|
|
list( $r['added'], $r['removed'] ) =
|
2009-03-29 16:39:42 +00:00
|
|
|
$form->doSaveUserGroups(
|
2009-03-28 19:08:47 +00:00
|
|
|
$user, (array)$params['add'],
|
2010-01-11 15:55:52 +00:00
|
|
|
(array)$params['remove'], $params['reason'] );
|
2009-03-28 19:08:47 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->getResult()->setIndexedTagName( $r['added'], 'group' );
|
|
|
|
|
$this->getResult()->setIndexedTagName( $r['removed'], 'group' );
|
|
|
|
|
$this->getResult()->addValue( null, $this->getModuleName(), $r );
|
2009-03-28 19:08:47 +00:00
|
|
|
}
|
2010-05-11 22:30:18 +00:00
|
|
|
|
|
|
|
|
private function getUser() {
|
|
|
|
|
if ( $this->mUser !== null ) {
|
|
|
|
|
return $this->mUser;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$params = $this->extractRequestParams();
|
|
|
|
|
if ( is_null( $params['user'] ) ) {
|
|
|
|
|
$this->dieUsageMsg( array( 'missingparam', 'user' ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$form = new UserrightsPage;
|
|
|
|
|
$status = $form->fetchUser( $params['user'] );
|
|
|
|
|
if ( !$status->isOK() ) {
|
|
|
|
|
$errors = $status->getErrorsArray();
|
|
|
|
|
$this->dieUsageMsg( $errors[0] );
|
|
|
|
|
} else {
|
|
|
|
|
$user = $status->value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->mUser = $user;
|
|
|
|
|
return $user;
|
|
|
|
|
}
|
2009-03-28 19:08:47 +00:00
|
|
|
|
|
|
|
|
public function mustBePosted() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function isWriteMode() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getAllowedParams() {
|
|
|
|
|
return array (
|
2009-03-29 16:39:42 +00:00
|
|
|
'user' => null,
|
2009-03-28 19:08:47 +00:00
|
|
|
'add' => array(
|
2010-02-26 13:18:56 +00:00
|
|
|
ApiBase::PARAM_TYPE => User::getAllGroups(),
|
|
|
|
|
ApiBase::PARAM_ISMULTI => true
|
2009-03-28 19:08:47 +00:00
|
|
|
),
|
|
|
|
|
'remove' => array(
|
2010-02-26 13:18:56 +00:00
|
|
|
ApiBase::PARAM_TYPE => User::getAllGroups(),
|
|
|
|
|
ApiBase::PARAM_ISMULTI => true
|
2009-03-28 19:08:47 +00:00
|
|
|
),
|
|
|
|
|
'token' => null,
|
|
|
|
|
'reason' => array(
|
2010-02-26 13:18:56 +00:00
|
|
|
ApiBase::PARAM_DFLT => ''
|
2009-03-28 19:08:47 +00:00
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getParamDescription() {
|
2010-02-26 13:18:56 +00:00
|
|
|
return array(
|
2009-03-28 19:08:47 +00:00
|
|
|
'user' => 'User name',
|
|
|
|
|
'add' => 'Add the user to these groups',
|
|
|
|
|
'remove' => 'Remove the user from these groups',
|
|
|
|
|
'token' => 'A userrights token previously retrieved through list=users',
|
|
|
|
|
'reason' => 'Reason for the change',
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getDescription() {
|
2010-05-25 20:46:09 +00:00
|
|
|
return 'Add/remove a user to/from groups';
|
2009-03-28 19:08:47 +00:00
|
|
|
}
|
2010-02-26 13:18:56 +00:00
|
|
|
|
|
|
|
|
public function getPossibleErrors() {
|
2010-02-13 00:09:05 +00:00
|
|
|
return array_merge( parent::getPossibleErrors(), array(
|
|
|
|
|
array( 'missingparam', 'user' ),
|
2010-02-26 13:18:56 +00:00
|
|
|
) );
|
2010-02-13 00:09:05 +00:00
|
|
|
}
|
2010-02-26 13:18:56 +00:00
|
|
|
|
2010-02-15 23:53:43 +00:00
|
|
|
public function getTokenSalt() {
|
2010-04-10 13:33:24 +00:00
|
|
|
return $this->getUser()->getName();
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-28 19:08:47 +00:00
|
|
|
protected function getExamples() {
|
2010-02-26 13:18:56 +00:00
|
|
|
return array(
|
2009-03-28 19:08:47 +00:00
|
|
|
'api.php?action=userrights&user=FooBot&add=bot&remove=sysop|bureaucrat&token=123ABC'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getVersion() {
|
|
|
|
|
return __CLASS__ . ': $Id$';
|
|
|
|
|
}
|
|
|
|
|
}
|