MediaWiki  master
SelfRedirectConstraint.php
Go to the documentation of this file.
1 <?php
22 
23 use Content;
25 use StatusValue;
26 
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(!defined('MW_SETUP_CALLBACK'))
The persistent session ID (if any) loaded at startup.
Definition: WebStart.php:82
Verify the page does not redirect to itself unless.
getLegacyStatus()
Get the legacy status for failure (or success)
__construct(bool $allowSelfRedirect, Content $newContent, Content $originalContent, LinkTarget $title)
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: StatusValue.php:46
fatal( $message,... $parameters)
Add an error and set OK to false, indicating that the operation as a whole was fatal.
Base interface for representing page content.
Definition: Content.php:34
Interface for all constraints that can prevent edits.