MediaWiki master
DoubleRedirectConstraint.php
Go to the documentation of this file.
1<?php
22
27use StatusValue;
28
38
39 private bool $allowDoubleRedirects;
40 private Content $newContent;
41 private Content $originalContent;
42 private LinkTarget $title;
43 private string $result;
44 private RedirectLookup $redirectLookup;
45
52 public function __construct(
53 bool $allowDoubleRedirects,
54 Content $newContent,
55 Content $originalContent,
56 LinkTarget $title,
57 RedirectLookup $redirectLookup
58 ) {
59 $this->allowDoubleRedirects = $allowDoubleRedirects;
60 $this->newContent = $newContent;
61 $this->originalContent = $originalContent;
62 $this->title = $title;
63 $this->redirectLookup = $redirectLookup;
64 }
65
66 public function checkConstraint(): string {
67 if ( !$this->allowDoubleRedirects ) {
68 $newRedirectTarget = $this->newContent->getRedirectTarget();
69
70 if ( $newRedirectTarget !== null && $newRedirectTarget->isRedirect() &&
71 !$newRedirectTarget->equals( $this->title ) ) {
72
73 $currentTarget = $this->originalContent->getRedirectTarget();
74
75 // fail if there was no previous content or the previous content already contained a double redirect
76 if ( !$currentTarget || !$currentTarget->isRedirect() ) {
77 $this->result = self::CONSTRAINT_FAILED;
78
79 return self::CONSTRAINT_FAILED;
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 if ( $this->result === self::CONSTRAINT_FAILED ) {
91 $realRedirectTarget = $this->redirectLookup->getRedirectTarget( $this->newContent->getRedirectTarget() );
92 $realTargetTitle = Title::castFromLinkTarget( $realRedirectTarget );
93
94 $statusValue->fatal(
95 'edit-constraint-doubleredirect',
96 wfEscapeWikiText( $realTargetTitle->getPrefixedText() )
97 );
98 $statusValue->value = self::AS_DOUBLE_REDIRECT;
99 }
100
101 return $statusValue;
102 }
103
104}
wfEscapeWikiText( $input)
Escapes the given text so that it may be output using addWikiText() without any linking,...
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:81
Verify the page does not redirect to another redirect unless.
__construct(bool $allowDoubleRedirects, Content $newContent, Content $originalContent, LinkTarget $title, RedirectLookup $redirectLookup)
getLegacyStatus()
Get the legacy status for failure (or success)
Represents a title within MediaWiki.
Definition Title.php:78
Generic operation result class Has warning/error list, boolean status and arbitrary value.
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.
Service for resolving a wiki page redirect.