MediaWiki
master
ExistingSectionEditConstraint.php
Go to the documentation of this file.
1
<?php
21
namespace
MediaWiki\EditPage\Constraint
;
22
23
use
Content
;
24
use
StatusValue
;
25
48
class
ExistingSectionEditConstraint
implements
IEditConstraint
{
49
50
private
string
$section;
51
private
string
$userSummary;
52
private
string
$autoSummary;
53
private
bool
$allowBlankSummary;
54
private
Content
$newContent;
55
private
?
Content
$originalContent;
56
private
string
$result;
57
66
public
function
__construct
(
67
string
$section,
68
string
$userSummary,
69
string
$autoSummary,
70
bool
$allowBlankSummary,
71
Content
$newContent,
72
?
Content
$originalContent
73
) {
74
$this->section = $section;
75
$this->userSummary = $userSummary;
76
$this->autoSummary = $autoSummary;
77
$this->allowBlankSummary = $allowBlankSummary;
78
$this->newContent = $newContent;
79
$this->originalContent = $originalContent;
80
}
81
82
public
function
checkConstraint
(): string {
83
if
( $this->section ===
'new'
) {
84
// Constraint is not applicable
85
$this->result = self::CONSTRAINT_PASSED;
86
return
self::CONSTRAINT_PASSED;
87
}
88
if
( $this->originalContent ===
null
) {
89
// T301947: User loses access to revision after loading
90
$this->result = self::CONSTRAINT_FAILED;
91
return
self::CONSTRAINT_FAILED;
92
}
93
if
(
94
!$this->allowBlankSummary &&
95
!$this->newContent->equals( $this->originalContent ) &&
96
!$this->newContent->isRedirect() &&
97
md5( $this->userSummary ) === $this->autoSummary
98
) {
99
$this->result = self::CONSTRAINT_FAILED;
100
}
else
{
101
$this->result = self::CONSTRAINT_PASSED;
102
}
103
return
$this->result;
104
}
105
106
public
function
getLegacyStatus
():
StatusValue
{
107
$statusValue =
StatusValue
::newGood();
108
if
( $this->result === self::CONSTRAINT_FAILED ) {
109
if
( $this->originalContent ===
null
) {
110
// T301947: User loses access to revision after loading
111
// The error message, rev-deleted-text-permission, is not
112
// really in use currently. It's added for completeness and in
113
// case any code path wants to know the error.
114
$statusValue->
fatal
(
'rev-deleted-text-permission'
);
115
$statusValue->value = self::AS_REVISION_WAS_DELETED;
116
}
else
{
117
$statusValue->fatal(
'missingsummary'
);
118
$statusValue->value = self::AS_SUMMARY_NEEDED;
119
}
120
}
121
return
$statusValue;
122
}
123
124
}
if
if(!defined('MW_SETUP_CALLBACK'))
Definition
WebStart.php:81
MediaWiki\EditPage\Constraint\ExistingSectionEditConstraint
To simplify the logic in EditPage, this constraint may be created even if the section being edited do...
Definition
ExistingSectionEditConstraint.php:48
MediaWiki\EditPage\Constraint\ExistingSectionEditConstraint\getLegacyStatus
getLegacyStatus()
Get the legacy status for failure (or success)
Definition
ExistingSectionEditConstraint.php:106
MediaWiki\EditPage\Constraint\ExistingSectionEditConstraint\__construct
__construct(string $section, string $userSummary, string $autoSummary, bool $allowBlankSummary, Content $newContent, ?Content $originalContent)
Definition
ExistingSectionEditConstraint.php:66
MediaWiki\EditPage\Constraint\ExistingSectionEditConstraint\checkConstraint
checkConstraint()
Definition
ExistingSectionEditConstraint.php:82
StatusValue
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition
StatusValue.php:49
StatusValue\fatal
fatal( $message,... $parameters)
Add an error and set OK to false, indicating that the operation as a whole was fatal.
Definition
StatusValue.php:287
Content
Base interface for representing page content.
Definition
Content.php:37
MediaWiki\EditPage\Constraint\IEditConstraint
Interface for all constraints that can prevent edits.
Definition
IEditConstraint.php:33
MediaWiki\EditPage\Constraint
Definition
AccidentalRecreationConstraint.php:21
includes
editpage
Constraint
ExistingSectionEditConstraint.php
Generated on Sat Jul 27 2024 11:22:43 for MediaWiki by
1.10.0