Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
UserBlockConstraint
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
3 / 3
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 checkConstraint
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
 getLegacyStatus
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
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
21namespace MediaWiki\EditPage\Constraint;
22
23use MediaWiki\Linker\LinkTarget;
24use MediaWiki\Permissions\PermissionManager;
25use MediaWiki\User\User;
26use 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 */
36class UserBlockConstraint implements IEditConstraint {
37
38    /** @var PermissionManager */
39    private $permissionManager;
40
41    /** @var LinkTarget */
42    private $title;
43
44    /** @var User */
45    private $user;
46
47    /** @var string|null */
48    private $result;
49
50    /**
51     * @param PermissionManager $permissionManager
52     * @param LinkTarget $title
53     * @param User $user
54     */
55    public function __construct(
56        PermissionManager $permissionManager,
57        LinkTarget $title,
58        User $user
59    ) {
60        $this->permissionManager = $permissionManager;
61        $this->title = $title;
62        $this->user = $user;
63    }
64
65    public function checkConstraint(): string {
66        // Check isn't simple enough to just repeat when getting the status
67        if ( $this->permissionManager->isBlockedFrom( $this->user, $this->title ) ) {
68            $this->result = self::CONSTRAINT_FAILED;
69            return self::CONSTRAINT_FAILED;
70        }
71
72        $this->result = self::CONSTRAINT_PASSED;
73        return self::CONSTRAINT_PASSED;
74    }
75
76    public function getLegacyStatus(): StatusValue {
77        $statusValue = StatusValue::newGood();
78
79        if ( $this->result === self::CONSTRAINT_FAILED ) {
80            $statusValue->setResult( false, self::AS_BLOCKED_PAGE_FOR_USER );
81        }
82
83        return $statusValue;
84    }
85
86}