MediaWiki master
PermissionsError.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Exception;
8
10use MediaWiki\Debug\DeprecationHelper;
13
23
24 use DeprecationHelper;
25
26 private ?string $permission;
27 private PermissionStatus $status;
28
37 public function __construct( ?string $permission, $status = [] ) {
38 $this->deprecatePublicProperty( 'permission', '1.43' );
39
40 if ( is_array( $status ) ) {
41 $errors = $status;
42 $status = PermissionStatus::newEmpty();
43 foreach ( $errors as $error ) {
44 if ( is_array( $error ) ) {
45 // @phan-suppress-next-line PhanParamTooFewUnpack
46 $status->fatal( ...$error );
47 } else {
48 $status->fatal( $error );
49 }
50 }
51 } elseif ( !( $status instanceof PermissionStatus ) ) {
52 throw new \InvalidArgumentException( __METHOD__ .
53 ': $status must be PermissionStatus or array, got ' . get_debug_type( $status ) );
54 }
55
56 if ( $permission === null && $status->isGood() ) {
57 throw new \InvalidArgumentException( __METHOD__ .
58 ': $permission and $status cannot both be empty' );
59 }
60
61 $this->permission = $permission;
62
63 if ( $status->isGood() ) {
65 ->getPermissionManager()
66 // @phan-suppress-next-line PhanTypeMismatchArgumentNullable Null on permission is check when used here
67 ->newFatalPermissionDeniedStatus( $this->permission, RequestContext::getMain() );
68 }
69
70 $this->status = $status;
71
72 // Give the parent class something to work with
73 parent::__construct( 'permissionserrors', $status->getMessages()[0] );
74 }
75
77 public function report( $action = self::SEND_OUTPUT ) {
78 global $wgOut;
79
80 $wgOut->showPermissionStatus( $this->status, $this->permission );
81 if ( $action === self::SEND_OUTPUT ) {
82 $wgOut->output();
83 }
84 }
85}
86
88class_alias( PermissionsError::class, 'PermissionsError' );
if(MW_ENTRY_POINT==='index') if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgOut
Definition Setup.php:551
Group all the pieces relevant to the context of a request into one instance.
An error page which can definitely be safely rendered using the OutputPage.
Show an error when a user tries to do something they do not have the necessary permissions for.
report( $action=self::SEND_OUTPUT)
to override
__construct(?string $permission, $status=[])
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
A StatusValue for permission errors.
getMessages(?string $type=null)
Returns a list of error messages, optionally only those of the given type.
fatal( $message,... $parameters)
Add an error and set OK to false, indicating that the operation as a whole was fatal.
isGood()
Returns whether the operation completed and didn't have any error or warnings.