MediaWiki master
SelfRedirectConstraint.php
Go to the documentation of this file.
1<?php
22
23use Content;
25use StatusValue;
26
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(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:81
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.
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:37
Interface for all constraints that can prevent edits.
Represents the target of a wiki link.