MediaWiki master
ImageRedirectConstraint.php
Go to the documentation of this file.
1<?php
6
7namespace MediaWiki\EditPage\Constraint;
8
9use MediaWiki\Content\Content;
10use MediaWiki\Page\PageReference;
11use MediaWiki\PageEdit\PageEditStatus;
12use MediaWiki\Permissions\Authority;
13use MediaWiki\Permissions\PermissionStatus;
14
24
25 public function __construct(
26 private readonly Content $newContent,
27 private readonly PageReference $page,
28 private readonly Authority $performer,
29 ) {
30 }
31
32 public function checkConstraint(): PageEditStatus {
33 $status = PermissionStatus::newGood();
34 // Check isn't simple enough to just repeat when getting the status
35 if ( $this->page->getNamespace() === NS_FILE &&
36 $this->newContent->isRedirect() &&
37 !$this->performer->isAllowed( 'upload', $status )
38 ) {
39 $errorCode = $this->performer->getUser()->isRegistered() ?
40 self::AS_IMAGE_REDIRECT_LOGGED :
41 self::AS_IMAGE_REDIRECT_ANON;
42 return PageEditStatus::newGood( $errorCode )
43 ->setOK( false )
44 ->setErrorFunction( $status->throwErrorPageError( ... ) );
45 }
46
47 return PageEditStatus::newGood();
48 }
49
50}
const NS_FILE
Definition Defines.php:57
Abstract class for all constraints that can prevent edits.
Verify user permissions: If creating a redirect in the file namespace, must have upload rights.
__construct(private readonly Content $newContent, private readonly PageReference $page, private readonly Authority $performer,)
Status returned by edit constraints and other page editing checks.
A StatusValue for permission errors.
Content objects represent page content, e.g.
Definition Content.php:28
Interface for objects (potentially) representing a page that can be viewable and linked to on a wiki.
This interface represents the authority associated with the current execution context,...
Definition Authority.php:23