MediaWiki master
PermissionsError.php
Go to the documentation of this file.
1<?php
25
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}
if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgOut
Definition Setup.php:536
An error page which can definitely be safely rendered using the OutputPage.
Group all the pieces relevant to the context of a request into one instance.
Service locator for MediaWiki core services.
A StatusValue for permission errors.
Represents a "user group membership" – a specific instance of a user belonging to a group.
Show an error when a user tries to do something they do not have the necessary permissions for.
report( $action=self::SEND_OUTPUT)
__construct(?string $permission, $errors=[])