Merge "Change mw-ui anchors to require mw-ui-anchor base class, and introduce mw...
[lhc/web/wiklou.git] / includes / api / ApiUserrights.php
index 0bed859..66af4c5 100644 (file)
@@ -32,12 +32,28 @@ class ApiUserrights extends ApiBase {
 
        private $mUser = null;
 
+       /**
+        * Get a UserrightsPage object, or subclass.
+        * @return UserrightsPage
+        */
+       protected function getUserRightsPage() {
+               return new UserrightsPage;
+       }
+
+       /**
+        * Get all available groups.
+        * @return array
+        */
+       protected function getAllGroups() {
+               return User::getAllGroups();
+       }
+
        public function execute() {
                $params = $this->extractRequestParams();
 
-               $user = $this->getUrUser();
+               $user = $this->getUrUser( $params );
 
-               $form = new UserrightsPage;
+               $form = $this->getUserRightsPage();
                $form->setContext( $this->getContext() );
                $r['user'] = $user->getName();
                $r['userid'] = $user->getId();
@@ -53,19 +69,19 @@ 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 = $this->getUserRightsPage();
                $form->setContext( $this->getContext() );
                $status = $form->fetchUser( $user );
                if ( !$status->isOK() ) {
@@ -94,17 +110,13 @@ class ApiUserrights extends ApiBase {
                                ApiBase::PARAM_TYPE => 'integer',
                        ),
                        'add' => array(
-                               ApiBase::PARAM_TYPE => User::getAllGroups(),
+                               ApiBase::PARAM_TYPE => $this->getAllGroups(),
                                ApiBase::PARAM_ISMULTI => true
                        ),
                        'remove' => array(
-                               ApiBase::PARAM_TYPE => User::getAllGroups(),
+                               ApiBase::PARAM_TYPE => $this->getAllGroups(),
                                ApiBase::PARAM_ISMULTI => true
                        ),
-                       'token' => array(
-                               ApiBase::PARAM_TYPE => 'string',
-                               ApiBase::PARAM_REQUIRED => true
-                       ),
                        'reason' => array(
                                ApiBase::PARAM_DFLT => ''
                        )
@@ -117,7 +129,10 @@ class ApiUserrights extends ApiBase {
                        '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',
                );
        }
@@ -127,11 +142,11 @@ class ApiUserrights extends ApiBase {
        }
 
        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() {