MediaWiki master
EditRightConstraint.php
Go to the documentation of this file.
1<?php
22
26use StatusValue;
27
37
38 private User $performer;
39 private PermissionManager $permManager;
40 private Title $title;
41 private string $result;
42 private bool $new;
43
50 public function __construct(
51 User $performer,
52 PermissionManager $permManager,
53 Title $title,
54 bool $new
55 ) {
56 $this->performer = $performer;
57 $this->permManager = $permManager;
58 $this->title = $title;
59 $this->new = $new;
60 }
61
62 public function checkConstraint(): string {
63 if ( $this->new ) {
64 // Check isn't simple enough to just repeat when getting the status
65 if ( !$this->performer->authorizeWrite( 'create', $this->title ) ) {
66 $this->result = (string)self::AS_NO_CREATE_PERMISSION;
67 return self::CONSTRAINT_FAILED;
68 }
69 }
70
71 // Check isn't simple enough to just repeat when getting the status
72 // Prior to 1.41 this checked if the user had edit rights in general
73 // instead of for the specific page in question.
74 if ( !$this->permManager->userCan(
75 'edit',
76 $this->performer,
77 $this->title
78 ) ) {
79 $this->result = self::CONSTRAINT_FAILED;
80 return self::CONSTRAINT_FAILED;
81 }
82
83 $this->result = self::CONSTRAINT_PASSED;
84 return self::CONSTRAINT_PASSED;
85 }
86
87 public function getLegacyStatus(): StatusValue {
88 $statusValue = StatusValue::newGood();
89
90 if ( $this->result === self::CONSTRAINT_FAILED ) {
91 if ( !$this->performer->isRegistered() ) {
92 $statusValue->setResult( false, self::AS_READ_ONLY_PAGE_ANON );
93 } else {
94 $statusValue->fatal( 'readonlytext' );
95 $statusValue->value = self::AS_READ_ONLY_PAGE_LOGGED;
96 }
97 } elseif ( $this->result === (string)self::AS_NO_CREATE_PERMISSION ) {
98 $statusValue->fatal( 'nocreatetext' );
99 $statusValue->value = self::AS_NO_CREATE_PERMISSION;
100 }
101
102 return $statusValue;
103 }
104
105}
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.