MediaWiki  master
PermissionsError.php
Go to the documentation of this file.
1 <?php
22 
32 
39  public function __construct( $permission, $errors = [] ) {
40  global $wgLang;
41 
42  if ( $permission === null && !$errors ) {
43  throw new \InvalidArgumentException( __METHOD__ .
44  ': $permission and $errors cannot both be empty' );
45  }
46 
47  $this->permission = $permission;
48 
49  if ( !count( $errors ) ) {
50  $groups = [];
51  foreach ( MediaWikiServices::getInstance()
53  ->getGroupsWithPermission( $this->permission ) as $group ) {
54  $groups[] = UserGroupMembership::getLink( $group, RequestContext::getMain(), 'wiki' );
55  }
56 
57  if ( $groups ) {
58  $errors[] = [ 'badaccess-groups', $wgLang->commaList( $groups ), count( $groups ) ];
59  } else {
60  $errors[] = [ 'badaccess-group0' ];
61  }
62  }
63 
64  $this->errors = $errors;
65 
66  // Give the parent class something to work with
67  parent::__construct( 'permissionserrors', Message::newFromSpecifier( $errors[0] ) );
68  }
69 
70  public function report( $action = self::SEND_OUTPUT ) {
71  global $wgOut;
72 
73  $wgOut->showPermissionsErrorPage( $this->errors, $this->permission );
74  if ( $action === self::SEND_OUTPUT ) {
75  $wgOut->output();
76  }
77  }
78 }
static getLink( $ugm, IContextSource $context, $format, $userName=null)
Gets a link for a user group, possibly including the expiry date if relevant.
getPermissionManager()
$wgLang
Definition: Setup.php:857
static getMain()
Get the RequestContext object associated with the main request.
An error page which can definitely be safely rendered using the OutputPage.
__construct( $permission, $errors=[])
report( $action=self::SEND_OUTPUT)
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition: Message.php:427
Show an error when a user tries to do something they do not have the necessary permissions for...
$wgOut
Definition: Setup.php:862