Debian Codegraph @

includes/editpage/Constraint/UserBlockConstraint.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\EditPage\Constraint;
22
23 use MediaWiki\Linker\LinkTarget;
24 use MediaWiki\Permissions\PermissionManager;
25 use MediaWiki\User\User;
26 use StatusValue;
27
28 /**
29 * Verify user permissions:
30 * Must not be blocked from the page
31 *
32 * @since 1.36
33 * @internal
34 * @author DannyS712
35 */
36 class UserBlockConstraint implements IEditConstraint {
37
38 private PermissionManager $permissionManager;
39 private LinkTarget $title;
40 private User $user;
41 private string $result;
42
43 /**
44 * @param PermissionManager $permissionManager
45 * @param LinkTarget $title
46 * @param User $user
47 */
48 public function __construct(
49 PermissionManager $permissionManager,
50 LinkTarget $title,
51 User $user
52 ) {
53 $this->permissionManager = $permissionManager;
54 $this->title = $title;
55 $this->user = $user;
56 }
57
58 public function checkConstraint(): string {
59 // Check isn't simple enough to just repeat when getting the status
60 if ( $this->permissionManager->isBlockedFrom( $this->user, $this->title ) ) {
61 $this->result = self::CONSTRAINT_FAILED;
62 return self::CONSTRAINT_FAILED;
63 }
64
65 $this->result = self::CONSTRAINT_PASSED;
66 return self::CONSTRAINT_PASSED;
67 }
68
69 public function getLegacyStatus(): StatusValue {
70 $statusValue = StatusValue::newGood();
71
72 if ( $this->result === self::CONSTRAINT_FAILED ) {
73 $statusValue->setResult( false, self::AS_BLOCKED_PAGE_FOR_USER );
74 }
75
76 return $statusValue;
77 }
78
79 }