MediaWiki master
ContentModelChangeConstraint.php
Go to the documentation of this file.
1<?php
22
25use StatusValue;
26
37
39 private $performer;
40
42 private $title;
43
45 private $newContentModel;
46
48 private $result;
49
55 public function __construct(
56 Authority $performer,
57 Title $title,
58 string $newContentModel
59 ) {
60 $this->performer = $performer;
61 $this->title = $title;
62 $this->newContentModel = $newContentModel;
63 }
64
65 public function checkConstraint(): string {
66 if ( $this->newContentModel === $this->title->getContentModel() ) {
67 // No change
68 $this->result = self::CONSTRAINT_PASSED;
69 return self::CONSTRAINT_PASSED;
70 }
71
72 if ( !$this->performer->isAllowed( 'editcontentmodel' ) ) {
73 $this->result = self::CONSTRAINT_FAILED;
74 return self::CONSTRAINT_FAILED;
75 }
76
77 // Make sure the user can edit the page under the new content model too
78 $titleWithNewContentModel = clone $this->title;
79 $titleWithNewContentModel->setContentModel( $this->newContentModel );
80
81 $canEditModel = $this->performer->authorizeWrite(
82 'editcontentmodel',
83 $titleWithNewContentModel
84 );
85
86 if (
87 !$canEditModel
88 || !$this->performer->authorizeWrite( 'edit', $titleWithNewContentModel )
89 ) {
90 $this->result = self::CONSTRAINT_FAILED;
91 return self::CONSTRAINT_FAILED;
92 }
93
94 $this->result = self::CONSTRAINT_PASSED;
95 return self::CONSTRAINT_PASSED;
96 }
97
98 public function getLegacyStatus(): StatusValue {
99 $statusValue = StatusValue::newGood();
100
101 if ( $this->result === self::CONSTRAINT_FAILED ) {
102 $statusValue->setResult( false, self::AS_NO_CHANGE_CONTENT_MODEL );
103 }
104
105 return $statusValue;
106 }
107
108}
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