Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
16 / 16 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
DefaultTextConstraint | |
100.00% |
16 / 16 |
|
100.00% |
3 / 3 |
8 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
checkConstraint | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
5 | |||
getLegacyStatus | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | */ |
20 | |
21 | namespace MediaWiki\EditPage\Constraint; |
22 | |
23 | use MediaWiki\Title\Title; |
24 | use StatusValue; |
25 | |
26 | /** |
27 | * Don't save a new page if it's blank or if it's a MediaWiki: |
28 | * message with content equivalent to default (allow empty pages |
29 | * in this case to disable messages, see T52124) |
30 | * |
31 | * @since 1.36 |
32 | * @internal |
33 | * @author DannyS712 |
34 | */ |
35 | class DefaultTextConstraint implements IEditConstraint { |
36 | |
37 | /** @var Title */ |
38 | private $title; |
39 | |
40 | /** @var bool */ |
41 | private $allowBlank; |
42 | |
43 | /** @var string */ |
44 | private $userProvidedText; |
45 | |
46 | /** @var string|null */ |
47 | private $result; |
48 | |
49 | /** |
50 | * @param Title $title |
51 | * @param bool $allowBlank |
52 | * @param string $userProvidedText |
53 | */ |
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 | } |