MediaWiki master
EditRightConstraint.php
Go to the documentation of this file.
1<?php
22
26use StatusValue;
27
37
39 private $performer;
40
42 private $permManager;
43
45 private $title;
46
48 private $result;
49
51 private $new;
52
59 public function __construct(
60 User $performer,
61 PermissionManager $permManager,
62 Title $title,
63 bool $new
64 ) {
65 $this->performer = $performer;
66 $this->permManager = $permManager;
67 $this->title = $title;
68 $this->new = $new;
69 }
70
71 public function checkConstraint(): string {
72 if ( $this->new ) {
73 // Check isn't simple enough to just repeat when getting the status
74 if ( !$this->performer->authorizeWrite( 'create', $this->title ) ) {
75 $this->result = (string)self::AS_NO_CREATE_PERMISSION;
76 return self::CONSTRAINT_FAILED;
77 }
78 }
79
80 // Check isn't simple enough to just repeat when getting the status
81 // Prior to 1.41 this checked if the user had edit rights in general
82 // instead of for the specific page in question.
83 if ( $this->permManager->getPermissionErrors(
84 'edit',
85 $this->performer,
86 $this->title
87 ) ) {
88 $this->result = self::CONSTRAINT_FAILED;
89 return self::CONSTRAINT_FAILED;
90 }
91
92 $this->result = self::CONSTRAINT_PASSED;
93 return self::CONSTRAINT_PASSED;
94 }
95
96 public function getLegacyStatus(): StatusValue {
97 $statusValue = StatusValue::newGood();
98
99 if ( $this->result === self::CONSTRAINT_FAILED ) {
100 if ( !$this->performer->isRegistered() ) {
101 $statusValue->setResult( false, self::AS_READ_ONLY_PAGE_ANON );
102 } else {
103 $statusValue->fatal( 'readonlytext' );
104 $statusValue->value = self::AS_READ_ONLY_PAGE_LOGGED;
105 }
106 } elseif ( $this->result === (string)self::AS_NO_CREATE_PERMISSION ) {
107 $statusValue->fatal( 'nocreatetext' );
108 $statusValue->value = self::AS_NO_CREATE_PERMISSION;
109 }
110
111 return $statusValue;
112 }
113
114}
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:81
Verify user permissions: Must have edit rights.
__construct(User $performer, PermissionManager $permManager, Title $title, bool $new)
getLegacyStatus()
Get the legacy status for failure (or success)
A service class for checking permissions To obtain an instance, use MediaWikiServices::getInstance()-...
Represents a title within MediaWiki.
Definition Title.php:78
internal since 1.36
Definition User.php:93
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.