MediaWiki REL1_39
ImageRedirectConstraint.php
Go to the documentation of this file.
1<?php
22
23use Content;
26use 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'))
The persistent session ID (if any) loaded at startup.
Definition WebStart.php:82
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.
setResult( $ok, $value=null)
Change operation result.
Base interface for content objects.
Definition Content.php:35
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