MediaWiki
master
SelfRedirectConstraint.php
Go to the documentation of this file.
1
<?php
21
namespace
MediaWiki\EditPage\Constraint
;
22
23
use
Content
;
24
use
MediaWiki\Linker\LinkTarget
;
25
use
StatusValue
;
26
35
class
SelfRedirectConstraint
implements
IEditConstraint
{
36
37
private
bool
$allowSelfRedirect;
38
private
Content
$newContent;
39
private
Content
$originalContent;
40
private
LinkTarget
$title;
41
private
string
$result;
42
49
public
function
__construct
(
50
bool
$allowSelfRedirect,
51
Content
$newContent,
52
Content
$originalContent,
53
LinkTarget
$title
54
) {
55
$this->allowSelfRedirect = $allowSelfRedirect;
56
$this->newContent = $newContent;
57
$this->originalContent = $originalContent;
58
$this->title = $title;
59
}
60
61
public
function
checkConstraint
(): string {
62
if
( !$this->allowSelfRedirect
63
&& $this->newContent->isRedirect()
64
&& $this->newContent->getRedirectTarget()->equals( $this->title )
65
) {
66
// T29683 If the page already redirects to itself, don't warn.
67
$currentTarget = $this->originalContent->getRedirectTarget();
68
if
( !$currentTarget || !$currentTarget->equals( $this->title ) ) {
69
$this->result = self::CONSTRAINT_FAILED;
70
return
self::CONSTRAINT_FAILED;
71
}
72
}
73
$this->result = self::CONSTRAINT_PASSED;
74
return
self::CONSTRAINT_PASSED;
75
}
76
77
public
function
getLegacyStatus
():
StatusValue
{
78
$statusValue =
StatusValue
::newGood();
79
if
( $this->result === self::CONSTRAINT_FAILED ) {
80
$statusValue->
fatal
(
'selfredirect'
);
81
$statusValue->value = self::AS_SELF_REDIRECT;
82
}
83
return
$statusValue;
84
}
85
86
}
if
if(!defined('MW_SETUP_CALLBACK'))
Definition
WebStart.php:81
MediaWiki\EditPage\Constraint\SelfRedirectConstraint
Verify the page does not redirect to itself unless.
Definition
SelfRedirectConstraint.php:35
MediaWiki\EditPage\Constraint\SelfRedirectConstraint\getLegacyStatus
getLegacyStatus()
Get the legacy status for failure (or success)
Definition
SelfRedirectConstraint.php:77
MediaWiki\EditPage\Constraint\SelfRedirectConstraint\__construct
__construct(bool $allowSelfRedirect, Content $newContent, Content $originalContent, LinkTarget $title)
Definition
SelfRedirectConstraint.php:49
MediaWiki\EditPage\Constraint\SelfRedirectConstraint\checkConstraint
checkConstraint()
Definition
SelfRedirectConstraint.php:61
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\Linker\LinkTarget
Represents the target of a wiki link.
Definition
LinkTarget.php:33
MediaWiki\EditPage\Constraint
Definition
AccidentalRecreationConstraint.php:21
includes
editpage
Constraint
SelfRedirectConstraint.php
Generated on Sat Jul 27 2024 00:23:01 for MediaWiki by
1.10.0