MediaWiki master
AuthorizationConstraint.php
Go to the documentation of this file.
1<?php
22
26use StatusValue;
27
35
36 private PermissionStatus $status;
37
38 private Authority $performer;
39 private PageIdentity $target;
40 private bool $new;
41
42 public function __construct(
43 Authority $performer,
44 PageIdentity $target,
45 bool $new
46 ) {
47 $this->performer = $performer;
48 $this->target = $target;
49 $this->new = $new;
50 }
51
52 public function checkConstraint(): string {
53 $this->status = PermissionStatus::newEmpty();
54
55 if ( $this->new && !$this->performer->authorizeWrite( 'create', $this->target, $this->status ) ) {
56 return self::CONSTRAINT_FAILED;
57 }
58
59 if ( !$this->performer->authorizeWrite( 'edit', $this->target, $this->status ) ) {
60 return self::CONSTRAINT_FAILED;
61 }
62
63 return self::CONSTRAINT_PASSED;
64 }
65
66 public function getLegacyStatus(): StatusValue {
67 $statusValue = StatusValue::newGood();
68
69 if ( !$this->status->isGood() ) {
70 // Report the most specific errors first
71 if ( $this->status->isBlocked() ) {
72 $statusValue->setResult( false, self::AS_BLOCKED_PAGE_FOR_USER );
73 } elseif ( $this->status->isRateLimitExceeded() ) {
74 $statusValue->setResult( false, self::AS_RATE_LIMITED );
75 } elseif ( $this->status->getPermission() === 'create' ) {
76 $statusValue->setResult( false, self::AS_NO_CREATE_PERMISSION );
77 } elseif ( !$this->performer->isRegistered() ) {
78 $statusValue->setResult( false, self::AS_READ_ONLY_PAGE_ANON );
79 } else {
80 $statusValue->setResult( false, self::AS_READ_ONLY_PAGE_LOGGED );
81 }
82 }
83
84 // TODO: Use error messages from the PermissionStatus ($this->status) here - T384399
85 return $statusValue;
86 }
87
88}
Verify authorization to edit the page (user rights, rate limits, blocks).
getLegacyStatus()
Get the legacy status for failure (or success)
__construct(Authority $performer, PageIdentity $target, bool $new)
A StatusValue for permission errors.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
setResult( $ok, $value=null)
Change operation result.
Interface for all constraints that can prevent edits.
Interface for objects (potentially) representing an editable wiki page.
This interface represents the authority associated with the current execution context,...
Definition Authority.php:37