3 * Implements Special:PasswordPolicies
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup SpecialPage
25 * This special page lists the defined password policies for user groups.
26 * See also @ref $wgPasswordPolicy.
28 * @ingroup SpecialPage
31 class SpecialPasswordPolicies
extends SpecialPage
{
32 public function __construct() {
33 parent
::__construct( 'PasswordPolicies' );
37 * Show the special page
38 * @param string|null $par
40 public function execute( $par ) {
42 $this->outputHeader();
44 $out = $this->getOutput();
45 $out->addModuleStyles( 'mediawiki.special' );
47 // TODO: Have specific user documentation page for this feature
48 $this->addHelpLink( 'Manual:$wgPasswordPolicy' );
51 Xml
::openElement( 'table', [ 'class' => 'wikitable mw-passwordpolicies-table' ] ) .
53 Xml
::element( 'th', null, $this->msg( 'passwordpolicies-group' )->text() ) .
54 Xml
::element( 'th', null, $this->msg( 'passwordpolicies-policies' )->text() ) .
58 $config = $this->getConfig();
59 $policies = $config->get( 'PasswordPolicy' );
61 $groupPermissions = $config->get( 'GroupPermissions' );
62 $revokePermissions = $config->get( 'RevokePermissions' );
63 $addGroups = $config->get( 'AddGroups' );
64 $removeGroups = $config->get( 'RemoveGroups' );
65 $groupsAddToSelf = $config->get( 'GroupsAddToSelf' );
66 $groupsRemoveFromSelf = $config->get( 'GroupsRemoveFromSelf' );
67 $allGroups = array_unique( array_merge(
68 array_keys( $groupPermissions ),
69 array_keys( $revokePermissions ),
70 array_keys( $addGroups ),
71 array_keys( $removeGroups ),
72 array_keys( $groupsAddToSelf ),
73 array_keys( $groupsRemoveFromSelf )
77 $linkRenderer = $this->getLinkRenderer();
79 foreach ( $allGroups as $group ) {
80 if ( $group == '*' ) {
84 $groupnameLocalized = UserGroupMembership
::getGroupName( $group );
86 $grouppageLocalizedTitle = UserGroupMembership
::getGroupPage( $group )
87 ?
: Title
::newFromText( MWNamespace
::getCanonicalName( NS_PROJECT
) . ':' . $group );
89 $grouppage = $linkRenderer->makeLink(
90 $grouppageLocalizedTitle,
94 if ( $group === 'user' ) {
95 // Link to Special:listusers for implicit group 'user'
96 $grouplink = '<br />' . $linkRenderer->makeKnownLink(
97 SpecialPage
::getTitleFor( 'Listusers' ),
98 $this->msg( 'listgrouprights-members' )->text()
100 } elseif ( !in_array( $group, $config->get( 'ImplicitGroups' ) ) ) {
101 $grouplink = '<br />' . $linkRenderer->makeKnownLink(
102 SpecialPage
::getTitleFor( 'Listusers' ),
103 $this->msg( 'listgrouprights-members' )->text(),
105 [ 'group' => $group ]
108 // No link to Special:listusers for other implicit groups as they are unlistable
112 $out->addHTML( Html
::rawElement( 'tr', [ 'id' => Sanitizer
::escapeIdForAttribute( $group ) ], "
113 <td>$grouppage$grouplink</td>
114 <td>" . $this->formatPolicies( $policies, $group ) . '</td>
120 $out->addHTML( Xml
::closeElement( 'table' ) );
124 * Create a HTML list of password policies for $group
126 * @param array $policies Original $wgPasswordPolicy array
127 * @param array $group Group to format password policies for
129 * @return string HTML list of all applied password policies
131 private function formatPolicies( $policies, $group ) {
132 $groupPolicies = UserPasswordPolicy
::getPoliciesForGroups(
133 $policies['policies'],
135 $policies['policies']['default']
139 foreach ( $groupPolicies as $gp => $val ) {
140 if ( $val === false ) {
141 // Policy isn't enabled, so no need to dislpay it
143 } elseif ( $val === true ) {
144 $msg = $this->msg( 'passwordpolicies-policy-' . strtolower( $gp ) );
146 $msg = $this->msg( 'passwordpolicies-policy-' . strtolower( $gp ) )->numParams( $val );
149 'passwordpolicies-policy-display',
151 '<span class="mw-passwordpolicies-policy-name">' . $gp . '</span>'
157 return '<ul><li>' . implode( "</li>\n<li>", $ret ) . '</li></ul>';
161 protected function getGroupName() {