MediaWiki master
BrokenRedirectConstraint.php
Go to the documentation of this file.
1<?php
22
25use StatusValue;
26
36
37 private bool $allowBrokenRedirects;
38 private Content $newContent;
39 private Content $originalContent;
40 private LinkTarget $title;
41 private string $result;
42
49 public function __construct(
50 bool $allowBrokenRedirects,
51 Content $newContent,
52 Content $originalContent,
53 LinkTarget $title
54 ) {
55 $this->allowBrokenRedirects = $allowBrokenRedirects;
56 $this->newContent = $newContent;
57 $this->originalContent = $originalContent;
58 $this->title = $title;
59 }
60
61 public function checkConstraint(): string {
62 if ( !$this->allowBrokenRedirects ) {
63 $newRedirectTarget = $this->newContent->getRedirectTarget();
64
65 if ( $newRedirectTarget !== null && !$newRedirectTarget->exists() &&
66 !$newRedirectTarget->equals( $this->title ) ) {
67 $currentTarget = $this->originalContent->getRedirectTarget();
68
69 // fail if there was no previous content or the previous content contained
70 // a redirect to an existing page
71 if ( !$currentTarget || $currentTarget->exists() ) {
72 $this->result = self::CONSTRAINT_FAILED;
73
74 return self::CONSTRAINT_FAILED;
75 }
76 }
77
78 }
79 $this->result = self::CONSTRAINT_PASSED;
80
81 return self::CONSTRAINT_PASSED;
82 }
83
84 public function getLegacyStatus(): StatusValue {
85 $statusValue = StatusValue::newGood();
86 if ( $this->result === self::CONSTRAINT_FAILED ) {
87 $statusValue->fatal( 'edit-constraint-brokenredirect' );
88 $statusValue->value = self::AS_BROKEN_REDIRECT;
89 }
90
91 return $statusValue;
92 }
93
94}
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:81
Verify the page does not redirect to a nonexistent page unless.
__construct(bool $allowBrokenRedirects, Content $newContent, Content $originalContent, LinkTarget $title)
getLegacyStatus()
Get the legacy status for failure (or success)
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:39
Interface for all constraints that can prevent edits.
Represents the target of a wiki link.