MediaWiki master
DefaultTextConstraint.php
Go to the documentation of this file.
1<?php
22
24use StatusValue;
25
36
37 private Title $title;
38 private bool $allowBlank;
39 private string $userProvidedText;
40 private string $result;
41
47 public function __construct(
48 Title $title,
49 bool $allowBlank,
50 string $userProvidedText
51 ) {
52 $this->title = $title;
53 $this->allowBlank = $allowBlank;
54 $this->userProvidedText = $userProvidedText;
55 }
56
57 public function checkConstraint(): string {
58 $defaultMessageText = $this->title->getDefaultMessageText();
59 if ( $this->title->getNamespace() === NS_MEDIAWIKI && $defaultMessageText !== false ) {
60 $defaultText = $defaultMessageText;
61 } else {
62 $defaultText = '';
63 }
64
65 if ( !$this->allowBlank && $this->userProvidedText === $defaultText ) {
66 $this->result = self::CONSTRAINT_FAILED;
67 } else {
68 $this->result = self::CONSTRAINT_PASSED;
69 }
70 return $this->result;
71 }
72
73 public function getLegacyStatus(): StatusValue {
74 $statusValue = StatusValue::newGood();
75 if ( $this->result === self::CONSTRAINT_FAILED ) {
76 $statusValue->fatal( 'blankarticle' );
77 $statusValue->setResult( false, self::AS_BLANK_ARTICLE );
78 }
79 return $statusValue;
80 }
81
82}
const NS_MEDIAWIKI
Definition Defines.php:73
Don't save a new page if it's blank or if it's a MediaWiki: message with content equivalent to defaul...
getLegacyStatus()
Get the legacy status for failure (or success)
__construct(Title $title, bool $allowBlank, string $userProvidedText)
Represents a title within MediaWiki.
Definition Title.php:79
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.