MediaWiki  master
SpecialPasswordPolicies.php
Go to the documentation of this file.
1 <?php
25 
34  public function __construct() {
35  parent::__construct( 'PasswordPolicies' );
36  }
37 
42  public function execute( $par ) {
43  $this->setHeaders();
44  $this->outputHeader();
45 
46  $out = $this->getOutput();
47  $out->addModuleStyles( 'mediawiki.special' );
48 
49  // TODO: Have specific user documentation page for this feature
50  $this->addHelpLink( 'Manual:$wgPasswordPolicy' );
51 
52  $out->addHTML(
53  Xml::openElement( 'table', [ 'class' => 'wikitable mw-passwordpolicies-table' ] ) .
54  '<tr>' .
55  Xml::element( 'th', null, $this->msg( 'passwordpolicies-group' )->text() ) .
56  Xml::element( 'th', null, $this->msg( 'passwordpolicies-policies' )->text() ) .
57  '</tr>'
58  );
59 
60  $config = $this->getConfig();
61  $policies = $config->get( 'PasswordPolicy' );
62 
63  $groupPermissions = $config->get( 'GroupPermissions' );
64  $revokePermissions = $config->get( 'RevokePermissions' );
65  $addGroups = $config->get( 'AddGroups' );
66  $removeGroups = $config->get( 'RemoveGroups' );
67  $groupsAddToSelf = $config->get( 'GroupsAddToSelf' );
68  $groupsRemoveFromSelf = $config->get( 'GroupsRemoveFromSelf' );
69  $allGroups = array_unique( array_merge(
70  array_keys( $groupPermissions ),
71  array_keys( $revokePermissions ),
72  array_keys( $addGroups ),
73  array_keys( $removeGroups ),
74  array_keys( $groupsAddToSelf ),
75  array_keys( $groupsRemoveFromSelf )
76  ) );
77  asort( $allGroups );
78 
79  $linkRenderer = $this->getLinkRenderer();
80 
81  foreach ( $allGroups as $group ) {
82  if ( $group == '*' ) {
83  continue;
84  }
85 
86  $groupnameLocalized = UserGroupMembership::getGroupName( $group );
87 
88  $grouppageLocalizedTitle = UserGroupMembership::getGroupPage( $group )
89  ?: Title::newFromText( MediaWikiServices::getInstance()->getNamespaceInfo()->
90  getCanonicalName( 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, $config->get( '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 }
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:1982
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:210
$value
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
formatPolicies( $policies, $group)
Create a HTML list of password policies for $group.
execute( $par)
Show the special page.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
getOutput()
Get the OutputPage being used for this instance.
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
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password 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:780
const NS_PROJECT
Definition: Defines.php:64
static openElement( $element, $attribs=null)
This opens an XML element.
Definition: Xml.php:108
static escapeIdForAttribute( $id, $mode=self::ID_PRIMARY)
Given a section name or other user-generated or otherwise unsafe string, escapes it to be a valid HTM...
Definition: Sanitizer.php:1288
static getGroupName( $group)
Gets the localized friendly name for a group, if it exists.
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...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes! ...
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don&#39;t need a full Title object...
Definition: SpecialPage.php:83
static getGroupPage( $group)
Gets the title of a page describing a particular user group.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
static closeElement( $element)
Shortcut to close an XML element.
Definition: Xml.php:117
getConfig()
Shortcut to get main config object.
static element( $element, $attribs=null, $contents='', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
Definition: Xml.php:41
getLanguage()
Shortcut to get user&#39;s language.
msg( $key)
Wrapper around wfMessage that sets the current context.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
This special page lists the defined password policies for user groups.
MediaWiki Linker LinkRenderer null $linkRenderer
Definition: SpecialPage.php:67
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:319