MediaWiki  master
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  ->getGroupsWithPermission( $this->permission ) as $group
62  ) {
63  $groups[] = UserGroupMembership::getLink( $group, RequestContext::getMain(), 'wiki' );
64  }
65 
66  if ( $groups ) {
67  $errors[] = [ 'badaccess-groups', $wgLang->commaList( $groups ), 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 }
Message\newFromSpecifier
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition: Message.php:399
PermissionsError\__construct
__construct( $permission, $errors=[])
Definition: PermissionsError.php:43
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:202
PermissionsError
Show an error when a user tries to do something they do not have the necessary permissions for.
Definition: PermissionsError.php:32
$wgLang
$wgLang
Definition: Setup.php:851
UserGroupMembership\getLink
static getLink( $ugm, IContextSource $context, $format, $userName=null)
Gets a link for a user group, possibly including the expiry date if relevant.
Definition: UserGroupMembership.php:104
PermissionsError\$permission
$permission
Definition: PermissionsError.php:33
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:484
MediaWiki\Permissions\PermissionStatus
A StatusValue for permission errors.
Definition: PermissionStatus.php:35
PermissionsError\$errors
$errors
Definition: PermissionsError.php:33
PermissionsError\report
report( $action=self::SEND_OUTPUT)
Definition: PermissionsError.php:79
$wgOut
$wgOut
Definition: Setup.php:856
ErrorPageError
An error page which can definitely be safely rendered using the OutputPage.
Definition: ErrorPageError.php:30