| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\EditPage\Constraint; |
| 22 |
|
| 23 |
use MediaWiki\Permissions\PermissionManager; |
| 24 |
use MediaWiki\Title\Title; |
| 25 |
use MediaWiki\User\User; |
| 26 |
use StatusValue; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
class EditRightConstraint implements IEditConstraint { |
| 37 |
|
| 38 |
private User $performer; |
| 39 |
private PermissionManager $permManager; |
| 40 |
private Title $title; |
| 41 |
private string $result; |
| 42 |
private bool $new; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
public function __construct( |
| 51 |
User $performer, |
| 52 |
PermissionManager $permManager, |
| 53 |
Title $title, |
| 54 |
bool $new |
| 55 |
) { |
| 56 |
$this->performer = $performer; |
| 57 |
$this->permManager = $permManager; |
| 58 |
$this->title = $title; |
| 59 |
$this->new = $new; |
| 60 |
} |
| 61 |
|
| 62 |
public function checkConstraint(): string { |
| 63 |
if ( $this->new ) { |
| 64 |
|
| 65 |
if ( !$this->performer->authorizeWrite( 'create', $this->title ) ) { |
| 66 |
$this->result = (string)self::AS_NO_CREATE_PERMISSION; |
| 67 |
return self::CONSTRAINT_FAILED; |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
if ( !$this->permManager->userCan( |
| 75 |
'edit', |
| 76 |
$this->performer, |
| 77 |
$this->title |
| 78 |
) ) { |
| 79 |
$this->result = self::CONSTRAINT_FAILED; |
| 80 |
return self::CONSTRAINT_FAILED; |
| 81 |
} |
| 82 |
|
| 83 |
$this->result = self::CONSTRAINT_PASSED; |
| 84 |
return self::CONSTRAINT_PASSED; |
| 85 |
} |
| 86 |
|
| 87 |
public function getLegacyStatus(): StatusValue { |
| 88 |
$statusValue = StatusValue::newGood(); |
| 89 |
|
| 90 |
if ( $this->result === self::CONSTRAINT_FAILED ) { |
| 91 |
if ( !$this->performer->isRegistered() ) { |
| 92 |
$statusValue->setResult( false, self::AS_READ_ONLY_PAGE_ANON ); |
| 93 |
} else { |
| 94 |
$statusValue->fatal( 'readonlytext' ); |
| 95 |
$statusValue->value = self::AS_READ_ONLY_PAGE_LOGGED; |
| 96 |
} |
| 97 |
} elseif ( $this->result === (string)self::AS_NO_CREATE_PERMISSION ) { |
| 98 |
$statusValue->fatal( 'nocreatetext' ); |
| 99 |
$statusValue->value = self::AS_NO_CREATE_PERMISSION; |
| 100 |
} |
| 101 |
|
| 102 |
return $statusValue; |
| 103 |
} |
| 104 |
|
| 105 |
} |