MediaWiki  master
AutoSummaryMissingSummaryConstraint.php
Go to the documentation of this file.
1 <?php
22 
23 use Content;
24 use StatusValue;
25 
42 
44  private $userSummary;
45 
47  private $autoSummary;
48 
51 
53  private $newContent;
54 
57 
59  private $result;
60 
68  public function __construct(
69  string $userSummary,
70  string $autoSummary,
71  bool $allowBlankSummary,
74  ) {
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 (
84  !$this->allowBlankSummary &&
85  !$this->newContent->equals( $this->originalContent ) &&
86  !$this->newContent->isRedirect() &&
87  md5( $this->userSummary ) == $this->autoSummary
88  ) {
89  // TODO this was == in EditPage, can it be === ?
90  $this->result = self::CONSTRAINT_FAILED;
91  } else {
92  $this->result = self::CONSTRAINT_PASSED;
93  }
94  return $this->result;
95  }
96 
97  public function getLegacyStatus(): StatusValue {
98  $statusValue = StatusValue::newGood();
99  if ( $this->result === self::CONSTRAINT_FAILED ) {
100  $statusValue->fatal( 'missingsummary' );
101  $statusValue->value = self::AS_SUMMARY_NEEDED;
102  }
103  return $statusValue;
104  }
105 
106 }
StatusValue
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: StatusValue.php:43
MediaWiki\EditPage\IEditObject\AS_SUMMARY_NEEDED
const AS_SUMMARY_NEEDED
Status: no edit summary given and the user has forceeditsummary set and the user is not editing in hi...
Definition: IEditObject.php:77
MediaWiki\EditPage\Constraint\AutoSummaryMissingSummaryConstraint\$autoSummary
string $autoSummary
Definition: AutoSummaryMissingSummaryConstraint.php:47
MediaWiki\EditPage\Constraint\AutoSummaryMissingSummaryConstraint\$result
string null $result
Definition: AutoSummaryMissingSummaryConstraint.php:59
MediaWiki\EditPage\Constraint\AutoSummaryMissingSummaryConstraint
For an edit to an existing page but not with a new section, do not allow the user to post with a summ...
Definition: AutoSummaryMissingSummaryConstraint.php:41
MediaWiki\EditPage\Constraint\AutoSummaryMissingSummaryConstraint\__construct
__construct(string $userSummary, string $autoSummary, bool $allowBlankSummary, Content $newContent, Content $originalContent)
Definition: AutoSummaryMissingSummaryConstraint.php:68
MediaWiki\EditPage\Constraint\AutoSummaryMissingSummaryConstraint\getLegacyStatus
getLegacyStatus()
Get the legacy status for failure (or success)
Definition: AutoSummaryMissingSummaryConstraint.php:97
MediaWiki\EditPage\Constraint\AutoSummaryMissingSummaryConstraint\$userSummary
string $userSummary
Definition: AutoSummaryMissingSummaryConstraint.php:44
MediaWiki\EditPage\Constraint\AutoSummaryMissingSummaryConstraint\$newContent
Content $newContent
Definition: AutoSummaryMissingSummaryConstraint.php:53
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:82
MediaWiki\EditPage\Constraint\AutoSummaryMissingSummaryConstraint\$originalContent
Content $originalContent
Definition: AutoSummaryMissingSummaryConstraint.php:56
MediaWiki\EditPage\Constraint\AutoSummaryMissingSummaryConstraint\checkConstraint
checkConstraint()
Definition: AutoSummaryMissingSummaryConstraint.php:82
Content
Base interface for content objects.
Definition: Content.php:35
MediaWiki\EditPage\Constraint
Definition: AccidentalRecreationConstraint.php:21
MediaWiki\EditPage\Constraint\AutoSummaryMissingSummaryConstraint\$allowBlankSummary
bool $allowBlankSummary
Definition: AutoSummaryMissingSummaryConstraint.php:50
MediaWiki\EditPage\Constraint\IEditConstraint
Interface for all constraints that can prevent edits.
Definition: IEditConstraint.php:33