Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
14 / 14 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
NewSectionMissingSubjectConstraint | |
100.00% |
14 / 14 |
|
100.00% |
3 / 3 |
7 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
checkConstraint | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
4 | |||
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 StatusValue; |
24 | |
25 | /** |
26 | * For a new section, do not allow the user to post with an empty subject (section title) unless they choose to |
27 | * |
28 | * @since 1.39 |
29 | * @internal |
30 | * @author DannyS712 |
31 | */ |
32 | class NewSectionMissingSubjectConstraint implements IEditConstraint { |
33 | |
34 | private string $section; |
35 | private string $subject; |
36 | private bool $allowBlankSubject; |
37 | private string $result; |
38 | |
39 | /** |
40 | * @param string $section |
41 | * @param string $subject |
42 | * @param bool $allowBlankSubject |
43 | */ |
44 | public function __construct( |
45 | string $section, |
46 | string $subject, |
47 | bool $allowBlankSubject |
48 | ) { |
49 | $this->section = $section; |
50 | $this->subject = $subject; |
51 | $this->allowBlankSubject = $allowBlankSubject; |
52 | } |
53 | |
54 | public function checkConstraint(): string { |
55 | if ( $this->section === 'new' && |
56 | !$this->allowBlankSubject && |
57 | trim( $this->subject ) === '' |
58 | ) { |
59 | $this->result = self::CONSTRAINT_FAILED; |
60 | } else { |
61 | $this->result = self::CONSTRAINT_PASSED; |
62 | } |
63 | return $this->result; |
64 | } |
65 | |
66 | public function getLegacyStatus(): StatusValue { |
67 | $statusValue = StatusValue::newGood(); |
68 | if ( $this->result === self::CONSTRAINT_FAILED ) { |
69 | // From EditPage, regarding the fatal: |
70 | // or 'missingcommentheader' if $section === 'new'. Blegh |
71 | // For new sections, the subject is also used for the summary, |
72 | // so we report missing summaries if the section is missing |
73 | $statusValue->fatal( 'missingsummary' ); |
74 | $statusValue->value = self::AS_SUMMARY_NEEDED; |
75 | } |
76 | return $statusValue; |
77 | } |
78 | |
79 | } |