MediaWiki REL1_39
PermissionsError.php
Go to the documentation of this file.
1<?php
23
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}
if(!defined( 'MW_NO_SESSION') &&! $wgCommandLineMode $wgOut
Definition Setup.php:497
if(!defined( 'MW_NO_SESSION') &&! $wgCommandLineMode $wgLang
Definition Setup.php:497
An error page which can definitely be safely rendered using the OutputPage.
Service locator for MediaWiki core services.
A StatusValue for permission errors.
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition Message.php:422
Show an error when a user tries to do something they do not have the necessary permissions for.
report( $action=self::SEND_OUTPUT)
__construct( $permission, $errors=[])