11use MediaWiki\Languages\LanguageConverterFactory;
40 LanguageConverterFactory $languageConverterFactory,
43 parent::__construct(
'Listgrouprights' );
44 $this->nsInfo = $nsInfo;
45 $this->userGroupManager = $userGroupManager;
46 $this->languageConverter = $languageConverterFactory->getLanguageConverter( $this->
getContentLanguage() );
47 $this->groupPermissionsLookup = $groupPermissionsLookup;
59 $out->addModuleStyles(
'mediawiki.special' );
60 $this->
addHelpLink(
'Help:User_rights_and_groups' );
62 $out->wrapWikiMsg(
"<div class=\"mw-listgrouprights-key\">\n$1\n</div>",
'listgrouprights-key' );
65 Html::openElement(
'table', [
'class' => [
'wikitable',
'mw-listgrouprights-table' ] ] ) .
77 $allGroups = array_merge(
78 $this->userGroupManager->listAllGroups(),
79 $this->userGroupManager->listAllImplicitGroups()
86 foreach ( $allGroups as $group ) {
87 $permissions = $this->groupPermissionsLookup->getGrantedPermissions( $group );
88 $groupname = ( $group ==
'*' )
92 $groupnameLocalized = $lang->getGroupName( $groupname );
94 $grouppageLocalizedTitle = UserGroupMembership::getGroupPage( $groupname )
95 ?: Title::makeTitleSafe(
NS_PROJECT, $groupname );
97 if ( $group ==
'*' || !$grouppageLocalizedTitle ) {
99 $grouppage = htmlspecialchars( $groupnameLocalized );
101 $grouppage = $linkRenderer->makeLink(
102 $grouppageLocalizedTitle,
107 $groupWithParentheses = $this->
msg(
'parentheses' )->rawParams( $group )->escaped();
108 $groupname =
"<br /><code>$groupWithParentheses</code>";
110 if ( $group ===
'user' ) {
112 $grouplink =
'<br />' . $linkRenderer->makeKnownLink(
114 $this->
msg(
'listgrouprights-members' )->text()
117 $grouplink =
'<br />' . $linkRenderer->makeKnownLink(
119 $this->
msg(
'listgrouprights-members' )->text(),
121 [
'group' => $group ]
128 $revoke = $this->groupPermissionsLookup->getRevokedPermissions( $group );
129 $addgroups = $addGroups[$group] ?? [];
130 $removegroups = $removeGroups[$group] ?? [];
131 $addgroupsSelf = $groupsAddToSelf[$group] ?? [];
132 $removegroupsSelf = $groupsRemoveFromSelf[$group] ?? [];
134 $id = $group ==
'*' ? false : Sanitizer::escapeIdForAttribute( $group );
135 $out->addHTML( Html::rawElement(
'tr', [
'id' => $id ],
"
136 <td>$grouppage$groupname$grouplink</td>
138 $this->formatPermissions( $permissions, $revoke, $addgroups, $removegroups,
139 $addgroupsSelf, $removegroupsSelf ) .
144 $out->addHTML( Html::closeElement(
'table' ) );
145 $this->outputNamespaceProtectionInfo();
148 private function outputNamespaceProtectionInfo() {
152 if ( count( $namespaceProtection ) == 0 ) {
156 $header = $this->
msg(
'listgrouprights-namespaceprotection-header' )->text();
159 'id' => Sanitizer::escapeIdForAttribute( $header )
161 Html::openElement(
'table', [
'class' =>
'wikitable' ] ) .
165 $this->
msg(
'listgrouprights-namespaceprotection-namespace' )->text()
170 $this->
msg(
'listgrouprights-namespaceprotection-restrictedto' )->text()
174 ksort( $namespaceProtection );
175 $validNamespaces = $this->nsInfo->getValidNamespaces();
176 foreach ( $namespaceProtection as $namespace => $rights ) {
177 if ( !in_array( $namespace, $validNamespaces ) ) {
182 $namespaceText = $this->
msg(
'blanknamespace' )->text();
184 $namespaceText = $this->languageConverter->convertNamespace( $namespace );
188 Html::openElement(
'tr' ) .
192 $linkRenderer->makeLink(
196 [
'namespace' => $namespace ]
199 Html::openElement(
'td' ) . Html::openElement(
'ul' )
202 if ( !is_array( $rights ) ) {
203 $rights = [ $rights ];
206 foreach ( $rights as $right ) {
207 $out->addHTML( Html::rawElement(
'li', [],
208 $this->
msg(
'listgrouprights-right-display' )
209 ->params( User::getRightDescription( $right ) )
212 [
'class' =>
'mw-listgrouprights-right-name' ],
219 Html::closeElement(
'ul' ) .
220 Html::closeElement(
'td' ) .
221 Html::closeElement(
'tr' )
224 $out->addHTML( Html::closeElement(
'table' ) );
238 private function formatPermissions( $permissions, $revoke, $add, $remove, $addSelf, $removeSelf ) {
240 foreach ( $permissions as $permission ) {
242 if ( !isset( $revoke[$permission] ) || !$revoke[$permission] ) {
243 $r[] = $this->
msg(
'listgrouprights-right-display' )
244 ->params( User::getRightDescription( $permission ) )
247 [
'class' =>
'mw-listgrouprights-right-name' ],
252 foreach ( $revoke as $permission ) {
253 $r[] = $this->
msg(
'listgrouprights-right-revoked' )
254 ->params( User::getRightDescription( $permission ) )
257 [
'class' =>
'mw-listgrouprights-right-name' ],
265 $allGroups = $this->userGroupManager->listAllGroups();
269 'removegroup' => $remove,
270 'addgroup-self' => $addSelf,
271 'removegroup-self' => $removeSelf
274 foreach ( $changeGroups as $messageKey => $changeGroup ) {
276 if ( $changeGroup ===
true ) {
279 $r[] = $this->
msg(
'listgrouprights-' . $messageKey .
'-all' )->escaped();
280 } elseif ( is_array( $changeGroup ) ) {
281 $changeGroup = array_intersect( array_values( array_unique( $changeGroup ) ), $allGroups );
282 if ( count( $changeGroup ) ) {
284 foreach ( $changeGroup as $group ) {
285 $groupLinks[] = UserGroupMembership::getLinkWiki( $group, $this->
getContext() );
289 $r[] = $this->
msg(
'listgrouprights-' . $messageKey,
290 $lang->listToText( $groupLinks ), count( $changeGroup ) )->parse();
298 return '<ul><li>' . implode(
"</li>\n<li>", $r ) .
'</li></ul>';
309class_alias( SpecialListGroupRights::class,
'SpecialListGroupRights' );
A class containing constants representing the names of configuration variables.
const ImplicitGroups
Name constant for the ImplicitGroups setting, for use with Config::get()
const NamespaceProtection
Name constant for the NamespaceProtection setting, for use with Config::get()
const GroupsRemoveFromSelf
Name constant for the GroupsRemoveFromSelf setting, for use with Config::get()
const AddGroups
Name constant for the AddGroups setting, for use with Config::get()
const GroupsAddToSelf
Name constant for the GroupsAddToSelf setting, for use with Config::get()
const RemoveGroups
Name constant for the RemoveGroups setting, for use with Config::get()
Parent class for all special pages.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
getConfig()
Shortcut to get main config object.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
getContentLanguage()
Shortcut to get content language.
getLanguage()
Shortcut to get user's language.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages By default the message key is the canonical name of...
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.