MediaWiki master
ImageRedirectConstraint.php
Go to the documentation of this file.
1<?php
8
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 // Check isn't simple enough to just repeat when getting the status
34 if ( $this->page->getNamespace() === NS_FILE &&
35 $this->newContent->isRedirect() &&
36 !$this->performer->isAllowed( 'upload' )
37 ) {
38 $errorCode = $this->performer->getUser()->isRegistered() ?
41 return PageEditStatus::newGood( $errorCode )
42 ->setOK( false )
43 ->setErrorFunction( static fn () => throw new PermissionsError( 'upload' ) );
44 }
45
46 return PageEditStatus::newGood();
47 }
48
49}
const NS_FILE
Definition Defines.php:57
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:71
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,)
Show an error when a user tries to do something they do not have the necessary permissions for.
Status returned by edit constraints and other page editing checks.
setOK( $ok)
Change operation status.
Content objects represent page content, e.g.
Definition Content.php:28
const AS_IMAGE_REDIRECT_ANON
Status: anonymous user is not allowed to upload (User::isAllowed('upload') == false)
const AS_IMAGE_REDIRECT_LOGGED
Status: logged in user is not allowed to upload (User::isAllowed('upload') == false)
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