MediaWiki REL1_37
SpecialPasswordPolicies.php
Go to the documentation of this file.
1<?php
32
33 public function __construct() {
34 parent::__construct( 'PasswordPolicies' );
35 }
36
41 public function execute( $par ) {
42 $this->setHeaders();
43 $this->outputHeader();
44
45 $out = $this->getOutput();
46 $out->addModuleStyles( 'mediawiki.special' );
47
48 // TODO: Have specific user documentation page for this feature
49 $this->addHelpLink( 'Manual:$wgPasswordPolicy' );
50
51 $out->addHTML(
52 Xml::openElement( 'table', [ 'class' => 'wikitable mw-passwordpolicies-table' ] ) .
53 '<tr>' .
54 Xml::element( 'th', null, $this->msg( 'passwordpolicies-group' )->text() ) .
55 Xml::element( 'th', null, $this->msg( 'passwordpolicies-policies' )->text() ) .
56 '</tr>'
57 );
58
59 $config = $this->getConfig();
60 $policies = $config->get( 'PasswordPolicy' );
61
62 $groupPermissions = $config->get( 'GroupPermissions' );
63 $revokePermissions = $config->get( 'RevokePermissions' );
64 $addGroups = $config->get( 'AddGroups' );
65 $removeGroups = $config->get( 'RemoveGroups' );
66 $groupsAddToSelf = $config->get( 'GroupsAddToSelf' );
67 $groupsRemoveFromSelf = $config->get( 'GroupsRemoveFromSelf' );
68 $allGroups = array_unique( array_merge(
69 array_keys( $groupPermissions ),
70 array_keys( $revokePermissions ),
71 array_keys( $addGroups ),
72 array_keys( $removeGroups ),
73 array_keys( $groupsAddToSelf ),
74 array_keys( $groupsRemoveFromSelf )
75 ) );
76 asort( $allGroups );
77
79
80 foreach ( $allGroups as $group ) {
81 if ( $group == '*' ) {
82 continue;
83 }
84
85 $groupnameLocalized = UserGroupMembership::getGroupName( $group );
86
87 $grouppageLocalizedTitle = UserGroupMembership::getGroupPage( $group )
88 ?: Title::makeTitle( NS_PROJECT, $group );
89
90 $grouppage = $linkRenderer->makeLink(
91 $grouppageLocalizedTitle,
92 $groupnameLocalized
93 );
94
95 if ( $group === 'user' ) {
96 // Link to Special:listusers for implicit group 'user'
97 $grouplink = '<br />' . $linkRenderer->makeKnownLink(
98 SpecialPage::getTitleFor( 'Listusers' ),
99 $this->msg( 'listgrouprights-members' )->text()
100 );
101 } elseif ( !in_array( $group, $config->get( 'ImplicitGroups' ) ) ) {
102 $grouplink = '<br />' . $linkRenderer->makeKnownLink(
103 SpecialPage::getTitleFor( 'Listusers' ),
104 $this->msg( 'listgrouprights-members' )->text(),
105 [],
106 [ 'group' => $group ]
107 );
108 } else {
109 // No link to Special:listusers for other implicit groups as they are unlistable
110 $grouplink = '';
111 }
112
113 $out->addHTML( Html::rawElement( 'tr', [ 'id' => Sanitizer::escapeIdForAttribute( $group ) ], "
114 <td>$grouppage$grouplink</td>
115 <td>" . $this->formatPolicies( $policies, $group ) . '</td>
116 '
117 ) );
118
119 }
120
121 $out->addHTML( Xml::closeElement( 'table' ) );
122 }
123
132 private function formatPolicies( $policies, $group ) {
134 $policies['policies'],
135 [ $group ],
136 $policies['policies']['default']
137 );
138
139 $ret = [];
140 foreach ( $groupPolicies as $gp => $settings ) {
141 if ( !is_array( $settings ) ) {
142 $settings = [ 'value' => $settings ];
143 }
144 $val = $settings['value'];
145 $flags = array_diff_key( $settings, [ 'value' => true ] );
146 if ( !$val ) {
147 // Policy isn't enabled, so no need to display it
148 continue;
149 }
150 $msg = $this->msg( 'passwordpolicies-policy-' . strtolower( $gp ) )->numParams( $val );
151 $flagMsgs = [];
152 foreach ( array_filter( $flags ) as $flag => $value ) {
153 $flagMsg = $this->msg( 'passwordpolicies-policyflag-' . strtolower( $flag ) );
154 $flagMsg->params( $value );
155 $flagMsgs[] = $flagMsg;
156 }
157 if ( $flagMsgs ) {
158 $ret[] = $this->msg(
159 'passwordpolicies-policy-displaywithflags',
160 $msg,
161 '<span class="mw-passwordpolicies-policy-name">' . $gp . '</span>',
162 $this->getLanguage()->commaList( $flagMsgs )
163 )->parse();
164 } else {
165 $ret[] = $this->msg(
166 'passwordpolicies-policy-display',
167 $msg,
168 '<span class="mw-passwordpolicies-policy-name">' . $gp . '</span>'
169 )->parse();
170 }
171 }
172 if ( $ret === [] ) {
173 return '';
174 } else {
175 return '<ul><li>' . implode( "</li>\n<li>", $ret ) . '</li></ul>';
176 }
177 }
178
179 protected function getGroupName() {
180 return 'users';
181 }
182}
const NS_PROJECT
Definition Defines.php:68
makeKnownLink( $target, $text=null, array $extraAttribs=[], array $query=[])
makeLink( $target, $text=null, array $extraAttribs=[], array $query=[])
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.
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,...
LinkRenderer null $linkRenderer
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
getLanguage()
Shortcut to get user's language.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
This special page lists the defined password policies for user groups.
formatPolicies( $policies, $group)
Create a HTML list of password policies for $group.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
execute( $par)
Show the special page.
static getPoliciesForGroups(array $policies, array $userGroups, array $defaultPolicy)
Utility function to get the effective policy from a list of policies, based on a list of groups.