MediaWiki  master
ImageRedirectConstraint.php
Go to the documentation of this file.
1 <?php
22 
23 use Content;
26 use StatusValue;
27 
37 
39  private $newContent;
40 
42  private $title;
43 
45  private $performer;
46 
48  private $result;
49 
55  public function __construct(
59  ) {
60  $this->newContent = $newContent;
61  $this->title = $title;
62  $this->performer = $performer;
63  }
64 
65  public function checkConstraint(): string {
66  // Check isn't simple enough to just repeat when getting the status
67  if ( $this->title->getNamespace() === NS_FILE &&
68  $this->newContent->isRedirect() &&
69  !$this->performer->isAllowed( 'upload' )
70  ) {
71  $this->result = self::CONSTRAINT_FAILED;
72  return self::CONSTRAINT_FAILED;
73  }
74 
75  $this->result = self::CONSTRAINT_PASSED;
76  return self::CONSTRAINT_PASSED;
77  }
78 
79  public function getLegacyStatus(): StatusValue {
80  $statusValue = StatusValue::newGood();
81 
82  if ( $this->result === self::CONSTRAINT_FAILED ) {
83  $errorCode = $this->performer->getUser()->isRegistered() ?
86  $statusValue->setResult( false, $errorCode );
87  }
88 
89  return $statusValue;
90  }
91 
92 }
StatusValue
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: StatusValue.php:43
MediaWiki\EditPage\Constraint\ImageRedirectConstraint\$newContent
Content $newContent
Definition: ImageRedirectConstraint.php:39
MediaWiki\EditPage\Constraint\ImageRedirectConstraint\__construct
__construct(Content $newContent, LinkTarget $title, Authority $performer)
Definition: ImageRedirectConstraint.php:55
MediaWiki\EditPage\Constraint\ImageRedirectConstraint\$performer
Authority $performer
Definition: ImageRedirectConstraint.php:45
MediaWiki\EditPage\Constraint\ImageRedirectConstraint\$title
LinkTarget $title
Definition: ImageRedirectConstraint.php:42
MediaWiki\EditPage\Constraint\ImageRedirectConstraint\checkConstraint
checkConstraint()
Definition: ImageRedirectConstraint.php:65
MediaWiki\EditPage\Constraint\ImageRedirectConstraint\getLegacyStatus
getLegacyStatus()
Get the legacy status for failure (or success)
Definition: ImageRedirectConstraint.php:79
MediaWiki\EditPage\Constraint\ImageRedirectConstraint
Verify user permissions: If creating a redirect in the file namespace, must have upload rights.
Definition: ImageRedirectConstraint.php:36
MediaWiki\Permissions\Authority
This interface represents the authority associated the current execution context, such as a web reque...
Definition: Authority.php:37
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:82
MediaWiki\EditPage\IEditObject\AS_IMAGE_REDIRECT_ANON
const AS_IMAGE_REDIRECT_ANON
Status: anonymous user is not allowed to upload (User::isAllowed('upload') == false)
Definition: IEditObject.php:92
Content
Base interface for content objects.
Definition: Content.php:35
MediaWiki\EditPage\IEditObject\AS_IMAGE_REDIRECT_LOGGED
const AS_IMAGE_REDIRECT_LOGGED
Status: logged in user is not allowed to upload (User::isAllowed('upload') == false)
Definition: IEditObject.php:95
MediaWiki\EditPage\Constraint\ImageRedirectConstraint\$result
string null $result
Definition: ImageRedirectConstraint.php:48
MediaWiki\EditPage\Constraint
Definition: AccidentalRecreationConstraint.php:21
NS_FILE
const NS_FILE
Definition: Defines.php:70
MediaWiki\Linker\LinkTarget
Definition: LinkTarget.php:26
MediaWiki\EditPage\Constraint\IEditConstraint
Interface for all constraints that can prevent edits.
Definition: IEditConstraint.php:33