MediaWiki master
ExistingSectionEditConstraint.php
Go to the documentation of this file.
1<?php
8
10use StatusValue;
11
35
36 private string $result;
37
46 public function __construct(
47 private readonly string $section,
48 private readonly string $userSummary,
49 private readonly string $autoSummary,
50 private readonly bool $allowBlankSummary,
51 private readonly Content $newContent,
52 private readonly ?Content $originalContent,
53 ) {
54 }
55
56 public function checkConstraint(): string {
57 if ( $this->section === 'new' ) {
58 // Constraint is not applicable
59 $this->result = self::CONSTRAINT_PASSED;
60 return self::CONSTRAINT_PASSED;
61 }
62 if ( $this->originalContent === null ) {
63 // T301947: User loses access to revision after loading
64 $this->result = self::CONSTRAINT_FAILED;
65 return self::CONSTRAINT_FAILED;
66 }
67 if (
68 !$this->allowBlankSummary &&
69 !$this->newContent->equals( $this->originalContent ) &&
70 !$this->newContent->isRedirect() &&
71 md5( $this->userSummary ) === $this->autoSummary
72 ) {
73 $this->result = self::CONSTRAINT_FAILED;
74 } else {
75 $this->result = self::CONSTRAINT_PASSED;
76 }
77 return $this->result;
78 }
79
80 public function getLegacyStatus(): StatusValue {
81 $statusValue = StatusValue::newGood();
82 if ( $this->result === self::CONSTRAINT_FAILED ) {
83 if ( $this->originalContent === null ) {
84 // T301947: User loses access to revision after loading
85 // The error message, rev-deleted-text-permission, is not
86 // really in use currently. It's added for completeness and in
87 // case any code path wants to know the error.
88 $statusValue->fatal( 'rev-deleted-text-permission' );
89 $statusValue->value = self::AS_REVISION_WAS_DELETED;
90 } else {
91 $statusValue->fatal( 'missingsummary' );
92 $statusValue->value = self::AS_SUMMARY_NEEDED;
93 }
94 }
95 return $statusValue;
96 }
97
98}
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:68
To simplify the logic in EditPage, this constraint may be created even if the section being edited do...
getLegacyStatus()
Get the legacy status for failure (or success)
__construct(private readonly string $section, private readonly string $userSummary, private readonly string $autoSummary, private readonly bool $allowBlankSummary, private readonly Content $newContent, private readonly ?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.
Content objects represent page content, e.g.
Definition Content.php:28
Interface for all constraints that can prevent edits.