MediaWiki REL1_34
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}
getPermissionManager()
$wgOut
Definition Setup.php:885
$wgLang
Definition Setup.php:880
An error page which can definitely be safely rendered using the OutputPage.
MediaWikiServices is the service locator for the application scope of MediaWiki.
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.
report( $action=self::SEND_OUTPUT)
__construct( $permission, $errors=[])