MediaWiki
1.39.10
ImageRedirectConstraint.php
Go to the documentation of this file.
1
<?php
21
namespace
MediaWiki\EditPage\Constraint
;
22
23
use
Content
;
24
use
MediaWiki\Linker\LinkTarget
;
25
use
MediaWiki\Permissions\Authority
;
26
use
StatusValue
;
27
36
class
ImageRedirectConstraint
implements
IEditConstraint
{
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
}
NS_FILE
const NS_FILE
Definition
Defines.php:70
if
if(!defined('MW_SETUP_CALLBACK'))
The persistent session ID (if any) loaded at startup.
Definition
WebStart.php:82
MediaWiki\EditPage\Constraint\ImageRedirectConstraint
Verify user permissions: If creating a redirect in the file namespace, must have upload rights.
Definition
ImageRedirectConstraint.php:36
MediaWiki\EditPage\Constraint\ImageRedirectConstraint\checkConstraint
checkConstraint()
Definition
ImageRedirectConstraint.php:65
MediaWiki\EditPage\Constraint\ImageRedirectConstraint\__construct
__construct(Content $newContent, LinkTarget $title, Authority $performer)
Definition
ImageRedirectConstraint.php:55
MediaWiki\EditPage\Constraint\ImageRedirectConstraint\getLegacyStatus
getLegacyStatus()
Get the legacy status for failure (or success)
Definition
ImageRedirectConstraint.php:79
StatusValue
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition
StatusValue.php:46
StatusValue\setResult
setResult( $ok, $value=null)
Change operation result.
Definition
StatusValue.php:177
Content
Base interface for content objects.
Definition
Content.php:35
MediaWiki\EditPage\Constraint\IEditConstraint
Interface for all constraints that can prevent edits.
Definition
IEditConstraint.php:33
MediaWiki\Linker\LinkTarget
Definition
LinkTarget.php:26
MediaWiki\Permissions\Authority
This interface represents the authority associated the current execution context, such as a web reque...
Definition
Authority.php:37
MediaWiki\EditPage\Constraint
Definition
AccidentalRecreationConstraint.php:21
$title
$title
Definition
testCompression.php:38
includes
editpage
Constraint
ImageRedirectConstraint.php
Generated on Tue Oct 1 2024 01:15:33 for MediaWiki by
1.10.0