MediaWiki  master
PermissionsError.php
Go to the documentation of this file.
1 <?php
23 
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 }
if(!defined( 'MW_NO_SESSION') &&! $wgCommandLineMode) $wgOut
Definition: Setup.php:519
An error page which can definitely be safely rendered using the OutputPage.
Service locator for MediaWiki core services.
A StatusValue for permission errors.
static listParam(array $list, $type='text')
Definition: Message.php:1278
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition: Message.php:426
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=[])
static getMain()
Get the RequestContext object associated with the main request.
static getLink( $ugm, IContextSource $context, $format, $userName=null)
Gets a link for a user group, possibly including the expiry date if relevant.