MediaWiki  master
NewSectionMissingSummaryConstraint.php
Go to the documentation of this file.
1 <?php
22 
23 use StatusValue;
24 
33 
35  private $userSummary;
36 
39 
41  private $result;
42 
47  public function __construct(
48  string $userSummary,
50  ) {
51  $this->userSummary = $userSummary;
52  $this->allowBlankSummary = $allowBlankSummary;
53  }
54 
55  public function checkConstraint(): string {
56  if ( !$this->allowBlankSummary && trim( $this->userSummary ) == '' ) {
57  // TODO this was == in EditPage, can it be === ?
58  $this->result = self::CONSTRAINT_FAILED;
59  } else {
60  $this->result = self::CONSTRAINT_PASSED;
61  }
62  return $this->result;
63  }
64 
65  public function getLegacyStatus(): StatusValue {
66  $statusValue = StatusValue::newGood();
67  if ( $this->result === self::CONSTRAINT_FAILED ) {
68  // From EditPage, regarding the fatal:
69  // or 'missingcommentheader' if $section == 'new'. Blegh
70  $statusValue->fatal( 'missingsummary' );
71  $statusValue->value = self::AS_SUMMARY_NEEDED;
72  }
73  return $statusValue;
74  }
75 
76 }
StatusValue
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: StatusValue.php:43
MediaWiki\EditPage\Constraint\NewSectionMissingSummaryConstraint\getLegacyStatus
getLegacyStatus()
Get the legacy status for failure (or success)
Definition: NewSectionMissingSummaryConstraint.php:65
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\NewSectionMissingSummaryConstraint\$userSummary
string $userSummary
Definition: NewSectionMissingSummaryConstraint.php:35
MediaWiki\EditPage\Constraint\NewSectionMissingSummaryConstraint\$result
string null $result
Definition: NewSectionMissingSummaryConstraint.php:41
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:82
MediaWiki\EditPage\Constraint\NewSectionMissingSummaryConstraint
For a new section, do not allow the user to post with an empty summary unless they choose to.
Definition: NewSectionMissingSummaryConstraint.php:32
MediaWiki\EditPage\Constraint\NewSectionMissingSummaryConstraint\$allowBlankSummary
bool $allowBlankSummary
Definition: NewSectionMissingSummaryConstraint.php:38
MediaWiki\EditPage\Constraint
Definition: AccidentalRecreationConstraint.php:21
MediaWiki\EditPage\Constraint\NewSectionMissingSummaryConstraint\checkConstraint
checkConstraint()
Definition: NewSectionMissingSummaryConstraint.php:55
MediaWiki\EditPage\Constraint\NewSectionMissingSummaryConstraint\__construct
__construct(string $userSummary, bool $allowBlankSummary)
Definition: NewSectionMissingSummaryConstraint.php:47
MediaWiki\EditPage\Constraint\IEditConstraint
Interface for all constraints that can prevent edits.
Definition: IEditConstraint.php:33