Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
20 / 20 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
ChangeTagsConstraint | |
100.00% |
20 / 20 |
|
100.00% |
3 / 3 |
6 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
checkConstraint | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
3 | |||
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 ChangeTags; |
24 | use MediaWiki\Permissions\Authority; |
25 | use StatusValue; |
26 | |
27 | /** |
28 | * Verify user can add change tags |
29 | * |
30 | * @since 1.36 |
31 | * @internal |
32 | * @author DannyS712 |
33 | */ |
34 | class ChangeTagsConstraint implements IEditConstraint { |
35 | |
36 | /** @var Authority */ |
37 | private $performer; |
38 | |
39 | /** @var array */ |
40 | private $tags; |
41 | |
42 | /** @var StatusValue|string */ |
43 | private $result; |
44 | |
45 | /** |
46 | * @param Authority $performer |
47 | * @param string[] $tags |
48 | */ |
49 | public function __construct( |
50 | Authority $performer, |
51 | array $tags |
52 | ) { |
53 | $this->performer = $performer; |
54 | $this->tags = $tags; |
55 | } |
56 | |
57 | public function checkConstraint(): string { |
58 | if ( !$this->tags ) { |
59 | $this->result = self::CONSTRAINT_PASSED; |
60 | return self::CONSTRAINT_PASSED; |
61 | } |
62 | |
63 | // TODO inject a service once canAddTagsAccompanyingChange is moved to a |
64 | // service as part of T245964 |
65 | $changeTagStatus = ChangeTags::canAddTagsAccompanyingChange( |
66 | $this->tags, |
67 | $this->performer, |
68 | false |
69 | ); |
70 | |
71 | if ( $changeTagStatus->isOK() ) { |
72 | $this->result = self::CONSTRAINT_PASSED; |
73 | return self::CONSTRAINT_PASSED; |
74 | } |
75 | |
76 | $this->result = $changeTagStatus; // The same status object is returned |
77 | return self::CONSTRAINT_FAILED; |
78 | } |
79 | |
80 | public function getLegacyStatus(): StatusValue { |
81 | if ( $this->result === self::CONSTRAINT_PASSED ) { |
82 | $statusValue = StatusValue::newGood(); |
83 | } else { |
84 | $statusValue = $this->result; |
85 | $statusValue->value = self::AS_CHANGE_TAG_ERROR; |
86 | } |
87 | return $statusValue; |
88 | } |
89 | |
90 | } |