MediaWiki
REL1_39
PermissionsError.php
Go to the documentation of this file.
1
<?php
21
use
MediaWiki\MediaWikiServices
;
22
use
MediaWiki\Permissions\PermissionStatus
;
23
32
class
PermissionsError
extends
ErrorPageError
{
33
public
$permission
,
$errors
;
34
43
public
function
__construct
( $permission, $errors = [] ) {
44
global
$wgLang
;
45
46
if
( $errors instanceof
PermissionStatus
) {
47
$errors = $errors->toLegacyErrorArray();
48
}
49
50
if
(
$permission
===
null
&& !$errors ) {
51
throw
new \InvalidArgumentException( __METHOD__ .
52
': $permission and $errors cannot both be empty'
);
53
}
54
55
$this->permission =
$permission
;
56
57
if
( !count( $errors ) ) {
58
$groups = [];
59
foreach
( MediaWikiServices::getInstance()
60
->getGroupPermissionsLookup()
61
// @phan-suppress-next-line PhanTypeMismatchArgumentNullable Null on permission is check when used here
62
->getGroupsWithPermission( $this->permission ) as $group
63
) {
64
$groups[] = UserGroupMembership::getLink( $group, RequestContext::getMain(),
'wiki'
);
65
}
66
67
if
( $groups ) {
68
$errors[] = [
'badaccess-groups'
,
$wgLang
->commaList( $groups ), count( $groups ) ];
69
}
else
{
70
$errors[] = [
'badaccess-group0'
];
71
}
72
}
73
74
$this->errors = $errors;
75
76
// Give the parent class something to work with
77
parent::__construct(
'permissionserrors'
,
Message::newFromSpecifier
( $errors[0] ) );
78
}
79
80
public
function
report
( $action = self::SEND_OUTPUT ) {
81
global
$wgOut
;
82
83
$wgOut
->showPermissionsErrorPage( $this->errors, $this->permission );
84
if
( $action === self::SEND_OUTPUT ) {
85
$wgOut
->output();
86
}
87
}
88
}
$wgOut
if(!defined( 'MW_NO_SESSION') &&! $wgCommandLineMode $wgOut
Definition
Setup.php:497
$wgLang
if(!defined( 'MW_NO_SESSION') &&! $wgCommandLineMode $wgLang
Definition
Setup.php:497
ErrorPageError
An error page which can definitely be safely rendered using the OutputPage.
Definition
ErrorPageError.php:30
MediaWiki\MediaWikiServices
Service locator for MediaWiki core services.
Definition
MediaWikiServices.php:212
MediaWiki\Permissions\PermissionStatus
A StatusValue for permission errors.
Definition
PermissionStatus.php:35
Message\newFromSpecifier
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition
Message.php:422
PermissionsError
Show an error when a user tries to do something they do not have the necessary permissions for.
Definition
PermissionsError.php:32
PermissionsError\$permission
$permission
Definition
PermissionsError.php:33
PermissionsError\report
report( $action=self::SEND_OUTPUT)
Definition
PermissionsError.php:80
PermissionsError\$errors
$errors
Definition
PermissionsError.php:33
PermissionsError\__construct
__construct( $permission, $errors=[])
Definition
PermissionsError.php:43
includes
exception
PermissionsError.php
Generated on Mon Nov 11 2024 07:22:54 for MediaWiki by
1.10.0