MediaWiki REL1_36
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 ->getPermissionManager()
61 ->getGroupsWithPermission( $this->permission ) as $group ) {
62 $groups[] = UserGroupMembership::getLink( $group, RequestContext::getMain(), 'wiki' );
63 }
64
65 if ( $groups ) {
66 $errors[] = [ 'badaccess-groups', $wgLang->commaList( $groups ), count( $groups ) ];
67 } else {
68 $errors[] = [ 'badaccess-group0' ];
69 }
70 }
71
72 $this->errors = $errors;
73
74 // Give the parent class something to work with
75 parent::__construct( 'permissionserrors', Message::newFromSpecifier( $errors[0] ) );
76 }
77
78 public function report( $action = self::SEND_OUTPUT ) {
79 global $wgOut;
80
81 $wgOut->showPermissionsErrorPage( $this->errors, $this->permission );
82 if ( $action === self::SEND_OUTPUT ) {
83 $wgOut->output();
84 }
85 }
86}
$wgOut
Definition Setup.php:818
$wgLang
Definition Setup.php:813
An error page which can definitely be safely rendered using the OutputPage.
MediaWikiServices is the service locator for the application scope of MediaWiki.
A StatusValue for permission errors.
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition Message.php:415
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=[])