MediaWiki  1.34.0
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 }
PermissionsError\__construct
__construct( $permission, $errors=[])
Definition: PermissionsError.php:39
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:117
PermissionsError
Show an error when a user tries to do something they do not have the necessary permissions for.
Definition: PermissionsError.php:30
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:376
getPermissionManager
getPermissionManager()
$wgLang
$wgLang
Definition: Setup.php:881
PermissionsError\$permission
$permission
Definition: PermissionsError.php:31
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:431
PermissionsError\$errors
$errors
Definition: PermissionsError.php:31
PermissionsError\report
report( $action=self::SEND_OUTPUT)
Definition: PermissionsError.php:70
$wgOut
$wgOut
Definition: Setup.php:886
ErrorPageError
An error page which can definitely be safely rendered using the OutputPage.
Definition: ErrorPageError.php:27