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(
50  Authority $performer,
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  false
69  );
70 
71  if ( $changeTagStatus->isOK() ) {
72  $this->result = self::CONSTRAINT_PASSED;
73  return self::CONSTRAINT_PASSED;
74  }
75 
76  $this->result = $changeTagStatus; // The same status object is returned
77  return self::CONSTRAINT_FAILED;
78  }
79 
80  public function getLegacyStatus(): StatusValue {
81  if ( $this->result === self::CONSTRAINT_PASSED ) {
82  $statusValue = StatusValue::newGood();
83  } else {
84  $statusValue = $this->result;
85  $statusValue->value = self::AS_CHANGE_TAG_ERROR;
86  }
87  return $statusValue;
88  }
89 
90 }
if(!defined('MW_SETUP_CALLBACK'))
Definition: WebStart.php:88
static canAddTagsAccompanyingChange(array $tags, Authority $performer=null, $checkBlock=true)
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:396
getLegacyStatus()
Get the legacy status for failure (or success)
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: StatusValue.php:46
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:85
Interface for all constraints that can prevent edits.
This interface represents the authority associated the current execution context, such as a web reque...
Definition: Authority.php:37