MediaWiki  master
PermissionsError.php
Go to the documentation of this file.
1 <?php
22 
33 
42  public function __construct( $permission, $errors = [] ) {
43  global $wgLang;
44 
45  if ( $permission === null && !$errors ) {
46  throw new \InvalidArgumentException( __METHOD__ .
47  ': $permission and $errors cannot both be empty' );
48  }
49 
50  $this->permission = $permission;
51 
52  if ( !count( $errors ) ) {
53  $groups = [];
54  foreach ( MediaWikiServices::getInstance()
56  ->getGroupsWithPermission( $this->permission ) as $group ) {
57  $groups[] = UserGroupMembership::getLink( $group, RequestContext::getMain(), 'wiki' );
58  }
59 
60  if ( $groups ) {
61  $errors[] = [ 'badaccess-groups', $wgLang->commaList( $groups ), count( $groups ) ];
62  } else {
63  $errors[] = [ 'badaccess-group0' ];
64  }
65  }
66 
67  $this->errors = $errors;
68 
69  // Give the parent class something to work with
70  parent::__construct( 'permissionserrors', Message::newFromSpecifier( $errors[0] ) );
71  }
72 
73  public function report( $action = self::SEND_OUTPUT ) {
74  global $wgOut;
75 
76  $wgOut->showPermissionsErrorPage( $this->errors, $this->permission );
77  if ( $action === self::SEND_OUTPUT ) {
78  $wgOut->output();
79  }
80  }
81 }
Message\newFromSpecifier
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition: Message.php:436
PermissionsError\__construct
__construct( $permission, $errors=[])
Stable to call.
Definition: PermissionsError.php:42
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:154
PermissionsError
Show an error when a user tries to do something they do not have the necessary permissions for.
Definition: PermissionsError.php:31
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:279
getPermissionManager
getPermissionManager()
$wgLang
$wgLang
Definition: Setup.php:776
PermissionsError\$permission
$permission
Definition: PermissionsError.php:32
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:453
PermissionsError\$errors
$errors
Definition: PermissionsError.php:32
PermissionsError\report
report( $action=self::SEND_OUTPUT)
Stable to override.
Definition: PermissionsError.php:73
$wgOut
$wgOut
Definition: Setup.php:781
ErrorPageError
An error page which can definitely be safely rendered using the OutputPage.
Definition: ErrorPageError.php:30