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