* http://www.gnu.org/copyleft/gpl.html
*/
-if (!defined('MEDIAWIKI')) {
+if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ("ApiBase.php");
+ require_once ( "ApiBase.php" );
}
*/
class ApiUserrights extends ApiBase {
- public function __construct($main, $action) {
- parent :: __construct($main, $action);
+ public function __construct( $main, $action ) {
+ parent :: __construct( $main, $action );
}
public function execute() {
global $wgUser;
$params = $this->extractRequestParams();
- if(is_null($params['user']))
- $this->dieUsageMsg(array('missingparam', 'user'));
- $user = User::newFromName($params['user']);
- if($user->isAnon())
- $this->dieUsageMsg(array('nosuchuser', $params['user']));
- if(is_null($params['token']))
- $this->dieUsageMsg(array('missingparam', 'token'));
- if(!$wgUser->matchEditToken($params['token'], $user->getName()))
- $this->dieUsageMsg(array('sessionfailure'));
+ if ( is_null( $params['user'] ) )
+ $this->dieUsageMsg( array( 'missingparam', 'user' ) );
+ if ( is_null( $params['token'] ) )
+ $this->dieUsageMsg( array( 'missingparam', 'token' ) );
+
+ $form = new UserrightsPage;
+ $user = $form->fetchUser( $params['user'] );
+ if ( $user instanceof WikiErrorMsg )
+ $this->dieUsageMsg( array_merge(
+ (array)$user->getMessageKey(),
+ $user->getMessageArgs() ) );
+ if ( !$wgUser->matchEditToken( $params['token'], $user->getName() ) )
+ $this->dieUsageMsg( array( 'sessionfailure' ) );
$r['user'] = $user->getName();
- list($r['added'], $r['removed']) =
- UserrightsPage::doSaveUserGroups(
+ list( $r['added'], $r['removed'] ) =
+ $form->doSaveUserGroups(
$user, (array)$params['add'],
- (array)$params['remove'], $params['reason']);
+ (array)$params['remove'], $params['reason'] );
- $this->getResult()->setIndexedTagName($r['added'], 'group');
- $this->getResult()->setIndexedTagName($r['removed'], 'group');
- $this->getResult()->addValue(null, $this->getModuleName(), $r);
+ $this->getResult()->setIndexedTagName( $r['added'], 'group' );
+ $this->getResult()->setIndexedTagName( $r['removed'], 'group' );
+ $this->getResult()->addValue( null, $this->getModuleName(), $r );
}
public function mustBePosted() {
public function getAllowedParams() {
return array (
- 'user' => array(
- ApiBase :: PARAM_TYPE => 'user'
- ),
+ 'user' => null,
'add' => array(
ApiBase :: PARAM_TYPE => User::getAllGroups(),
ApiBase :: PARAM_ISMULTI => true