MediaWiki 1.44.0
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;
45 private ?LinkTarget $doubleRedirectTarget;
46 private RedirectLookup $redirectLookup;
47
55 public function __construct(
56 bool $allowDoubleRedirects,
57 Content $newContent,
58 Content $originalContent,
59 LinkTarget $title,
60 RedirectLookup $redirectLookup
61 ) {
62 $this->allowDoubleRedirects = $allowDoubleRedirects;
63 $this->newContent = $newContent;
64 $this->originalContent = $originalContent;
65 $this->title = $title;
66 $this->redirectLookup = $redirectLookup;
67 }
68
69 public function checkConstraint(): string {
70 if ( !$this->allowDoubleRedirects ) {
71 $newRedirectTarget = $this->newContent->getRedirectTarget();
72
73 if ( $newRedirectTarget !== null && $newRedirectTarget->isRedirect() &&
74 !$newRedirectTarget->equals( $this->title ) ) {
75
76 $currentTarget = $this->originalContent->getRedirectTarget();
77
78 // fail if there was no previous content or the previous content already contained a double redirect
79 if ( !$currentTarget || !$currentTarget->isRedirect() ) {
80 $this->result = self::CONSTRAINT_FAILED;
81 $this->doubleRedirectTarget =
82 $this->redirectLookup->getRedirectTarget( $this->newContent->getRedirectTarget() );
83 $this->willCreateSelfRedirect =
84 $this->doubleRedirectTarget != null &&
85 $this->doubleRedirectTarget->isSameLinkAs( $this->title );
86
87 return self::CONSTRAINT_FAILED;
88 }
89 }
90 }
91 $this->result = self::CONSTRAINT_PASSED;
92
93 return self::CONSTRAINT_PASSED;
94 }
95
96 public function getLegacyStatus(): StatusValue {
97 $statusValue = StatusValue::newGood();
98 if ( $this->result === self::CONSTRAINT_FAILED ) {
99 $realRedirectTarget = $this->redirectLookup->getRedirectTarget( $this->newContent->getRedirectTarget() );
100 $realTargetTitle = Title::castFromLinkTarget( $realRedirectTarget );
101
102 $statusValue->fatal(
103 'edit-constraint-doubleredirect',
104 wfEscapeWikiText( $realTargetTitle->getPrefixedText() )
105 );
106 $statusValue->value = self::AS_DOUBLE_REDIRECT;
107 }
108
109 return $statusValue;
110 }
111
112}
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:82
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.