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();
124 if ( $this->mTarget !==
null && User::getCanonicalName( $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 &&
193 $user->matchEditToken(
$request->getVal(
'wpEditToken' ), $this->mTarget )
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();
313 Hooks::run(
'UserGroupsChanged', [
$user, $add, $remove, $this->
getUser(), $reason ] );
314 MediaWiki\Auth\AuthManager::callLegacyAuthPlugin(
315 'updateExternalDBGroups', [
$user, $add, $remove ]
318 wfDebug(
'oldGroups: ' . print_r( $oldGroups,
true ) .
"\n" );
319 wfDebug(
'newGroups: ' . print_r( $newGroups,
true ) .
"\n" );
321 Hooks::run(
'UserRights', [ &
$user, $add, $remove ],
'1.26' );
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' ) ) {
393 return Status::newFatal(
'userrights-no-interwiki' );
396 return Status::newFatal(
'userrights-nodatabase', $database );
401 if (
$name ===
'' ) {
402 return Status::newFatal(
'nouserspecified' );
405 if (
$name[0] ==
'#' ) {
408 $id = intval( substr(
$name, 1 ) );
410 if ( $database ==
'' ) {
411 $name = User::whoIs( $id );
417 return Status::newFatal(
'noname' );
421 if (
$name ===
false ) {
423 return Status::newFatal(
'nosuchusershort',
$username );
427 if ( $database ==
'' ) {
434 return Status::newFatal(
'nosuchusershort',
$username );
437 return Status::newGood(
$user );
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'
471 Html::hidden(
'title', $this->
getPageTitle()->getPrefixedText() ) .
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()
492 Html::closeElement(
'fieldset' ) .
493 Html::closeElement(
'form' ) .
"\n"
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 ) {
535 $autoMembersList = [];
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'
591 Html::hidden(
'user', $this->mTarget ) .
592 Html::hidden(
'wpEditToken', $this->
getUser()->getEditToken( $this->mTarget ) ) .
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() .
607 $this->groupCheckboxes( $groups,
$user ) .
610 <td class='mw-label'>" .
611 Xml::label( $this->msg(
'userrights-reason' )->text(),
'wpReason' ) .
613 <td class='mw-input'>" .
614 Xml::input(
'user-reason', 60, $this->getRequest()->getVal(
'user-reason',
false ),
615 [
'id' =>
'wpReason',
'maxlength' => 255 ] ) .
620 <td class='mw-submit'>" .
622 [
'name' =>
'saveusergroups' ] +
640 return User::makeGroupLinkHTML( $group, User::getGroupName( $group ) );
650 return User::makeGroupLinkHTML( $group, User::getGroupMember( $group ) );
658 return User::getAllGroups();
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' ] : [];
725 $member = User::getGroupMember( $group,
$user->getName() );
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' );
807 $user = User::newFromName( $search );
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
static tooltipAndAccesskeyAttribs( $name, array $msgParams=[])
Returns the attributes for the tooltip and access key.
static userToolLinks( $userId, $userText, $redContribsWhenNoEdits=false, $flags=0, $edits=null)
Generate standard user tool links (talk, contributions, block link, etc.)
static showLogExtract(&$out, $types=[], $page='', $user='', $param=[])
Show log extract.
Class to simplify the use of log pages.
Class for creating log entries manually, to inject them into the database.
Show an error when a user tries to do something they do not have the necessary permissions for.
Parent class for all special pages.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
getUser()
Shortcut to get the User executing this instance.
getSkin()
Shortcut to get the skin being used for this instance.
getConfig()
Shortcut to get main config object.
getRequest()
Get the WebRequest being used for this instance.
checkReadOnly()
If the wiki is currently in readonly mode, throws a ReadOnlyError.
getPageTitle( $subpage=false)
Get a self-referential title object.
getLanguage()
Shortcut to get user's language.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
msg()
Wrapper around wfMessage that sets the current context.
Show an error when the user tries to do something whilst blocked.
static search( $audience, $search, $limit, $offset=0)
Do a prefix search of user names and return a list of matching user names.
static validDatabase( $database)
Confirm the selected database name is a valid local interwiki database name.
static newFromName( $database, $name, $ignoreInvalidDB=false)
Factory function; get a remote user entry by name.
static whoIs( $database, $id, $ignoreInvalidDB=false)
Same as User::whoIs()
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Special page to allow managing user group membership.
isRestricted()
Can be overridden by subclasses with more complicated permissions schemes.
doSaveUserGroups( $user, $add, $remove, $reason='')
Save user groups changes in the database.
static getAllGroups()
Returns an array of all groups that may be edited.
userCanExecute(User $user)
Checks if the given user (identified by an object) can execute this special page (as defined by $mRes...
switchForm()
Output a form to allow searching for a user.
showEditUserGroupsForm( $user, $groups)
Show the form to edit group memberships.
$mTarget
The target of the local right-adjuster's interest.
prefixSearchSubpages( $search, $limit, $offset)
Return an array of subpages beginning with $search that this special page will accept.
addLogEntry( $user, $oldGroups, $newGroups, $reason)
Add a rights log entry for an action.
splitGroups( $groups)
Go through used and available groups and return the ones that this form will be able to manipulate ba...
editUserGroupsForm( $username)
Edit user groups membership.
static buildGroupLink( $group)
Format a link to a group description page.
groupCheckboxes( $usergroups, $user)
Adds a table with checkboxes where you can select what groups to add/remove.
userCanChangeRights( $user, $checkIfSelf=true)
showLogFragment( $user, $output)
Show a rights log fragment for the specified user.
fetchUser( $username)
Normalize the input username, which may be local or remote, and return a user (or proxy) object for m...
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
execute( $par)
Manage forms to be shown according to posted data.
saveUserGroups( $username, $reason, $user)
Save user groups changes in the database.
static buildGroupMemberLink( $group)
Format a link to a group member description page.
doesWrites()
Indicates whether this special page may perform database writes.
changeableGroups()
Returns $this->getUser()->changeableGroups()
static closeElement( $element)
Shortcut to close an XML element.
static label( $label, $id, $attribs=[])
Convenience function to build an HTML form label.
static openElement( $element, $attribs=null)
This opens an XML element.
static input( $name, $size=false, $value=false, $attribs=[])
Convenience function to build an HTML text input field.
static submitButton( $value, $attribs=[])
Convenience function to build an HTML submit button When $wgUseMediaWikiUIEverywhere is true it will ...
static checkLabel( $label, $name, $id, $checked=false, $attribs=[])
Convenience function to build an HTML checkbox with a label.
static inputLabel( $label, $name, $id, $size=false, $value=false, $attribs=[])
Convenience function to build an HTML text input field with a label.
static tags( $element, $attribs=null, $contents)
Same as Xml::element(), but does not escape contents.
static element( $element, $attribs=null, $contents='', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
static fieldset( $legend=false, $content=false, $attribs=[])
Shortcut for creating fieldsets.
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
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
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
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
the array() calling protocol came about after MediaWiki 1.4rc1.
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
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
error also a ContextSource you ll probably need to make sure the header is varied on $request
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
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
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
this hook is for auditing only or null if authentication failed before getting that far $username
Allows to change the fields on the form that will be generated $name
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