MediaWiki REL1_35
EditResultBuilder.php
Go to the documentation of this file.
1<?php
25namespace MediaWiki\Storage;
26
29
37
39 private $revisionRecord = null;
40
42 private $isNew = false;
43
45 private $originalRevisionId = false;
46
48 private $originalRevision = null;
49
51 private $revertMethod = null;
52
54 private $newestRevertedRevId = null;
55
57 private $oldestRevertedRevId = null;
58
61
64
73 $this->revisionStore = $revisionStore;
74 $this->softwareTags = $softwareTags;
75 }
76
82 public function buildEditResult() : EditResult {
83 if ( $this->revisionRecord === null ) {
84 throw new PageUpdateException(
85 'Revision was not set prior to building an EditResult'
86 );
87 }
88
89 return new EditResult(
90 $this->isNew,
91 $this->originalRevisionId,
92 $this->revertMethod,
93 $this->oldestRevertedRevId,
94 $this->newestRevertedRevId,
95 $this->isExactRevert(),
96 $this->isNullEdit(),
97 $this->getRevertTags()
98 );
99 }
100
107 public function setRevisionRecord( RevisionRecord $revisionRecord ) {
108 $this->revisionRecord = $revisionRecord;
109 }
110
117 public function setIsNew( bool $isNew ) {
118 $this->isNew = $isNew;
119 }
120
131 public function markAsRevert(
132 int $revertMethod,
133 int $oldestRevertedRevId,
134 int $newestRevertedRevId = 0
135 ) {
136 if ( $oldestRevertedRevId === 0 ) {
137 return;
138 }
139 if ( $newestRevertedRevId === 0 ) {
140 $newestRevertedRevId = $oldestRevertedRevId;
141 }
142
143 $this->revertMethod = $revertMethod;
144 $this->oldestRevertedRevId = $oldestRevertedRevId;
145 $this->newestRevertedRevId = $newestRevertedRevId;
146 }
147
153 public function setOriginalRevisionId( $originalRevId ) {
154 $this->originalRevisionId = $originalRevId;
155 }
156
165 private function getOriginalRevision(
166 int $flags = RevisionStore::READ_NORMAL
167 ) : ?RevisionRecord {
168 if ( $this->originalRevision ) {
169 return $this->originalRevision;
170 }
171 if ( $this->originalRevisionId === false ) {
172 return null;
173 }
174
175 $this->originalRevision = $this->revisionStore->getRevisionById(
176 $this->originalRevisionId,
177 $flags
178 );
179 return $this->originalRevision;
180 }
181
188 private function isExactRevert() : bool {
189 if ( $this->isNew || $this->oldestRevertedRevId === null ) {
190 return false;
191 }
192
193 if ( $this->getOriginalRevision() === null ) {
194 // we can't find the original revision for some reason, better return false
195 return false;
196 }
197
198 return $this->revisionRecord->hasSameContent( $this->getOriginalRevision() );
199 }
200
206 private function isNullEdit() : bool {
207 if ( $this->isNew ) {
208 return false;
209 }
210
211 return $this->getOriginalRevision() &&
212 $this->originalRevisionId === $this->revisionRecord->getParentId();
213 }
214
220 private function getRevertTags() : array {
221 if ( $this->revertMethod === EditResult::REVERT_UNDO &&
222 in_array( 'mw-undo', $this->softwareTags )
223 ) {
224 return [ 'mw-undo' ];
225 } elseif ( $this->revertMethod === EditResult::REVERT_ROLLBACK &&
226 in_array( 'mw-rollback', $this->softwareTags )
227 ) {
228 return [ 'mw-rollback' ];
229 }
230
231 return [];
232 }
233}
if(ini_get('mbstring.func_overload')) if(!defined('MW_ENTRY_POINT'))
Pre-config setup: Before loading LocalSettings.php.
Definition Setup.php:85
Page revision base class.
Service for looking up page revisions.
Builder class for the EditResult object.
buildEditResult()
Builds the EditResult object.
__construct(RevisionStore $revisionStore, array $softwareTags)
EditResultBuilder constructor.
setOriginalRevisionId( $originalRevId)
Sets the ID of an earlier revision that is being repeated or restored.
setIsNew(bool $isNew)
Set whether the edit created a new page.
isExactRevert()
Whether the edit was an exact revert, i.e.
setRevisionRecord(RevisionRecord $revisionRecord)
Set the revision associated with this edit.
markAsRevert(int $revertMethod, int $oldestRevertedRevId, int $newestRevertedRevId=0)
Marks this edit as a revert and applies relevant information.
getRevertTags()
Returns an array of revert-related tags that will be applied automatically to this edit.
isNullEdit()
An edit is a null edit if the original revision is equal to the parent revision.
getOriginalRevision(int $flags=RevisionStore::READ_NORMAL)
Returns the revision that is being repeated or restored.
Object for storing information about the effects of an edit.
Exception representing a failure to update a page entry.