00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 if ( !defined( 'MEDIAWIKI' ) ) {
00026
00027 require_once ( "ApiBase.php" );
00028 }
00029
00033 class ApiUserrights extends ApiBase {
00034
00035 public function __construct( $main, $action ) {
00036 parent :: __construct( $main, $action );
00037 }
00038
00039 public function execute() {
00040 $params = $this->extractRequestParams();
00041
00042
00043 $form = new UserrightsPage;
00044 $user = $form->fetchUser( $params['user'] );
00045
00046 $r['user'] = $user->getName();
00047 list( $r['added'], $r['removed'] ) =
00048 $form->doSaveUserGroups(
00049 $user, (array)$params['add'],
00050 (array)$params['remove'], $params['reason'] );
00051
00052 $this->getResult()->setIndexedTagName( $r['added'], 'group' );
00053 $this->getResult()->setIndexedTagName( $r['removed'], 'group' );
00054 $this->getResult()->addValue( null, $this->getModuleName(), $r );
00055 }
00056
00057 public function mustBePosted() {
00058 return true;
00059 }
00060
00061 public function isWriteMode() {
00062 return true;
00063 }
00064
00065 public function getAllowedParams() {
00066 return array (
00067 'user' => null,
00068 'add' => array(
00069 ApiBase :: PARAM_TYPE => User::getAllGroups(),
00070 ApiBase :: PARAM_ISMULTI => true
00071 ),
00072 'remove' => array(
00073 ApiBase :: PARAM_TYPE => User::getAllGroups(),
00074 ApiBase :: PARAM_ISMULTI => true
00075 ),
00076 'token' => null,
00077 'reason' => array(
00078 ApiBase :: PARAM_DFLT => ''
00079 )
00080 );
00081 }
00082
00083 public function getParamDescription() {
00084 return array (
00085 'user' => 'User name',
00086 'add' => 'Add the user to these groups',
00087 'remove' => 'Remove the user from these groups',
00088 'token' => 'A userrights token previously retrieved through list=users',
00089 'reason' => 'Reason for the change',
00090 );
00091 }
00092
00093 public function getDescription() {
00094 return array(
00095 'Add/remove a user to/from groups',
00096 );
00097 }
00098
00099 public function getPossibleErrors() {
00100 return array_merge( parent::getPossibleErrors(), array(
00101 array( 'missingparam', 'user' ),
00102 ) );
00103 }
00104
00105 public function needsToken() {
00106 return true;
00107 }
00108
00109 public function getTokenSalt() {
00110 $params = $this->extractRequestParams();
00111 if ( is_null( $params['user'] ) )
00112 $this->dieUsageMsg( array( 'missingparam', 'user' ) );
00113
00114 $form = new UserrightsPage;
00115 $user = $form->fetchUser( $params['user'] );
00116 if ( $user instanceof WikiErrorMsg )
00117 $this->dieUsageMsg( array_merge(
00118 (array)$user->getMessageKey(), $user->getMessageArgs() ) );
00119
00120 return $user->getName();
00121 }
00122
00123 protected function getExamples() {
00124 return array (
00125 'api.php?action=userrights&user=FooBot&add=bot&remove=sysop|bureaucrat&token=123ABC'
00126 );
00127 }
00128
00129 public function getVersion() {
00130 return __CLASS__ . ': $Id: ApiUserrights.php 74217 2010-10-03 15:53:07Z reedy $';
00131 }
00132 }