44 parent::__construct(
'Userrights' );
66 if (
$user->getId() == 0 ) {
70 return !empty( $available[
'add'] )
71 || !empty( $available[
'remove'] )
72 || ( ( $this->isself || !$checkIfSelf ) &&
73 ( !empty( $available[
'add-self'] )
74 || !empty( $available[
'remove-self'] ) ) );
97 if (
$user->isBlocked() && !
$user->isAllowed(
'userrights' ) ) {
101 if ( $par !== null ) {
102 $this->mTarget = $par;
104 $this->mTarget =
$request->getVal(
'user' );
107 if ( is_string( $this->mTarget ) ) {
108 $this->mTarget = trim( $this->mTarget );
113 if ( $this->mTarget === null ) {
119 if ( !count( $available[
'add'] ) && !count( $available[
'remove'] ) ) {
120 $this->mTarget =
$user->getName();
125 $this->isself =
true;
128 $fetchedStatus = $this->
fetchUser( $this->mTarget );
129 if ( $fetchedStatus->isOK() ) {
130 $this->mFetchedUser = $fetchedStatus->value;
131 if ( $this->mFetchedUser instanceof
User ) {
134 $this->
getSkin()->setRelevantUser( $this->mFetchedUser );
139 if ( $this->isself &&
$request->getCheck(
'success' ) ) {
144 $out->wrapWikiMsg(
"<div class=\"successbox\">\n$1\n</div>",
'userrights-removed-self' );
145 $out->returnToMain();
151 $msg =
$user->isAnon() ?
'userrights-nologin' :
'userrights-notallowed';
156 if (
$request->getCheck(
'success' ) && $this->mFetchedUser !== null ) {
157 $out->addModules( [
'mediawiki.special.userrights' ] );
158 $out->addModuleStyles(
'mediawiki.notification.convertmessagebox.styles' );
163 'class' =>
'mw-notify-success successbox',
164 'id' =>
'mw-preferences-success',
165 'data-mw-autohide' =>
'false',
170 $this->
msg(
'savedrights', $this->mFetchedUser->getName() )->
text()
181 $out->addModuleStyles(
'mediawiki.special' );
182 $this->
addHelpLink(
'Help:Assigning permissions' );
185 if ( count( $available[
'add'] ) || count( $available[
'remove'] ) ) {
191 $request->getCheck(
'saveusergroups' ) &&
192 $this->mTarget !== null &&
196 if ( !$fetchedStatus->isOK() ) {
197 $this->
getOutput()->addWikiText( $fetchedStatus->getWikiText() );
203 if ( $targetUser instanceof
User ) {
204 $targetUser->clearInstanceCache();
207 if (
$request->getVal(
'conflictcheck-originalgroups' )
208 !== implode(
',', $targetUser->getGroups() )
210 $out->addWikiMsg(
'userrights-conflict' );
225 if ( $this->mTarget !== null ) {
231 return $this->
getPageTitle( $this->mTarget )->getFullURL( [
'success' => 1 ] );
250 foreach ( $allgroups
as $group ) {
253 if ( $this->
getRequest()->getCheck(
"wpGroup-$group" ) ) {
254 $addgroup[] = $group;
256 $removegroup[] = $group;
275 $groups =
$user->getGroups();
277 $addable = array_merge( $changeable[
'add'],
$isself ? $changeable[
'add-self'] : [] );
278 $removable = array_merge( $changeable[
'remove'],
$isself ? $changeable[
'remove-self'] : [] );
280 $remove = array_unique(
281 array_intersect( (
array)$remove, $removable, $groups ) );
282 $add = array_unique( array_diff(
283 array_intersect( (
array)$add, $addable ),
287 $oldGroups =
$user->getGroups();
288 $newGroups = $oldGroups;
292 foreach ( $remove
as $index => $group ) {
293 if ( !
$user->removeGroup( $group ) ) {
294 unset( $remove[$index] );
297 $newGroups = array_diff( $newGroups, $remove );
300 foreach ( $add
as $index => $group ) {
301 if ( !
$user->addGroup( $group ) ) {
302 unset( $add[$index] );
305 $newGroups = array_merge( $newGroups, $add );
307 $newGroups = array_unique( $newGroups );
310 $user->invalidateCache();
315 'updateExternalDBGroups', [
$user, $add, $remove ]
318 wfDebug(
'oldGroups: ' . print_r( $oldGroups,
true ) .
"\n" );
319 wfDebug(
'newGroups: ' . print_r( $newGroups,
true ) .
"\n" );
323 if ( $newGroups != $oldGroups ) {
327 return [ $add, $remove ];
339 $logEntry->setPerformer( $this->
getUser() );
340 $logEntry->setTarget(
$user->getUserPage() );
341 $logEntry->setComment( $reason );
342 $logEntry->setParameters( [
343 '4::oldgroups' => $oldGroups,
344 '5::newgroups' => $newGroups,
346 $logid = $logEntry->insert();
347 $logEntry->publish( $logid );
364 $groups =
$user->getGroups();
382 $parts = explode( $this->
getConfig()->
get(
'UserrightsInterwikiDelimiter' ),
$username );
383 if ( count( $parts ) < 2 ) {
387 list(
$name, $database ) = array_map(
'trim', $parts );
392 if ( !$this->
getUser()->isAllowed(
'userrights-interwiki' ) ) {
401 if (
$name ===
'' ) {
405 if (
$name[0] ==
'#' ) {
408 $id = intval( substr(
$name, 1 ) );
410 if ( $database ==
'' ) {
421 if (
$name ===
false ) {
427 if ( $database ==
'' ) {
448 if ( empty( $ids ) ) {
449 return $this->
msg(
'rightsnone' )->inContentLanguage()->text();
451 return implode(
', ', $ids );
459 $this->
getOutput()->addModules(
'mediawiki.userSuggest' );
468 'id' =>
'mw-userrights-form1'
474 $this->
msg(
'userrights-user-editname' )->
text(),
478 str_replace(
'_',
' ', $this->mTarget ),
480 'class' =>
'mw-autocomplete-user',
483 $this->mFetchedUser === null ? [
'autofocus' =>
'' ] : []
489 $this->mFetchedUser === null ?
'[]' : $this->mFetchedUser->getName()
506 list( $addable, $removable, $addself, $removeself ) = array_values( $this->
changeableGroups() );
508 $removable = array_intersect(
509 array_merge( $this->isself ? $removeself : [], $removable ),
512 $addable = array_diff(
513 array_merge( $this->isself ? $addself : [], $addable ),
517 return [ $addable, $removable ];
529 foreach ( $groups
as $group ) {
530 $list[] = self::buildGroupLink( $group );
531 $membersList[] = self::buildGroupMemberLink( $group );
535 $autoMembersList = [];
538 $autoList[] = self::buildGroupLink( $group );
539 $autoMembersList[] = self::buildGroupMemberLink( $group );
544 $displayedList = $this->
msg(
'userrights-groupsmember-type' )
546 $language->listToText( $list ),
547 $language->listToText( $membersList )
549 $displayedAutolist = $this->
msg(
'userrights-groupsmember-type' )
551 $language->listToText( $autoList ),
552 $language->listToText( $autoMembersList )
558 $grouplist = $this->
msg(
'userrights-groupsmember' )
560 ->params(
$user->getName() )
562 $grouplist =
'<p>' . $grouplist .
' ' . $displayedList .
"</p>\n";
565 $count = count( $autoList );
567 $autogrouplistintro = $this->
msg(
'userrights-groupsmember-auto' )
569 ->params(
$user->getName() )
571 $grouplist .=
'<p>' . $autogrouplistintro .
' ' . $displayedAutolist .
"</p>\n";
587 'name' =>
'editGroup',
588 'id' =>
'mw-userrights-form2'
594 'conflictcheck-originalgroups',
595 implode(
',',
$user->getGroups() )
601 $this->
msg(
'userrights-editusergroup',
$user->getName() )->
text()
604 ->rawParams( $userToolLinks )->parse() .
605 $this->
msg(
'userrights-groups-help',
$user->getName() )->parse() .
610 <td class='mw-label'>" .
613 <td class='mw-input'>" .
615 [
'id' =>
'wpReason',
'maxlength' => 255 ] ) .
620 <td class='mw-submit'>" .
622 [
'name' =>
'saveusergroups' ] +
675 $columns = [
'unchangeable' => [],
'changeable' => [] ];
677 foreach ( $allgroups
as $group ) {
678 $set = in_array( $group, $usergroups );
681 ( $set && $this->
canRemove( $group ) ) ||
682 ( !$set && $this->
canAdd( $group ) ) );
684 $irreversible = !$disabled && (
685 ( $set && !$this->
canAdd( $group ) ) ||
686 ( !$set && !$this->
canRemove( $group ) ) );
690 'disabled' => $disabled,
691 'irreversible' => $irreversible
695 $columns[
'unchangeable'][$group] = $checkbox;
697 $columns[
'changeable'][$group] = $checkbox;
704 foreach ( $columns
as $name => $column ) {
705 if ( $column === [] ) {
712 $this->
msg(
'userrights-' .
$name .
'-col', count( $column ) )->
text()
716 $ret .=
"</tr>\n<tr>\n";
717 foreach ( $columns
as $column ) {
718 if ( $column === [] ) {
721 $ret .=
"\t<td style='vertical-align:top;'>\n";
722 foreach ( $column
as $group => $checkbox ) {
723 $attr = $checkbox[
'disabled'] ? [
'disabled' =>
'disabled' ] : [];
726 if ( $checkbox[
'irreversible'] ) {
727 $text = $this->
msg(
'userrights-irreversible-marker', $member )->text();
732 "wpGroup-" . $group, $checkbox[
'set'], $attr );
733 $ret .=
"\t\t" . ( $checkbox[
'disabled']
734 ?
Xml::tags(
'span', [
'class' =>
'mw-userrights-disabled' ], $checkboxHtml )
755 $groups[
'remove'] ) || ( $this->isself && in_array( $group, $groups[
'remove-self'] )
768 $groups[
'add'] ) || ( $this->isself && in_array( $group, $groups[
'add-self'] )
783 return $this->
getUser()->changeableGroups();
793 $rightsLogPage =
new LogPage(
'rights' );
static newFromName($name, $validate= 'valid')
Static factory method for creation from username.
showEditUserGroupsForm($user, $groups)
Show the form to edit group memberships.
static closeElement($element)
Returns "$element>".
static whoIs($id)
Get the username corresponding to a given user ID.
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
userCanExecute(User $user)
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
the array() calling protocol came about after MediaWiki 1.4rc1.
wfScript($script= 'index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
static element($element, $attribs=null, $contents= '', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
static buildGroupLink($group)
Format a link to a group description page.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
static whoIs($database, $id, $ignoreInvalidDB=false)
Same as User::whoIs()
static getCanonicalName($name, $validate= 'valid')
Given unvalidated user input, return a canonical username, or false if the username is invalid...
static newFatal($message)
Factory function for fatal errors.
static rawElement($element, $attribs=[], $contents= '')
Returns an HTML element in a string.
static newFromName($database, $name, $ignoreInvalidDB=false)
Factory function; get a remote user entry by name.
changeableGroups()
Returns $this->getUser()->changeableGroups()
fetchUser($username)
Normalize the input username, which may be local or remote, and return a user (or proxy) object for m...
static hidden($name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
static input($name, $size=false, $value=false, $attribs=[])
Convenience function to build an HTML text input field.
splitGroups($groups)
Go through used and available groups and return the ones that this form will be able to manipulate ba...
static inputLabel($label, $name, $id, $size=false, $value=false, $attribs=[])
Convenience function to build an HTML text input field with a label.
msg()
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
userCanChangeRights($user, $checkIfSelf=true)
static makeGroupLinkHTML($group, $text= '')
Create a link to the group in HTML, if available; else return the group name.
static tooltipAndAccesskeyAttribs($name, array $msgParams=[])
Returns the attributes for the tooltip and access key.
static submitButton($value, $attribs=[])
Convenience function to build an HTML submit button When $wgUseMediaWikiUIEverywhere is true it will ...
addHelpLink($to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
static label($label, $id, $attribs=[])
Convenience function to build an HTML form label.
wfDebug($text, $dest= 'all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
static showLogExtract(&$out, $types=[], $page= '', $user= '', $param=[])
Show log extract.
static getAllGroups()
Return the set of defined explicit groups.
outputHeader($summaryMessageKey= '')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
Class to simplify the use of log pages.
static fieldset($legend=false, $content=false, $attribs=[])
Shortcut for creating fieldsets.
static closeElement($element)
Shortcut to close an XML element.
prefixSearchSubpages($search, $limit, $offset)
Return an array of subpages beginning with $search that this special page will accept.
Parent class for all special pages.
static openElement($element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
wfEscapeWikiText($text)
Escapes the given text so that it may be output using addWikiText() without any linking, formatting, etc.
switchForm()
Output a form to allow searching for a user.
execute($par)
Manage forms to be shown according to posted data.
static validDatabase($database)
Confirm the selected database name is a valid local interwiki database name.
static search($audience, $search, $limit, $offset=0)
Do a prefix search of user names and return a list of matching user names.
static openElement($element, $attribs=null)
This opens an XML element.
getSkin()
Shortcut to get the skin being used for this instance.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes! ...
doSaveUserGroups($user, $add, $remove, $reason= '')
Save user groups changes in the database.
$mTarget
The target of the local right-adjuster's interest.
static newGood($value=null)
Factory function for good results.
static buildGroupMemberLink($group)
Format a link to a group member description page.
static run($event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
Show an error when the user tries to do something whilst blocked.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
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 local account $user
static getGroupName($group)
Get the localized descriptive name for a group, if it exists.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object & $output
groupCheckboxes($usergroups, $user)
Adds a table with checkboxes where you can select what groups to add/remove.
static getAllGroups()
Returns an array of all groups that may be edited.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
this hook is for auditing only or null if authentication failed before getting that far $username
static tags($element, $attribs=null, $contents)
Same as Xml::element(), but does not escape contents.
static getGroupMember($group, $username= '#')
Get the localized descriptive name for a member of a group, if it exists.
editUserGroupsForm($username)
Edit user groups membership.
Class for creating log entries manually, to inject them into the database.
error also a ContextSource you ll probably need to make sure the header is varied on $request
getUser()
Shortcut to get the User executing this instance.
getConfig()
Shortcut to get main config object.
addLogEntry($user, $oldGroups, $newGroups, $reason)
Add a rights log entry for an action.
Show an error when a user tries to do something they do not have the necessary permissions for...
static userToolLinks($userId, $userText, $redContribsWhenNoEdits=false, $flags=0, $edits=null)
Generate standard user tool links (talk, contributions, block link, etc.)
getLanguage()
Shortcut to get user's language.
saveUserGroups($username, $reason, $user)
Save user groups changes in the database.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object to manipulate or replace but no entry for that model exists in $wgContentHandlers if desired whether it is OK to use $contentModel on $title Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok inclusive $limit
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
Special page to allow managing user group membership.
static checkLabel($label, $name, $id, $checked=false, $attribs=[])
Convenience function to build an HTML checkbox with a label.
getRequest()
Get the WebRequest being used for this instance.
showLogFragment($user, $output)
Show a rights log fragment for the specified user.
checkReadOnly()
If the wiki is currently in readonly mode, throws a ReadOnlyError.
static element($element, $attribs=[], $contents= '')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
getPageTitle($subpage=false)
Get a self-referential title object.
Allows to change the fields on the form that will be generated $name