MediaWiki master
NewSectionMissingSubjectConstraint.php
Go to the documentation of this file.
1<?php
22
23use StatusValue;
24
33
34 private string $section;
35 private string $subject;
36 private bool $allowBlankSubject;
37 private string $result;
38
44 public function __construct(
45 string $section,
46 string $subject,
47 bool $allowBlankSubject
48 ) {
49 $this->section = $section;
50 $this->subject = $subject;
51 $this->allowBlankSubject = $allowBlankSubject;
52 }
53
54 public function checkConstraint(): string {
55 if ( $this->section === 'new' &&
56 !$this->allowBlankSubject &&
57 trim( $this->subject ) === ''
58 ) {
59 $this->result = self::CONSTRAINT_FAILED;
60 } else {
61 $this->result = self::CONSTRAINT_PASSED;
62 }
63 return $this->result;
64 }
65
66 public function getLegacyStatus(): StatusValue {
67 $statusValue = StatusValue::newGood();
68 if ( $this->result === self::CONSTRAINT_FAILED ) {
69 // From EditPage, regarding the fatal:
70 // or 'missingcommentheader' if $section === 'new'. Blegh
71 // For new sections, the subject is also used for the summary,
72 // so we report missing summaries if the section is missing
73 $statusValue->fatal( 'missingsummary' );
74 $statusValue->value = self::AS_SUMMARY_NEEDED;
75 }
76 return $statusValue;
77 }
78
79}
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...
__construct(string $section, string $subject, bool $allowBlankSubject)
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.