diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2014-12-27 15:41:37 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2014-12-31 11:43:28 +0100 |
commit | c1f9b1f7b1b77776192048005dcc66dcf3df2bfb (patch) | |
tree | 2b38796e738dd74cb42ecd9bfd151803108386bc /includes/api/ApiUserrights.php | |
parent | b88ab0086858470dd1f644e64cb4e4f62bb2be9b (diff) |
Update to MediaWiki 1.24.1
Diffstat (limited to 'includes/api/ApiUserrights.php')
-rw-r--r-- | includes/api/ApiUserrights.php | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/includes/api/ApiUserrights.php b/includes/api/ApiUserrights.php index 7d308285..c3ceb345 100644 --- a/includes/api/ApiUserrights.php +++ b/includes/api/ApiUserrights.php @@ -35,16 +35,16 @@ class ApiUserrights extends ApiBase { public function execute() { $params = $this->extractRequestParams(); - $user = $this->getUrUser(); + $user = $this->getUrUser( $params ); $form = new UserrightsPage; $form->setContext( $this->getContext() ); $r['user'] = $user->getName(); $r['userid'] = $user->getId(); - list( $r['added'], $r['removed'] ) = - $form->doSaveUserGroups( - $user, (array)$params['add'], - (array)$params['remove'], $params['reason'] ); + list( $r['added'], $r['removed'] ) = $form->doSaveUserGroups( + $user, (array)$params['add'], + (array)$params['remove'], $params['reason'] + ); $result = $this->getResult(); $result->setIndexedTagName( $r['added'], 'group' ); @@ -53,26 +53,28 @@ class ApiUserrights extends ApiBase { } /** + * @param array $params * @return User */ - private function getUrUser() { + private function getUrUser( array $params ) { if ( $this->mUser !== null ) { return $this->mUser; } - $params = $this->extractRequestParams(); + $this->requireOnlyOneParameter( $params, 'user', 'userid' ); + + $user = isset( $params['user'] ) ? $params['user'] : '#' . $params['userid']; $form = new UserrightsPage; $form->setContext( $this->getContext() ); - $status = $form->fetchUser( $params['user'] ); + $status = $form->fetchUser( $user ); if ( !$status->isOK() ) { $this->dieStatus( $status ); - } else { - $user = $status->value; } - $this->mUser = $user; - return $user; + $this->mUser = $status->value; + + return $status->value; } public function mustBePosted() { @@ -87,7 +89,9 @@ class ApiUserrights extends ApiBase { return array( 'user' => array( ApiBase::PARAM_TYPE => 'string', - ApiBase::PARAM_REQUIRED => true + ), + 'userid' => array( + ApiBase::PARAM_TYPE => 'integer', ), 'add' => array( ApiBase::PARAM_TYPE => User::getAllGroups(), @@ -97,10 +101,6 @@ class ApiUserrights extends ApiBase { ApiBase::PARAM_TYPE => User::getAllGroups(), ApiBase::PARAM_ISMULTI => true ), - 'token' => array( - ApiBase::PARAM_TYPE => 'string', - ApiBase::PARAM_REQUIRED => true - ), 'reason' => array( ApiBase::PARAM_DFLT => '' ) @@ -110,28 +110,33 @@ class ApiUserrights extends ApiBase { public function getParamDescription() { return array( 'user' => 'User name', + 'userid' => 'User id', 'add' => 'Add the user to these groups', 'remove' => 'Remove the user from these groups', - 'token' => 'A userrights token previously retrieved through list=users', + 'token' => array( + /* Standard description automatically prepended */ + 'For compatibility, the token used in the web UI is also accepted.' + ), 'reason' => 'Reason for the change', ); } public function getDescription() { - return 'Add/remove a user to/from groups'; + return 'Add/remove a user to/from groups.'; } public function needsToken() { - return true; + return 'userrights'; } - public function getTokenSalt() { - return $this->getUrUser()->getName(); + protected function getWebUITokenSalt( array $params ) { + return $this->getUrUser( $params )->getName(); } public function getExamples() { return array( - 'api.php?action=userrights&user=FooBot&add=bot&remove=sysop|bureaucrat&token=123ABC' + 'api.php?action=userrights&user=FooBot&add=bot&remove=sysop|bureaucrat&token=123ABC', + 'api.php?action=userrights&userid=123&add=bot&remove=sysop|bureaucrat&token=123ABC' ); } |