Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
17 / 17 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
AutoSummaryMissingSummaryConstraint | |
100.00% |
17 / 17 |
|
100.00% |
3 / 3 |
8 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
checkConstraint | |
100.00% |
7 / 7 |
|
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 Content; |
24 | use StatusValue; |
25 | |
26 | /** |
27 | * For an edit to an existing page but not with a new section, do not allow the user to post with |
28 | * a summary that matches the automatic summary if |
29 | * - the content has changed (to allow null edits without a summary, see T7365), |
30 | * - the new content is not a redirect (since redirecting a page has an informative automatic |
31 | * edit summary, see T9889), and |
32 | * - the user has not explicitly chosen to allow the automatic summary to be used |
33 | * |
34 | * For most edits, the automatic summary is blank, so checking against the automatic summary means |
35 | * checking that any summary was given. |
36 | * |
37 | * @since 1.36 |
38 | * @internal |
39 | * @author DannyS712 |
40 | */ |
41 | class AutoSummaryMissingSummaryConstraint implements IEditConstraint { |
42 | |
43 | /** @var string */ |
44 | private $userSummary; |
45 | |
46 | /** @var string */ |
47 | private $autoSummary; |
48 | |
49 | /** @var bool */ |
50 | private $allowBlankSummary; |
51 | |
52 | /** @var Content */ |
53 | private $newContent; |
54 | |
55 | /** @var Content */ |
56 | private $originalContent; |
57 | |
58 | /** @var string|null */ |
59 | private $result; |
60 | |
61 | /** |
62 | * @param string $userSummary |
63 | * @param string $autoSummary |
64 | * @param bool $allowBlankSummary |
65 | * @param Content $newContent |
66 | * @param Content $originalContent |
67 | */ |
68 | public function __construct( |
69 | string $userSummary, |
70 | string $autoSummary, |
71 | bool $allowBlankSummary, |
72 | Content $newContent, |
73 | Content $originalContent |
74 | ) { |
75 | $this->userSummary = $userSummary; |
76 | $this->autoSummary = $autoSummary; |
77 | $this->allowBlankSummary = $allowBlankSummary; |
78 | $this->newContent = $newContent; |
79 | $this->originalContent = $originalContent; |
80 | } |
81 | |
82 | public function checkConstraint(): string { |
83 | if ( |
84 | !$this->allowBlankSummary && |
85 | !$this->newContent->equals( $this->originalContent ) && |
86 | !$this->newContent->isRedirect() && |
87 | md5( $this->userSummary ) == $this->autoSummary |
88 | ) { |
89 | // TODO this was == in EditPage, can it be === ? |
90 | $this->result = self::CONSTRAINT_FAILED; |
91 | } else { |
92 | $this->result = self::CONSTRAINT_PASSED; |
93 | } |
94 | return $this->result; |
95 | } |
96 | |
97 | public function getLegacyStatus(): StatusValue { |
98 | $statusValue = StatusValue::newGood(); |
99 | if ( $this->result === self::CONSTRAINT_FAILED ) { |
100 | $statusValue->fatal( 'missingsummary' ); |
101 | $statusValue->value = self::AS_SUMMARY_NEEDED; |
102 | } |
103 | return $statusValue; |
104 | } |
105 | |
106 | } |