MediaWiki master
NewSectionMissingSubjectConstraint.php
Go to the documentation of this file.
1<?php
22
23use StatusValue;
24
33
35 private $subject;
36
38 private $allowBlankSubject;
39
41 private $result;
42
47 public function __construct(
48 string $subject,
49 bool $allowBlankSubject
50 ) {
51 $this->subject = $subject;
52 $this->allowBlankSubject = $allowBlankSubject;
53 }
54
55 public function checkConstraint(): string {
56 if ( !$this->allowBlankSubject && trim( $this->subject ) == '' ) {
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 // For new sections, the subject is also used for the summary,
71 // so we report missing summaries if the section is missing
72 $statusValue->fatal( 'missingsummary' );
73 $statusValue->value = self::AS_SUMMARY_NEEDED;
74 }
75 return $statusValue;
76 }
77
78}
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:81
For a new section, do not allow the user to post with an empty subject (section title) unless they ch...
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.
Interface for all constraints that can prevent edits.