| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\EditPage\Constraint; |
| 22 |
|
| 23 |
use MediaWiki\Content\Content; |
| 24 |
use MediaWiki\Linker\LinkTarget; |
| 25 |
use MediaWiki\Permissions\Authority; |
| 26 |
use StatusValue; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
class ImageRedirectConstraint implements IEditConstraint { |
| 37 |
|
| 38 |
private Content $newContent; |
| 39 |
private LinkTarget $title; |
| 40 |
private Authority $performer; |
| 41 |
private string $result; |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public function __construct( |
| 49 |
Content $newContent, |
| 50 |
LinkTarget $title, |
| 51 |
Authority $performer |
| 52 |
) { |
| 53 |
$this->newContent = $newContent; |
| 54 |
$this->title = $title; |
| 55 |
$this->performer = $performer; |
| 56 |
} |
| 57 |
|
| 58 |
public function checkConstraint(): string { |
| 59 |
|
| 60 |
if ( $this->title->getNamespace() === NS_FILE && |
| 61 |
$this->newContent->isRedirect() && |
| 62 |
!$this->performer->isAllowed( 'upload' ) |
| 63 |
) { |
| 64 |
$this->result = self::CONSTRAINT_FAILED; |
| 65 |
return self::CONSTRAINT_FAILED; |
| 66 |
} |
| 67 |
|
| 68 |
$this->result = self::CONSTRAINT_PASSED; |
| 69 |
return self::CONSTRAINT_PASSED; |
| 70 |
} |
| 71 |
|
| 72 |
public function getLegacyStatus(): StatusValue { |
| 73 |
$statusValue = StatusValue::newGood(); |
| 74 |
|
| 75 |
if ( $this->result === self::CONSTRAINT_FAILED ) { |
| 76 |
$errorCode = $this->performer->getUser()->isRegistered() ? |
| 77 |
self::AS_IMAGE_REDIRECT_LOGGED : |
| 78 |
self::AS_IMAGE_REDIRECT_ANON; |
| 79 |
$statusValue->setResult( false, $errorCode ); |
| 80 |
} |
| 81 |
|
| 82 |
return $statusValue; |
| 83 |
} |
| 84 |
|
| 85 |
} |