MediaWiki REL1_39
SpecialPasswordPolicies.php
Go to the documentation of this file.
1<?php
26
35
37 private $userGroupManager;
38
42 public function __construct( UserGroupManager $userGroupManager ) {
43 parent::__construct( 'PasswordPolicies' );
44 $this->userGroupManager = $userGroupManager;
45 }
46
51 public function execute( $par ) {
52 $this->setHeaders();
53 $this->outputHeader();
54
55 $out = $this->getOutput();
56 $out->addModuleStyles( 'mediawiki.special' );
57
58 // TODO: Have specific user documentation page for this feature
59 $this->addHelpLink( 'Manual:$wgPasswordPolicy' );
60
61 $out->addHTML(
62 Xml::openElement( 'table', [ 'class' => 'wikitable mw-passwordpolicies-table' ] ) .
63 '<tr>' .
64 Xml::element( 'th', null, $this->msg( 'passwordpolicies-group' )->text() ) .
65 Xml::element( 'th', null, $this->msg( 'passwordpolicies-policies' )->text() ) .
66 '</tr>'
67 );
68
69 $config = $this->getConfig();
70 $policies = $config->get( MainConfigNames::PasswordPolicy );
71
72 $implicitGroups = $this->userGroupManager->listAllImplicitGroups();
73 $allGroups = array_merge(
74 $this->userGroupManager->listAllGroups(),
75 $implicitGroups
76 );
77 asort( $allGroups );
78
79 $linkRenderer = $this->getLinkRenderer();
80 $lang = $this->getLanguage();
81
82 foreach ( $allGroups as $group ) {
83 if ( $group == '*' ) {
84 continue;
85 }
86
87 $groupnameLocalized = $lang->getGroupName( $group );
88
89 $grouppageLocalizedTitle = UserGroupMembership::getGroupPage( $group )
90 ?: Title::makeTitle( NS_PROJECT, $group );
91
92 $grouppage = $linkRenderer->makeLink(
93 $grouppageLocalizedTitle,
94 $groupnameLocalized
95 );
96
97 if ( $group === 'user' ) {
98 // Link to Special:listusers for implicit group 'user'
99 $grouplink = '<br />' . $linkRenderer->makeKnownLink(
100 SpecialPage::getTitleFor( 'Listusers' ),
101 $this->msg( 'listgrouprights-members' )->text()
102 );
103 } elseif ( !in_array( $group, $implicitGroups ) ) {
104 $grouplink = '<br />' . $linkRenderer->makeKnownLink(
105 SpecialPage::getTitleFor( 'Listusers' ),
106 $this->msg( 'listgrouprights-members' )->text(),
107 [],
108 [ 'group' => $group ]
109 );
110 } else {
111 // No link to Special:listusers for other implicit groups as they are unlistable
112 $grouplink = '';
113 }
114
115 $out->addHTML( Html::rawElement( 'tr', [ 'id' => Sanitizer::escapeIdForAttribute( $group ) ], "
116 <td>$grouppage$grouplink</td>
117 <td>" . $this->formatPolicies( $policies, $group ) . '</td>
118 '
119 ) );
120
121 }
122
123 $out->addHTML( Xml::closeElement( 'table' ) );
124 }
125
134 private function formatPolicies( $policies, $group ) {
136 $policies['policies'],
137 [ $group ],
138 $policies['policies']['default']
139 );
140
141 $ret = [];
142 foreach ( $groupPolicies as $gp => $settings ) {
143 if ( !is_array( $settings ) ) {
144 $settings = [ 'value' => $settings ];
145 }
146 $val = $settings['value'];
147 $flags = array_diff_key( $settings, [ 'value' => true ] );
148 if ( !$val ) {
149 // Policy isn't enabled, so no need to display it
150 continue;
151 }
152 $msg = $this->msg( 'passwordpolicies-policy-' . strtolower( $gp ) )->numParams( $val );
153 $flagMsgs = [];
154 foreach ( array_filter( $flags ) as $flag => $value ) {
155 $flagMsg = $this->msg( 'passwordpolicies-policyflag-' . strtolower( $flag ) );
156 $flagMsg->params( $value );
157 $flagMsgs[] = $flagMsg;
158 }
159 if ( $flagMsgs ) {
160 $ret[] = $this->msg(
161 'passwordpolicies-policy-displaywithflags',
162 $msg,
163 '<span class="mw-passwordpolicies-policy-name">' . $gp . '</span>',
164 $this->getLanguage()->commaList( $flagMsgs )
165 )->parse();
166 } else {
167 $ret[] = $this->msg(
168 'passwordpolicies-policy-display',
169 $msg,
170 '<span class="mw-passwordpolicies-policy-name">' . $gp . '</span>'
171 )->parse();
172 }
173 }
174 if ( $ret === [] ) {
175 return '';
176 } else {
177 return '<ul><li>' . implode( "</li>\n<li>", $ret ) . '</li></ul>';
178 }
179 }
180
181 protected function getGroupName() {
182 return 'users';
183 }
184}
const NS_PROJECT
Definition Defines.php:68
A class containing constants representing the names of configuration variables.
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,...
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.
__construct(UserGroupManager $userGroupManager)
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.
if(!isset( $args[0])) $lang