| 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 ChangeTags; |
| 24 |
use MediaWiki\Permissions\Authority; |
| 25 |
use StatusValue; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
class ChangeTagsConstraint implements IEditConstraint { |
| 35 |
|
| 36 |
private Authority $performer; |
| 37 |
|
| 38 |
private $tags; |
| 39 |
|
| 40 |
private $result; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
public function __construct( |
| 47 |
Authority $performer, |
| 48 |
array $tags |
| 49 |
) { |
| 50 |
$this->performer = $performer; |
| 51 |
$this->tags = $tags; |
| 52 |
} |
| 53 |
|
| 54 |
public function checkConstraint(): string { |
| 55 |
if ( !$this->tags ) { |
| 56 |
$this->result = self::CONSTRAINT_PASSED; |
| 57 |
return self::CONSTRAINT_PASSED; |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
$changeTagStatus = ChangeTags::canAddTagsAccompanyingChange( |
| 63 |
$this->tags, |
| 64 |
$this->performer, |
| 65 |
false |
| 66 |
); |
| 67 |
|
| 68 |
if ( $changeTagStatus->isOK() ) { |
| 69 |
$this->result = self::CONSTRAINT_PASSED; |
| 70 |
return self::CONSTRAINT_PASSED; |
| 71 |
} |
| 72 |
|
| 73 |
$this->result = $changeTagStatus; |
| 74 |
return self::CONSTRAINT_FAILED; |
| 75 |
} |
| 76 |
|
| 77 |
public function getLegacyStatus(): StatusValue { |
| 78 |
if ( $this->result === self::CONSTRAINT_PASSED ) { |
| 79 |
$statusValue = StatusValue::newGood(); |
| 80 |
} else { |
| 81 |
$statusValue = $this->result; |
| 82 |
$statusValue->value = self::AS_CHANGE_TAG_ERROR; |
| 83 |
} |
| 84 |
return $statusValue; |
| 85 |
} |
| 86 |
|
| 87 |
} |