MediaWiki master
ContentModelChangeConstraint.php
Go to the documentation of this file.
1<?php
8
13
25
31 public function __construct(
32 private readonly Authority $performer,
33 private readonly Title $title,
34 private readonly string $newContentModel,
35 ) {
36 }
37
38 public function checkConstraint(): EditPageStatus {
39 if ( $this->newContentModel === $this->title->getContentModel() ) {
41 }
42
43 $status = PermissionStatus::newEmpty();
44
45 if ( !$this->performer->authorizeWrite( 'editcontentmodel', $this->title, $status ) ) {
46 return $this->castPermissionStatus( $status );
47 }
48
49 // Make sure the user can edit the page under the new content model too.
50 // We rely on caching in UserAuthority to avoid bumping the rate limit counter twice.
51 $titleWithNewContentModel = clone $this->title;
52 $titleWithNewContentModel->setContentModel( $this->newContentModel );
53 if (
54 !$this->performer->authorizeWrite( 'editcontentmodel', $titleWithNewContentModel, $status )
55 || !$this->performer->authorizeWrite( 'edit', $titleWithNewContentModel, $status )
56 ) {
57 return $this->castPermissionStatus( $status );
58 }
59
61 }
62
63 private function castPermissionStatus( PermissionStatus $status ): EditPageStatus {
64 $statusValue = EditPageStatus::newGood();
65
66 if ( !$status->isGood() ) {
67 if ( $status->isRateLimitExceeded() ) {
68 $statusValue->setResult( false, self::AS_RATE_LIMITED );
69 } else {
70 $statusValue
71 ->setResult( false, self::AS_NO_CHANGE_CONTENT_MODEL )
72 ->setErrorFunction( $status->throwErrorPageError( ... ) );
73 }
74 }
75
76 // TODO: Use error messages from the PermissionStatus ($status) here - T384399
77 return $statusValue;
78 }
79
80}
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:69
Verify user permissions if changing content model: Must have editcontentmodel rights Must be able to ...
__construct(private readonly Authority $performer, private readonly Title $title, private readonly string $newContentModel,)
Status returned by edit constraints and other page editing checks.
A StatusValue for permission errors.
Represents a title within MediaWiki.
Definition Title.php:69
static newGood( $value=null)
Factory function for good results.
Interface for all constraints that can prevent edits.
This interface represents the authority associated with the current execution context,...
Definition Authority.php:23