MediaWiki
REL1_39
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
38
private
$allowSelfRedirect;
39
41
private
$newContent;
42
44
private
$originalContent;
45
47
private
$title;
48
50
private
$result;
51
58
public
function
__construct
(
59
bool
$allowSelfRedirect,
60
Content
$newContent,
61
Content
$originalContent,
62
LinkTarget
$title
63
) {
64
$this->allowSelfRedirect = $allowSelfRedirect;
65
$this->newContent = $newContent;
66
$this->originalContent = $originalContent;
67
$this->title =
$title
;
68
}
69
70
public
function
checkConstraint
(): string {
71
if
( !$this->allowSelfRedirect
72
&& $this->newContent->isRedirect()
73
&& $this->newContent->getRedirectTarget()->equals( $this->title )
74
) {
75
// T29683 If the page already redirects to itself, don't warn.
76
$currentTarget = $this->originalContent->getRedirectTarget();
77
if
( !$currentTarget || !$currentTarget->equals( $this->title ) ) {
78
$this->result = self::CONSTRAINT_FAILED;
79
return
self::CONSTRAINT_FAILED;
80
}
81
}
82
$this->result = self::CONSTRAINT_PASSED;
83
return
self::CONSTRAINT_PASSED;
84
}
85
86
public
function
getLegacyStatus
():
StatusValue
{
87
$statusValue =
StatusValue
::newGood();
88
if
( $this->result === self::CONSTRAINT_FAILED ) {
89
$statusValue->
fatal
(
'selfredirect'
);
90
$statusValue->value = self::AS_SELF_REDIRECT;
91
}
92
return
$statusValue;
93
}
94
95
}
if
if(!defined('MW_SETUP_CALLBACK'))
The persistent session ID (if any) loaded at startup.
Definition
WebStart.php:82
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:86
MediaWiki\EditPage\Constraint\SelfRedirectConstraint\__construct
__construct(bool $allowSelfRedirect, Content $newContent, Content $originalContent, LinkTarget $title)
Definition
SelfRedirectConstraint.php:58
MediaWiki\EditPage\Constraint\SelfRedirectConstraint\checkConstraint
checkConstraint()
Definition
SelfRedirectConstraint.php:70
StatusValue
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition
StatusValue.php:46
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:276
Content
Base interface for content objects.
Definition
Content.php:35
MediaWiki\EditPage\Constraint\IEditConstraint
Interface for all constraints that can prevent edits.
Definition
IEditConstraint.php:33
MediaWiki\Linker\LinkTarget
Definition
LinkTarget.php:26
MediaWiki\EditPage\Constraint
Definition
AccidentalRecreationConstraint.php:21
$title
$title
Definition
testCompression.php:38
includes
editpage
Constraint
SelfRedirectConstraint.php
Generated on Sat Dec 14 2024 09:23:08 for MediaWiki by
1.10.0