| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\EditPage\Constraint; |
| 22 |
|
| 23 |
use MediaWiki\Title\Title; |
| 24 |
use StatusValue; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
class DefaultTextConstraint implements IEditConstraint { |
| 36 |
|
| 37 |
private Title $title; |
| 38 |
private bool $allowBlank; |
| 39 |
private string $userProvidedText; |
| 40 |
private string $result; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 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 |
} |