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 $this->addHelpLink( 'Help:Password policies' );
50 Xml
::openElement( 'table', [ 'class' => 'wikitable mw-passwordpolicies-table' ] ) .
52 Xml
::element( 'th', null, $this->msg( 'passwordpolicies-group' )->text() ) .
53 Xml
::element( 'th', null, $this->msg( 'passwordpolicies-policies' )->text() ) .
57 $config = $this->getConfig();
58 $policies = $config->get( 'PasswordPolicy' );
60 $groupPermissions = $config->get( 'GroupPermissions' );
61 $revokePermissions = $config->get( 'RevokePermissions' );
62 $addGroups = $config->get( 'AddGroups' );
63 $removeGroups = $config->get( 'RemoveGroups' );
64 $groupsAddToSelf = $config->get( 'GroupsAddToSelf' );
65 $groupsRemoveFromSelf = $config->get( 'GroupsRemoveFromSelf' );
66 $allGroups = array_unique( array_merge(
67 array_keys( $groupPermissions ),
68 array_keys( $revokePermissions ),
69 array_keys( $addGroups ),
70 array_keys( $removeGroups ),
71 array_keys( $groupsAddToSelf ),
72 array_keys( $groupsRemoveFromSelf )
76 $linkRenderer = $this->getLinkRenderer();
78 foreach ( $allGroups as $group ) {
79 if ( $group == '*' ) {
83 $groupnameLocalized = UserGroupMembership
::getGroupName( $group );
85 $grouppageLocalizedTitle = UserGroupMembership
::getGroupPage( $group )
86 ?
: Title
::newFromText( MWNamespace
::getCanonicalName( NS_PROJECT
) . ':' . $group );
88 $grouppage = $linkRenderer->makeLink(
89 $grouppageLocalizedTitle,
93 if ( $group === 'user' ) {
94 // Link to Special:listusers for implicit group 'user'
95 $grouplink = '<br />' . $linkRenderer->makeKnownLink(
96 SpecialPage
::getTitleFor( 'Listusers' ),
97 $this->msg( 'listgrouprights-members' )->text()
99 } elseif ( !in_array( $group, $config->get( 'ImplicitGroups' ) ) ) {
100 $grouplink = '<br />' . $linkRenderer->makeKnownLink(
101 SpecialPage
::getTitleFor( 'Listusers' ),
102 $this->msg( 'listgrouprights-members' )->text(),
104 [ 'group' => $group ]
107 // No link to Special:listusers for other implicit groups as they are unlistable
111 $out->addHTML( Html
::rawElement( 'tr', [ 'id' => Sanitizer
::escapeIdForAttribute( $group ) ], "
112 <td>$grouppage$grouplink</td>
113 <td>" . $this->formatPolicies( $policies, $group ) . '</td>
119 $out->addHTML( Xml
::closeElement( 'table' ) );
123 * Create a HTML list of password policies for $group
125 * @param array $policies Original $wgPasswordPolicy array
126 * @param array $group Group to format password policies for
128 * @return string HTML list of all applied password policies
130 private function formatPolicies( $policies, $group ) {
131 $groupPolicies = UserPasswordPolicy
::getPoliciesForGroups(
132 $policies['policies'],
134 $policies['policies']['default']
138 foreach ( $groupPolicies as $gp => $val ) {
139 if ( $val === false ) {
140 // Policy isn't enabled, so no need to dislpay it
142 } elseif ( $val === true ) {
143 $msg = $this->msg( 'passwordpolicies-policy-' . strtolower( $gp ) );
145 $msg = $this->msg( 'passwordpolicies-policy-' . strtolower( $gp ) )->numParams( $val );
148 'passwordpolicies-policy-display',
150 '<span class="mw-passwordpolicies-policy-name">' . $gp . '</span>'
153 if ( !count( $ret ) ) {
156 return '<ul><li>' . implode( "</li>\n<li>", $ret ) . '</li></ul>';
160 protected function getGroupName() {