MediaWiki
master
PermissionsError.php
Go to the documentation of this file.
1
<?php
21
use
MediaWiki\Context\RequestContext
;
22
use
MediaWiki\MediaWikiServices
;
23
use
MediaWiki\Permissions\PermissionStatus
;
24
use
MediaWiki\User\UserGroupMembership
;
25
34
class
PermissionsError
extends
ErrorPageError
{
35
public
?
string
$permission
;
36
public
array
$errors
;
37
46
public
function
__construct
( ?
string
$permission, $errors = [] ) {
47
if
( $errors instanceof
PermissionStatus
) {
48
$errors = $errors->toLegacyErrorArray();
49
}
50
51
if
( $permission ===
null
&& !$errors ) {
52
throw
new \InvalidArgumentException( __METHOD__ .
53
': $permission and $errors cannot both be empty'
);
54
}
55
56
$this->permission = $permission;
57
58
if
( !count( $errors ) ) {
59
$groups = [];
60
foreach
( MediaWikiServices::getInstance()
61
->getGroupPermissionsLookup()
62
// @phan-suppress-next-line PhanTypeMismatchArgumentNullable Null on permission is check when used here
63
->getGroupsWithPermission( $this->permission ) as $group
64
) {
65
$groups[] = UserGroupMembership::getLinkWiki( $group, RequestContext::getMain() );
66
}
67
68
if
( $groups ) {
69
$errors[] = [
'badaccess-groups'
, Message::listParam( $groups,
'comma'
), count( $groups ) ];
70
}
else
{
71
$errors[] = [
'badaccess-group0'
];
72
}
73
}
74
75
$this->errors = $errors;
76
77
// Give the parent class something to work with
78
parent::__construct(
'permissionserrors'
, Message::newFromSpecifier( $errors[0] ) );
79
}
80
81
public
function
report
( $action = self::SEND_OUTPUT ) {
82
global
$wgOut
;
83
84
$wgOut
->showPermissionsErrorPage( $this->errors, $this->permission );
85
if
( $action === self::SEND_OUTPUT ) {
86
$wgOut
->output();
87
}
88
}
89
}
$wgOut
if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgOut
Definition
Setup.php:536
ErrorPageError
An error page which can definitely be safely rendered using the OutputPage.
Definition
ErrorPageError.php:30
MediaWiki\Context\RequestContext
Group all the pieces relevant to the context of a request into one instance.
Definition
RequestContext.php:66
MediaWiki\MediaWikiServices
Service locator for MediaWiki core services.
Definition
MediaWikiServices.php:240
MediaWiki\Permissions\PermissionStatus
A StatusValue for permission errors.
Definition
PermissionStatus.php:39
MediaWiki\User\UserGroupMembership
Represents a "user group membership" – a specific instance of a user belonging to a group.
Definition
UserGroupMembership.php:40
PermissionsError
Show an error when a user tries to do something they do not have the necessary permissions for.
Definition
PermissionsError.php:34
PermissionsError\$permission
string $permission
Definition
PermissionsError.php:35
PermissionsError\$errors
array $errors
Definition
PermissionsError.php:36
PermissionsError\report
report( $action=self::SEND_OUTPUT)
Definition
PermissionsError.php:81
PermissionsError\__construct
__construct(?string $permission, $errors=[])
Definition
PermissionsError.php:46
includes
exception
PermissionsError.php
Generated on Wed Apr 24 2024 07:22:59 for MediaWiki by
1.10.0