MediaWiki master
PermissionsError.php
Go to the documentation of this file.
1<?php
25
35 public ?string $permission;
36 public array $errors;
37
46 public function __construct( ?string $permission, $errors = [] ) {
47 if ( $errors instanceof PermissionStatus ) {
48 $errors = $errors->toLegacyErrorArray();
49 }
50
51 if ( $permission === null && !$errors ) {
52 throw new \InvalidArgumentException( __METHOD__ .
53 ': $permission and $errors cannot both be empty' );
54 }
55
56 $this->permission = $permission;
57
58 if ( !count( $errors ) ) {
59 $errors = MediaWikiServices::getInstance()
60 ->getPermissionManager()
61 // @phan-suppress-next-line PhanTypeMismatchArgumentNullable Null on permission is check when used here
62 ->newFatalPermissionDeniedStatus( $this->permission, RequestContext::getMain() )
63 ->toLegacyErrorArray();
64 }
65
66 $this->errors = $errors;
67
68 // Give the parent class something to work with
69 parent::__construct( 'permissionserrors', Message::newFromSpecifier( $errors[0] ) );
70 }
71
72 public function report( $action = self::SEND_OUTPUT ) {
73 global $wgOut;
74
75 $wgOut->showPermissionsErrorPage( $this->errors, $this->permission );
76 if ( $action === self::SEND_OUTPUT ) {
77 $wgOut->output();
78 }
79 }
80}
if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgOut
Definition Setup.php:538
An error page which can definitely be safely rendered using the OutputPage.
Group all the pieces relevant to the context of a request into one instance.
Service locator for MediaWiki core services.
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition Message.php:158
A StatusValue for permission errors.
Show an error when a user tries to do something they do not have the necessary permissions for.
report( $action=self::SEND_OUTPUT)
__construct(?string $permission, $errors=[])