MediaWiki master
ChangeTagsConstraint.php
Go to the documentation of this file.
1<?php
22
23use ChangeTags;
25use StatusValue;
26
35
36 private Authority $performer;
38 private $tags;
40 private $result;
41
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 // TODO inject a service once canAddTagsAccompanyingChange is moved to a
61 // service as part of T245964
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; // The same status object is returned
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}
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:81
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...
getLegacyStatus()
Get the legacy status for failure (or success)
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Interface for all constraints that can prevent edits.
This interface represents the authority associated with the current execution context,...
Definition Authority.php:37