MediaWiki master
ExistingSectionEditConstraint.php
Go to the documentation of this file.
1<?php
22
23use Content;
24use StatusValue;
25
49
50 private string $section;
51 private string $userSummary;
52 private string $autoSummary;
53 private bool $allowBlankSummary;
54 private Content $newContent;
55 private ?Content $originalContent;
56 private string $result;
57
66 public function __construct(
67 string $section,
68 string $userSummary,
69 string $autoSummary,
70 bool $allowBlankSummary,
71 Content $newContent,
72 ?Content $originalContent
73 ) {
74 $this->section = $section;
75 $this->userSummary = $userSummary;
76 $this->autoSummary = $autoSummary;
77 $this->allowBlankSummary = $allowBlankSummary;
78 $this->newContent = $newContent;
79 $this->originalContent = $originalContent;
80 }
81
82 public function checkConstraint(): string {
83 if ( $this->section === 'new' ) {
84 // Constraint is not applicable
85 $this->result = self::CONSTRAINT_PASSED;
86 return self::CONSTRAINT_PASSED;
87 }
88 if ( $this->originalContent === null ) {
89 // T301947: User loses access to revision after loading
90 $this->result = self::CONSTRAINT_FAILED;
91 return self::CONSTRAINT_FAILED;
92 }
93 if (
94 !$this->allowBlankSummary &&
95 !$this->newContent->equals( $this->originalContent ) &&
96 !$this->newContent->isRedirect() &&
97 md5( $this->userSummary ) === $this->autoSummary
98 ) {
99 $this->result = self::CONSTRAINT_FAILED;
100 } else {
101 $this->result = self::CONSTRAINT_PASSED;
102 }
103 return $this->result;
104 }
105
106 public function getLegacyStatus(): StatusValue {
107 $statusValue = StatusValue::newGood();
108 if ( $this->result === self::CONSTRAINT_FAILED ) {
109 if ( $this->originalContent === null ) {
110 // T301947: User loses access to revision after loading
111 // The error message, rev-deleted-text-permission, is not
112 // really in use currently. It's added for completeness and in
113 // case any code path wants to know the error.
114 $statusValue->fatal( 'rev-deleted-text-permission' );
115 $statusValue->value = self::AS_REVISION_WAS_DELETED;
116 } else {
117 $statusValue->fatal( 'missingsummary' );
118 $statusValue->value = self::AS_SUMMARY_NEEDED;
119 }
120 }
121 return $statusValue;
122 }
123
124}
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:81
To simplify the logic in EditPage, this constraint may be created even if the section being edited do...
__construct(string $section, string $userSummary, string $autoSummary, bool $allowBlankSummary, Content $newContent, ?Content $originalContent)
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.