MediaWiki REL1_32
PermissionsError.php
Go to the documentation of this file.
1<?php
30
37 public function __construct( $permission, $errors = [] ) {
38 global $wgLang;
39
40 if ( $permission === null && !$errors ) {
41 throw new \InvalidArgumentException( __METHOD__ .
42 ': $permission and $errors cannot both be empty' );
43 }
44
45 $this->permission = $permission;
46
47 if ( !count( $errors ) ) {
48 $groups = [];
49 foreach ( User::getGroupsWithPermission( $this->permission ) as $group ) {
50 $groups[] = UserGroupMembership::getLink( $group, RequestContext::getMain(), 'wiki' );
51 }
52
53 if ( $groups ) {
54 $errors[] = [ 'badaccess-groups', $wgLang->commaList( $groups ), count( $groups ) ];
55 } else {
56 $errors[] = [ 'badaccess-group0' ];
57 }
58 }
59
60 $this->errors = $errors;
61
62 // Give the parent class something to work with
63 parent::__construct( 'permissionserrors', Message::newFromSpecifier( $errors[0] ) );
64 }
65
66 public function report() {
67 global $wgOut;
68
69 $wgOut->showPermissionsErrorPage( $this->errors, $this->permission );
70 $wgOut->output();
71 }
72}
$wgOut
Definition Setup.php:915
$wgLang
Definition Setup.php:910
An error page which can definitely be safely rendered using the OutputPage.
Show an error when a user tries to do something they do not have the necessary permissions for.
report()
Output a report about the exception and takes care of formatting.
__construct( $permission, $errors=[])
static getGroupsWithPermission( $role)
Get all the groups who have a given permission.
Definition User.php:4990