MediaWiki master
ContentModelChangeConstraint.php
Go to the documentation of this file.
1<?php
22
25use StatusValue;
26
37
38 private Authority $performer;
39 private Title $title;
40 private string $newContentModel;
41 private string $result;
42
48 public function __construct(
49 Authority $performer,
50 Title $title,
51 string $newContentModel
52 ) {
53 $this->performer = $performer;
54 $this->title = $title;
55 $this->newContentModel = $newContentModel;
56 }
57
58 public function checkConstraint(): string {
59 if ( $this->newContentModel === $this->title->getContentModel() ) {
60 // No change
61 $this->result = self::CONSTRAINT_PASSED;
62 return self::CONSTRAINT_PASSED;
63 }
64
65 if ( !$this->performer->isAllowed( 'editcontentmodel' ) ) {
66 $this->result = self::CONSTRAINT_FAILED;
67 return self::CONSTRAINT_FAILED;
68 }
69
70 // Make sure the user can edit the page under the new content model too
71 $titleWithNewContentModel = clone $this->title;
72 $titleWithNewContentModel->setContentModel( $this->newContentModel );
73
74 $canEditModel = $this->performer->authorizeWrite(
75 'editcontentmodel',
76 $titleWithNewContentModel
77 );
78
79 if (
80 !$canEditModel
81 || !$this->performer->authorizeWrite( 'edit', $titleWithNewContentModel )
82 ) {
83 $this->result = self::CONSTRAINT_FAILED;
84 return self::CONSTRAINT_FAILED;
85 }
86
87 $this->result = self::CONSTRAINT_PASSED;
88 return self::CONSTRAINT_PASSED;
89 }
90
91 public function getLegacyStatus(): StatusValue {
92 $statusValue = StatusValue::newGood();
93
94 if ( $this->result === self::CONSTRAINT_FAILED ) {
95 $statusValue->setResult( false, self::AS_NO_CHANGE_CONTENT_MODEL );
96 }
97
98 return $statusValue;
99 }
100
101}
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:81
Verify user permissions if changing content model: Must have editcontentmodel rights Must be able to ...
getLegacyStatus()
Get the legacy status for failure (or success)
__construct(Authority $performer, Title $title, string $newContentModel)
Represents a title within MediaWiki.
Definition Title.php:78
Generic operation result class Has warning/error list, boolean status and arbitrary value.
setResult( $ok, $value=null)
Change operation result.
Interface for all constraints that can prevent edits.
This interface represents the authority associated with the current execution context,...
Definition Authority.php:37