MediaWiki REL1_40
DefaultTextConstraint.php
Go to the documentation of this file.
1<?php
22
24use StatusValue;
25
36
38 private $title;
39
41 private $allowBlank;
42
44 private $userProvidedText;
45
47 private $result;
48
54 public function __construct(
55 Title $title,
56 bool $allowBlank,
57 string $userProvidedText
58 ) {
59 $this->title = $title;
60 $this->allowBlank = $allowBlank;
61 $this->userProvidedText = $userProvidedText;
62 }
63
64 public function checkConstraint(): string {
65 $defaultMessageText = $this->title->getDefaultMessageText();
66 if ( $this->title->getNamespace() === NS_MEDIAWIKI && $defaultMessageText !== false ) {
67 $defaultText = $defaultMessageText;
68 } else {
69 $defaultText = '';
70 }
71
72 if ( !$this->allowBlank && $this->userProvidedText === $defaultText ) {
73 $this->result = self::CONSTRAINT_FAILED;
74 } else {
75 $this->result = self::CONSTRAINT_PASSED;
76 }
77 return $this->result;
78 }
79
80 public function getLegacyStatus(): StatusValue {
81 $statusValue = StatusValue::newGood();
82 if ( $this->result === self::CONSTRAINT_FAILED ) {
83 $statusValue->fatal( 'blankarticle' );
84 $statusValue->setResult( false, self::AS_BLANK_ARTICLE );
85 }
86 return $statusValue;
87 }
88
89}
const NS_MEDIAWIKI
Definition Defines.php:72
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:82
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.