MediaWiki  master
SelfRedirectConstraint.php
Go to the documentation of this file.
1 <?php
22 
23 use Content;
25 use StatusValue;
26 
36 
39 
41  private $newContent;
42 
45 
47  private $title;
48 
50  private $result;
51 
58  public function __construct(
59  bool $allowSelfRedirect,
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 }
StatusValue
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: StatusValue.php:43
MediaWiki\EditPage\Constraint\SelfRedirectConstraint\__construct
__construct(bool $allowSelfRedirect, Content $newContent, Content $originalContent, LinkTarget $title)
Definition: SelfRedirectConstraint.php:58
MediaWiki\EditPage\Constraint\SelfRedirectConstraint\$originalContent
Content $originalContent
Definition: SelfRedirectConstraint.php:44
MediaWiki\EditPage\Constraint\SelfRedirectConstraint\$allowSelfRedirect
bool $allowSelfRedirect
Definition: SelfRedirectConstraint.php:38
MediaWiki\EditPage\Constraint\SelfRedirectConstraint\getLegacyStatus
getLegacyStatus()
Get the legacy status for failure (or success)
Definition: SelfRedirectConstraint.php:86
MediaWiki\EditPage\IEditObject\AS_SELF_REDIRECT
const AS_SELF_REDIRECT
Status: user tried to create self-redirect and wpIgnoreSelfRedirect is false.
Definition: IEditObject.php:104
MediaWiki\EditPage\Constraint\SelfRedirectConstraint\checkConstraint
checkConstraint()
Definition: SelfRedirectConstraint.php:70
MediaWiki\EditPage\Constraint\SelfRedirectConstraint
Verify the page does not redirect to itself unless.
Definition: SelfRedirectConstraint.php:35
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:82
Content
Base interface for content objects.
Definition: Content.php:35
MediaWiki\EditPage\Constraint\SelfRedirectConstraint\$title
LinkTarget $title
Definition: SelfRedirectConstraint.php:47
MediaWiki\EditPage\Constraint
Definition: AccidentalRecreationConstraint.php:21
MediaWiki\EditPage\Constraint\SelfRedirectConstraint\$result
string null $result
Definition: SelfRedirectConstraint.php:50
MediaWiki\Linker\LinkTarget
Definition: LinkTarget.php:26
MediaWiki\EditPage\Constraint\IEditConstraint
Interface for all constraints that can prevent edits.
Definition: IEditConstraint.php:33
MediaWiki\EditPage\Constraint\SelfRedirectConstraint\$newContent
Content $newContent
Definition: SelfRedirectConstraint.php:41