Debian Codegraph @

includes/Permissions/UltimateAuthority.php

raw symbols SCIP
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\Permissions;
22
23 use InvalidArgumentException;
24 use MediaWiki\Block\Block;
25 use MediaWiki\Page\PageIdentity;
26 use MediaWiki\User\UserIdentity;
27 use Wikimedia\Rdbms\IDBAccessObject;
28
29 /**
30 * Represents an authority that has all permissions.
31 * This is intended for use in maintenance scripts and tests.
32 *
33 * @newable
34 * @since 1.36
35 */
36 class UltimateAuthority implements Authority {
37
38 /** @var UserIdentity */
39 private $actor;
40
41 /** @var bool */
42 private $isTemp;
43
44 /**
45 * @stable to call
46 * @param UserIdentity $actor
47 * @param bool $isTemp
48 */
49 public function __construct( UserIdentity $actor, $isTemp = false ) {
50 $this->actor = $actor;
51 $this->isTemp = $isTemp;
52 }
53
54 /** @inheritDoc */
55 public function getUser(): UserIdentity {
56 return $this->actor;
57 }
58
59 /** @inheritDoc */
60 public function getBlock( int $freshness = IDBAccessObject::READ_NORMAL ): ?Block {
61 return null;
62 }
63
64 /** @inheritDoc */
65 public function isAllowed( string $permission, ?PermissionStatus $status = null ): bool {
66 return true;
67 }
68
69 /** @inheritDoc */
70 public function isAllowedAny( ...$permissions ): bool {
71 if ( !$permissions ) {
72 throw new InvalidArgumentException( 'At least one permission must be specified' );
73 }
74
75 return true;
76 }
77
78 /** @inheritDoc */
79 public function isAllowedAll( ...$permissions ): bool {
80 if ( !$permissions ) {
81 throw new InvalidArgumentException( 'At least one permission must be specified' );
82 }
83
84 return true;
85 }
86
87 /** @inheritDoc */
88 public function probablyCan(
89 string $action,
90 PageIdentity $target,
91 ?PermissionStatus $status = null
92 ): bool {
93 return true;
94 }
95
96 /** @inheritDoc */
97 public function definitelyCan(
98 string $action,
99 PageIdentity $target,
100 ?PermissionStatus $status = null
101 ): bool {
102 return true;
103 }
104
105 /** @inheritDoc */
106 public function isDefinitelyAllowed( string $action, ?PermissionStatus $status = null ): bool {
107 return true;
108 }
109
110 /** @inheritDoc */
111 public function authorizeAction( string $action, ?PermissionStatus $status = null ): bool {
112 return true;
113 }
114
115 /** @inheritDoc */
116 public function authorizeRead(
117 string $action,
118 PageIdentity $target,
119 ?PermissionStatus $status = null
120 ): bool {
121 return true;
122 }
123
124 /** @inheritDoc */
125 public function authorizeWrite(
126 string $action,
127 PageIdentity $target,
128 ?PermissionStatus $status = null
129 ): bool {
130 return true;
131 }
132
133 public function isRegistered(): bool {
134 return $this->actor->isRegistered();
135 }
136
137 public function isTemp(): bool {
138 return $this->isTemp;
139 }
140
141 public function isNamed(): bool {
142 return $this->isRegistered() && !$this->isTemp();
143 }
144 }