MediaWiki master
ImageRedirectConstraint.php
Go to the documentation of this file.
1<?php
8
14
24
30 public function __construct(
31 private readonly Content $newContent,
32 private readonly LinkTarget $title,
33 private readonly Authority $performer,
34 ) {
35 }
36
37 public function checkConstraint(): EditPageStatus {
38 // Check isn't simple enough to just repeat when getting the status
39 if ( $this->title->getNamespace() === NS_FILE &&
40 $this->newContent->isRedirect() &&
41 !$this->performer->isAllowed( 'upload' )
42 ) {
43 $errorCode = $this->performer->getUser()->isRegistered() ?
46 return EditPageStatus::newGood( $errorCode )
47 ->setOK( false )
48 ->setErrorFunction( static fn () => throw new PermissionsError( 'upload' ) );
49 }
50
52 }
53
54}
const NS_FILE
Definition Defines.php:57
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:69
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 LinkTarget $title, private readonly Authority $performer,)
Status returned by edit constraints and other page editing checks.
Show an error when a user tries to do something they do not have the necessary permissions for.
setOK( $ok)
Change operation status.
static newGood( $value=null)
Factory function for good results.
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)
Represents the target of a wiki link.
This interface represents the authority associated with the current execution context,...
Definition Authority.php:23