MediaWiki
master
PermissionsError.php
Go to the documentation of this file.
1
<?php
21
use
MediaWiki\MediaWikiServices
;
22
use
MediaWiki\Permissions\PermissionStatus
;
23
use
MediaWiki\User\UserGroupMembership
;
24
33
class
PermissionsError
extends
ErrorPageError
{
34
public
$permission
,
$errors
;
35
44
public
function
__construct
(
$permission
,
$errors
= [] ) {
45
if
(
$errors
instanceof
PermissionStatus
) {
46
$errors
=
$errors
->toLegacyErrorArray();
47
}
48
49
if
(
$permission
===
null
&& !
$errors
) {
50
throw
new \InvalidArgumentException( __METHOD__ .
51
': $permission and $errors cannot both be empty'
);
52
}
53
54
$this->permission =
$permission
;
55
56
if
( !count(
$errors
) ) {
57
$groups = [];
58
foreach
( MediaWikiServices::getInstance()
59
->getGroupPermissionsLookup()
60
// @phan-suppress-next-line PhanTypeMismatchArgumentNullable Null on permission is check when used here
61
->getGroupsWithPermission( $this->permission ) as $group
62
) {
63
$groups[] = UserGroupMembership::getLinkWiki( $group,
RequestContext::getMain
() );
64
}
65
66
if
( $groups ) {
67
$errors
[] = [
'badaccess-groups'
,
Message::listParam
( $groups,
'comma'
), count( $groups ) ];
68
}
else
{
69
$errors
[] = [
'badaccess-group0'
];
70
}
71
}
72
73
$this->errors =
$errors
;
74
75
// Give the parent class something to work with
76
parent::__construct(
'permissionserrors'
,
Message::newFromSpecifier
(
$errors
[0] ) );
77
}
78
79
public
function
report
( $action = self::SEND_OUTPUT ) {
80
global
$wgOut
;
81
82
$wgOut
->showPermissionsErrorPage( $this->errors, $this->permission );
83
if
( $action === self::SEND_OUTPUT ) {
84
$wgOut
->output();
85
}
86
}
87
}
$wgOut
if(!defined( 'MW_NO_SESSION') &&! $wgCommandLineMode) $wgOut
Definition:
Setup.php:535
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:232
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:41
Message\listParam
static listParam(array $list, $type='text')
Definition:
Message.php:1279
Message\newFromSpecifier
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition:
Message.php:427
PermissionsError
Show an error when a user tries to do something they do not have the necessary permissions for.
Definition:
PermissionsError.php:33
PermissionsError\$permission
$permission
Definition:
PermissionsError.php:34
PermissionsError\report
report( $action=self::SEND_OUTPUT)
Definition:
PermissionsError.php:79
PermissionsError\$errors
$errors
Definition:
PermissionsError.php:34
PermissionsError\__construct
__construct( $permission, $errors=[])
Definition:
PermissionsError.php:44
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition:
RequestContext.php:593
includes
exception
PermissionsError.php
Generated on Sun Sep 24 2023 04:08:31 for MediaWiki by
1.9.1