Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
10 / 10 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
ActionInfo | |
100.00% |
10 / 10 |
|
100.00% |
6 / 6 |
6 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
getName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getRestriction | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
needsReadRights | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
requiresWrite | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
requiresUnblock | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
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 |
14 | * along with this program; if not, write to the Free Software |
15 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
16 | * |
17 | * @file |
18 | */ |
19 | |
20 | namespace MediaWiki\Actions; |
21 | |
22 | /** |
23 | * Provides information about an action that can be used to determine whether the action |
24 | * can be executed in a given context. |
25 | * |
26 | * @since 1.41 |
27 | * @author Daniel Kinzler |
28 | */ |
29 | class ActionInfo { |
30 | |
31 | private string $name; |
32 | private ?string $restriction; |
33 | private bool $needsReadRights; |
34 | private bool $requiresWrite; |
35 | private bool $requiresUnblock; |
36 | |
37 | /** |
38 | * Constructs ActionInfo based on an action object spec which is expected to |
39 | * include the following keys: |
40 | * - name: the canonical name of the action (string) |
41 | * - requiresUnblock: Whether this action can still be executed by a blocked user (bool) |
42 | * - requiresWrite: Whether this action requires the wiki not to be locked (bool) |
43 | * - needsReadRights: whether this action requires read rights (bool) |
44 | * - restriction: the permission required to perform this action (string, or null for none) |
45 | * |
46 | * @param array $spec The action spec |
47 | */ |
48 | public function __construct( array $spec ) { |
49 | $this->name = $spec['name']; |
50 | $this->restriction = $spec['restriction']; |
51 | $this->needsReadRights = $spec['needsReadRights']; |
52 | $this->requiresWrite = $spec['requiresWrite']; |
53 | $this->requiresUnblock = $spec['requiresUnblock']; |
54 | } |
55 | |
56 | /** |
57 | * @return string The action's name |
58 | */ |
59 | public function getName(): string { |
60 | return $this->name; |
61 | } |
62 | |
63 | /** |
64 | * @return ?string A permission required to execute the action |
65 | */ |
66 | public function getRestriction(): ?string { |
67 | return $this->restriction; |
68 | } |
69 | |
70 | /** |
71 | * @return bool Whether the action requires the user to have read access |
72 | */ |
73 | public function needsReadRights(): bool { |
74 | return $this->needsReadRights; |
75 | } |
76 | |
77 | /** |
78 | * @return bool Whether the action requires the database to be writable |
79 | */ |
80 | public function requiresWrite(): bool { |
81 | return $this->requiresWrite; |
82 | } |
83 | |
84 | /** |
85 | * @return bool Whether the action requires the user to not be blocked |
86 | */ |
87 | public function requiresUnblock(): bool { |
88 | return $this->requiresUnblock; |
89 | } |
90 | |
91 | } |