MediaWiki REL1_32
SpecialPasswordPolicies.php
Go to the documentation of this file.
1<?php
32 public function __construct() {
33 parent::__construct( 'PasswordPolicies' );
34 }
35
40 public function execute( $par ) {
41 $this->setHeaders();
42 $this->outputHeader();
43
44 $out = $this->getOutput();
45 $out->addModuleStyles( 'mediawiki.special' );
46
47 // TODO: Have specific user documentation page for this feature
48 $this->addHelpLink( 'Manual:$wgPasswordPolicy' );
49
50 $out->addHTML(
51 Xml::openElement( 'table', [ 'class' => 'wikitable mw-passwordpolicies-table' ] ) .
52 '<tr>' .
53 Xml::element( 'th', null, $this->msg( 'passwordpolicies-group' )->text() ) .
54 Xml::element( 'th', null, $this->msg( 'passwordpolicies-policies' )->text() ) .
55 '</tr>'
56 );
57
58 $config = $this->getConfig();
59 $policies = $config->get( 'PasswordPolicy' );
60
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 )
74 ) );
75 asort( $allGroups );
76
78
79 foreach ( $allGroups as $group ) {
80 if ( $group == '*' ) {
81 continue;
82 }
83
84 $groupnameLocalized = UserGroupMembership::getGroupName( $group );
85
86 $grouppageLocalizedTitle = UserGroupMembership::getGroupPage( $group )
87 ?: Title::newFromText( MWNamespace::getCanonicalName( NS_PROJECT ) . ':' . $group );
88
89 $grouppage = $linkRenderer->makeLink(
90 $grouppageLocalizedTitle,
91 $groupnameLocalized
92 );
93
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()
99 );
100 } elseif ( !in_array( $group, $config->get( 'ImplicitGroups' ) ) ) {
101 $grouplink = '<br />' . $linkRenderer->makeKnownLink(
102 SpecialPage::getTitleFor( 'Listusers' ),
103 $this->msg( 'listgrouprights-members' )->text(),
104 [],
105 [ 'group' => $group ]
106 );
107 } else {
108 // No link to Special:listusers for other implicit groups as they are unlistable
109 $grouplink = '';
110 }
111
112 $out->addHTML( Html::rawElement( 'tr', [ 'id' => Sanitizer::escapeIdForAttribute( $group ) ], "
113 <td>$grouppage$grouplink</td>
114 <td>" . $this->formatPolicies( $policies, $group ) . '</td>
115 '
116 ) );
117
118 }
119
120 $out->addHTML( Xml::closeElement( 'table' ) );
121 }
122
131 private function formatPolicies( $policies, $group ) {
133 $policies['policies'],
134 [ $group ],
135 $policies['policies']['default']
136 );
137
138 $ret = [];
139 foreach ( $groupPolicies as $gp => $val ) {
140 if ( $val === false ) {
141 // Policy isn't enabled, so no need to dislpay it
142 continue;
143 } elseif ( $val === true ) {
144 $msg = $this->msg( 'passwordpolicies-policy-' . strtolower( $gp ) );
145 } else {
146 $msg = $this->msg( 'passwordpolicies-policy-' . strtolower( $gp ) )->numParams( $val );
147 }
148 $ret[] = $this->msg(
149 'passwordpolicies-policy-display',
150 $msg,
151 '<span class="mw-passwordpolicies-policy-name">' . $gp . '</span>'
152 )->parse();
153 }
154 if ( !count( $ret ) ) {
155 return '';
156 } else {
157 return '<ul><li>' . implode( "</li>\n<li>", $ret ) . '</li></ul>';
158 }
159 }
160
161 protected function getGroupName() {
162 return 'users';
163 }
164}
This list may contain false positives That usually means there is additional text with links below the first Each row contains links to the first and second as well as the first line of the second redirect text
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)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
MediaWiki Linker LinkRenderer null $linkRenderer
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.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition hooks.txt:2054
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition hooks.txt:894
const NS_PROJECT
Definition Defines.php:68