Merge "Add documentation to clarify difference between save and upload message"
[lhc/web/wiklou.git] / includes / api / ApiUserrights.php
index 66af4c5..e32b612 100644 (file)
@@ -49,6 +49,14 @@ class ApiUserrights extends ApiBase {
        }
 
        public function execute() {
+               $pUser = $this->getUser();
+
+               // Deny if the user is blocked and doesn't have the full 'userrights' permission.
+               // This matches what Special:UserRights does for the web UI.
+               if ( $pUser->isBlocked() && !$pUser->isAllowed( 'userrights' ) ) {
+                       $this->dieBlocked( $pUser->getBlock() );
+               }
+
                $params = $this->extractRequestParams();
 
                $user = $this->getUrUser( $params );
@@ -63,8 +71,8 @@ class ApiUserrights extends ApiBase {
                );
 
                $result = $this->getResult();
-               $result->setIndexedTagName( $r['added'], 'group' );
-               $result->setIndexedTagName( $r['removed'], 'group' );
+               ApiResult::setIndexedTagName( $r['added'], 'group' );
+               ApiResult::setIndexedTagName( $r['removed'], 'group' );
                $result->addValue( null, $this->getModuleName(), $r );
        }
 
@@ -119,28 +127,14 @@ class ApiUserrights extends ApiBase {
                        ),
                        'reason' => array(
                                ApiBase::PARAM_DFLT => ''
-                       )
-               );
-       }
-
-       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' => array(
-                               /* Standard description automatically prepended */
-                               'For compatibility, the token used in the web UI is also accepted.'
+                               // Standard definition automatically inserted
+                               ApiBase::PARAM_HELP_MSG_APPEND => array( 'api-help-param-token-webui' ),
                        ),
-                       'reason' => 'Reason for the change',
                );
        }
 
-       public function getDescription() {
-               return 'Add/remove a user to/from groups.';
-       }
-
        public function needsToken() {
                return 'userrights';
        }
@@ -149,10 +143,12 @@ class ApiUserrights extends ApiBase {
                return $this->getUrUser( $params )->getName();
        }
 
-       public function getExamples() {
+       protected function getExamplesMessages() {
                return array(
-                       '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'
+                       'action=userrights&user=FooBot&add=bot&remove=sysop|bureaucrat&token=123ABC'
+                               => 'apihelp-userrights-example-user',
+                       'action=userrights&userid=123&add=bot&remove=sysop|bureaucrat&token=123ABC'
+                               => 'apihelp-userrights-example-userid',
                );
        }