MediaWiki
REL1_40
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
if
( $errors instanceof
PermissionStatus
) {
45
$errors = $errors->toLegacyErrorArray();
46
}
47
48
if
(
$permission
===
null
&& !$errors ) {
49
throw
new \InvalidArgumentException( __METHOD__ .
50
': $permission and $errors cannot both be empty'
);
51
}
52
53
$this->permission =
$permission
;
54
55
if
( !count( $errors ) ) {
56
$groups = [];
57
foreach
( MediaWikiServices::getInstance()
58
->getGroupPermissionsLookup()
59
// @phan-suppress-next-line PhanTypeMismatchArgumentNullable Null on permission is check when used here
60
->getGroupsWithPermission( $this->permission ) as $group
61
) {
62
$groups[] = UserGroupMembership::getLink( $group, RequestContext::getMain(),
'wiki'
);
63
}
64
65
if
( $groups ) {
66
$errors[] = [
'badaccess-groups'
,
Message::listParam
( $groups,
'comma'
), count( $groups ) ];
67
}
else
{
68
$errors[] = [
'badaccess-group0'
];
69
}
70
}
71
72
$this->errors = $errors;
73
74
// Give the parent class something to work with
75
parent::__construct(
'permissionserrors'
,
Message::newFromSpecifier
( $errors[0] ) );
76
}
77
78
public
function
report
( $action = self::SEND_OUTPUT ) {
79
global
$wgOut
;
80
81
$wgOut
->showPermissionsErrorPage( $this->errors, $this->permission );
82
if
( $action === self::SEND_OUTPUT ) {
83
$wgOut
->output();
84
}
85
}
86
}
$wgOut
if(!defined( 'MW_NO_SESSION') &&! $wgCommandLineMode $wgOut
Definition
Setup.php:527
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:223
MediaWiki\Permissions\PermissionStatus
A StatusValue for permission errors.
Definition
PermissionStatus.php:35
Message\listParam
static listParam(array $list, $type='text')
Definition
Message.php:1278
Message\newFromSpecifier
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition
Message.php:426
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:78
PermissionsError\$errors
$errors
Definition
PermissionsError.php:33
PermissionsError\__construct
__construct( $permission, $errors=[])
Definition
PermissionsError.php:43
includes
exception
PermissionsError.php
Generated on Thu Jun 27 2024 14:02:42 for MediaWiki by
1.10.0