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(
56  Content $newContent,
57  LinkTarget $title,
58  Authority $performer
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() ?
84  self::AS_IMAGE_REDIRECT_LOGGED :
85  self::AS_IMAGE_REDIRECT_ANON;
86  $statusValue->setResult( false, $errorCode );
87  }
88 
89  return $statusValue;
90  }
91 
92 }
const NS_FILE
Definition: Defines.php:70
if(!defined('MW_SETUP_CALLBACK'))
Definition: WebStart.php:88
Verify user permissions: If creating a redirect in the file namespace, must have upload rights.
__construct(Content $newContent, LinkTarget $title, Authority $performer)
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
setResult( $ok, $value=null)
Change operation result.
Base interface for representing page content.
Definition: Content.php:39
Interface for all constraints that can prevent edits.
Represents the target of a wiki link.
Definition: LinkTarget.php:30
This interface represents the authority associated the current execution context, such as a web reque...
Definition: Authority.php:37