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 | private Title $title; |
38 | private bool $allowBlank; |
39 | private string $userProvidedText; |
40 | private string $result; |
41 | |
42 | /** |
43 | * @param Title $title |
44 | * @param bool $allowBlank |
45 | * @param string $userProvidedText |
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 | } |