MediaWiki  1.23.12
ApiUserrights.php
Go to the documentation of this file.
1 <?php
2 
31 class ApiUserrights extends ApiBase {
32 
33  private $mUser = null;
34 
35  public function execute() {
36  $params = $this->extractRequestParams();
37 
38  $user = $this->getUrUser();
39 
40  $form = new UserrightsPage;
41  $form->setContext( $this->getContext() );
42  $r['user'] = $user->getName();
43  $r['userid'] = $user->getId();
44  list( $r['added'], $r['removed'] ) = $form->doSaveUserGroups(
45  $user, (array)$params['add'],
46  (array)$params['remove'], $params['reason']
47  );
48 
49  $result = $this->getResult();
50  $result->setIndexedTagName( $r['added'], 'group' );
51  $result->setIndexedTagName( $r['removed'], 'group' );
52  $result->addValue( null, $this->getModuleName(), $r );
53  }
54 
58  private function getUrUser() {
59  if ( $this->mUser !== null ) {
60  return $this->mUser;
61  }
62 
63  $params = $this->extractRequestParams();
64  $this->requireOnlyOneParameter( $params, 'user', 'userid' );
65 
66  $user = isset( $params['user'] ) ? $params['user'] : '#' . $params['userid'];
67 
68  $form = new UserrightsPage;
69  $form->setContext( $this->getContext() );
70  $status = $form->fetchUser( $user );
71  if ( !$status->isOK() ) {
72  $this->dieStatus( $status );
73  }
74 
75  $this->mUser = $status->value;
76 
77  return $status->value;
78  }
79 
80  public function mustBePosted() {
81  return true;
82  }
83 
84  public function isWriteMode() {
85  return true;
86  }
87 
88  public function getAllowedParams() {
89  return array(
90  'user' => array(
91  ApiBase::PARAM_TYPE => 'string',
92  ),
93  'userid' => array(
94  ApiBase::PARAM_TYPE => 'integer',
95  ),
96  'add' => array(
99  ),
100  'remove' => array(
102  ApiBase::PARAM_ISMULTI => true
103  ),
104  'token' => array(
105  ApiBase::PARAM_TYPE => 'string',
107  ),
108  'reason' => array(
109  ApiBase::PARAM_DFLT => ''
110  )
111  );
112  }
113 
114  public function getParamDescription() {
115  return array(
116  'user' => 'User name',
117  'userid' => 'User id',
118  'add' => 'Add the user to these groups',
119  'remove' => 'Remove the user from these groups',
120  'token' => 'A userrights token previously retrieved through list=users',
121  'reason' => 'Reason for the change',
122  );
123  }
124 
125  public function getDescription() {
126  return 'Add/remove a user to/from groups.';
127  }
128 
129  public function needsToken() {
130  return true;
131  }
132 
133  public function getTokenSalt() {
134  return $this->getUrUser()->getName();
135  }
136 
137  public function getExamples() {
138  return array(
139  'api.php?action=userrights&user=FooBot&add=bot&remove=sysop|bureaucrat&token=123ABC',
140  'api.php?action=userrights&userid=123&add=bot&remove=sysop|bureaucrat&token=123ABC'
141  );
142  }
143 
144  public function getHelpUrls() {
145  return 'https://www.mediawiki.org/wiki/API:User_group_membership';
146  }
147 }
ApiBase\dieStatus
dieStatus( $status)
Throw a UsageException based on the errors in the Status object.
Definition: ApiBase.php:1419
$result
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. $reader:XMLReader object $logInfo:Array of information Return false to stop further processing of the tag 'ImportHandlePageXMLTag':When parsing a XML tag in a page. $reader:XMLReader object $pageInfo:Array of information Return false to stop further processing of the tag 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information Return false to stop further processing of the tag 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. $reader:XMLReader object Return false to stop further processing of the tag 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. $reader:XMLReader object $revisionInfo:Array of information Return false to stop further processing of the tag 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. $title:Title object for the current page $request:WebRequest $ignoreRedirect:boolean to skip redirect check $target:Title/string of redirect target $article:Article object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) $article:article(object) being checked 'IsTrustedProxy':Override the result of wfIsTrustedProxy() $ip:IP being check $result:Change this value to override the result of wfIsTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of User::isValidEmailAddr(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetMagic':DEPRECATED, use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetSpecialPageAliases':DEPRECATED, use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Associative array mapping language codes to prefixed links of the form "language:title". & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LinkBegin':Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1528
ContextSource\getContext
getContext()
Get the RequestContext object.
Definition: ContextSource.php:40
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
ApiBase\PARAM_REQUIRED
const PARAM_REQUIRED
Definition: ApiBase.php:62
$form
usually copyright or history_copyright This message must be in HTML not wikitext $subpages will be ignored and the rest of subPageSubtitle() will run. 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink' whether MediaWiki currently thinks this is a CSS JS page Hooks may change this value to override the return value of Title::isCssOrJsPage(). 'TitleIsAlwaysKnown' whether MediaWiki currently thinks this page is known isMovable() always returns false. $title whether MediaWiki currently thinks this page is movable Hooks may change this value to override the return value of Title::isMovable(). 'TitleIsWikitextPage' whether MediaWiki currently thinks this is a wikitext page Hooks may change this value to override the return value of Title::isWikitextPage() 'TitleMove' use UploadVerification and UploadVerifyFile instead $form
Definition: hooks.txt:2578
ApiBase\PARAM_TYPE
const PARAM_TYPE
Definition: ApiBase.php:50
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:205
ApiUserrights\$mUser
$mUser
Definition: ApiUserrights.php:33
ApiUserrights\mustBePosted
mustBePosted()
Indicates whether this module must be called with a POST request.
Definition: ApiUserrights.php:80
ApiUserrights\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiUserrights.php:88
$params
$params
Definition: styleTest.css.php:40
ApiUserrights\needsToken
needsToken()
Returns whether this module requires a token to execute It is used to show possible errors in action=...
Definition: ApiUserrights.php:129
ApiBase
This abstract class implements many basic API functions, and is the base of all API classes.
Definition: ApiBase.php:42
ApiUserrights\getTokenSalt
getTokenSalt()
Returns the token salt if there is one, '' if the module doesn't require a salt, else false if the mo...
Definition: ApiUserrights.php:133
ApiUserrights\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiUserrights.php:35
UserrightsPage
Special page to allow managing user group membership.
Definition: SpecialUserrights.php:29
ApiUserrights\getHelpUrls
getHelpUrls()
Definition: ApiUserrights.php:144
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
list
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
ApiBase\extractRequestParams
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:687
ApiBase\requireOnlyOneParameter
requireOnlyOneParameter( $params)
Die if none or more than one of a certain set of parameters is set and not false.
Definition: ApiBase.php:722
ApiUserrights
Definition: ApiUserrights.php:31
ApiUserrights\getExamples
getExamples()
Returns usage examples for this module.
Definition: ApiUserrights.php:137
User\getAllGroups
static getAllGroups()
Return the set of defined explicit groups.
Definition: User.php:4222
ApiUserrights\getDescription
getDescription()
Returns the description string for this module.
Definition: ApiUserrights.php:125
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:237
ApiUserrights\getParamDescription
getParamDescription()
Returns an array of parameter descriptions.
Definition: ApiUserrights.php:114
ApiUserrights\getUrUser
getUrUser()
Definition: ApiUserrights.php:58
ApiBase\PARAM_DFLT
const PARAM_DFLT
Definition: ApiBase.php:46
ApiBase\getModuleName
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:148
ApiBase\PARAM_ISMULTI
const PARAM_ISMULTI
Definition: ApiBase.php:48
ApiUserrights\isWriteMode
isWriteMode()
Indicates whether this module requires write mode.
Definition: ApiUserrights.php:84