MediaWiki  master
ChangeTagsConstraint.php
Go to the documentation of this file.
1 <?php
22 
23 use ChangeTags;
25 use StatusValue;
26 
35 
37  private $performer;
38 
40  private $tags;
41 
43  private $result;
44 
49  public function __construct(
51  array $tags
52  ) {
53  $this->performer = $performer;
54  $this->tags = $tags;
55  }
56 
57  public function checkConstraint(): string {
58  if ( !$this->tags ) {
59  $this->result = self::CONSTRAINT_PASSED;
60  return self::CONSTRAINT_PASSED;
61  }
62 
63  // TODO inject a service once canAddTagsAccompanyingChange is moved to a
64  // service as part of T245964
66  $this->tags,
67  $this->performer
68  );
69 
70  if ( $changeTagStatus->isOK() ) {
71  $this->result = self::CONSTRAINT_PASSED;
72  return self::CONSTRAINT_PASSED;
73  }
74 
75  $this->result = $changeTagStatus; // The same status object is returned
76  return self::CONSTRAINT_FAILED;
77  }
78 
79  public function getLegacyStatus(): StatusValue {
80  if ( $this->result === self::CONSTRAINT_PASSED ) {
81  $statusValue = StatusValue::newGood();
82  } else {
83  $statusValue = $this->result;
84  $statusValue->value = self::AS_CHANGE_TAG_ERROR;
85  }
86  return $statusValue;
87  }
88 
89 }
StatusValue
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: StatusValue.php:43
MediaWiki\EditPage\Constraint\ChangeTagsConstraint\getLegacyStatus
getLegacyStatus()
Get the legacy status for failure (or success)
Definition: ChangeTagsConstraint.php:79
MediaWiki\EditPage\Constraint\ChangeTagsConstraint\__construct
__construct(Authority $performer, array $tags)
Definition: ChangeTagsConstraint.php:49
MediaWiki\EditPage\Constraint\ChangeTagsConstraint\$performer
Authority $performer
Definition: ChangeTagsConstraint.php:37
ChangeTags
Definition: ChangeTags.php:32
MediaWiki\EditPage\Constraint\ChangeTagsConstraint\$tags
array $tags
Definition: ChangeTagsConstraint.php:40
MediaWiki\EditPage\Constraint\ChangeTagsConstraint\checkConstraint
checkConstraint()
Definition: ChangeTagsConstraint.php:57
MediaWiki\Permissions\Authority
This interface represents the authority associated the current execution context, such as a web reque...
Definition: Authority.php:37
ChangeTags\canAddTagsAccompanyingChange
static canAddTagsAccompanyingChange(array $tags, Authority $performer=null)
Is it OK to allow the user to apply all the specified tags at the same time as they edit/make the cha...
Definition: ChangeTags.php:630
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:82
MediaWiki\EditPage\Constraint\ChangeTagsConstraint\$result
StatusValue string null $result
Definition: ChangeTagsConstraint.php:43
MediaWiki\EditPage\Constraint\ChangeTagsConstraint
Verify user can add change tags.
Definition: ChangeTagsConstraint.php:34
MediaWiki\EditPage\Constraint
Definition: AccidentalRecreationConstraint.php:21
MediaWiki\EditPage\IEditObject\AS_CHANGE_TAG_ERROR
const AS_CHANGE_TAG_ERROR
Status: an error relating to change tagging.
Definition: IEditObject.php:107
MediaWiki\EditPage\Constraint\IEditConstraint
Interface for all constraints that can prevent edits.
Definition: IEditConstraint.php:33