49 private const REVERT_METHOD_TO_CHANGE_TAG = [
56 private $revisionRecord =
null;
59 private $isNew =
false;
62 private $originalRevisionId =
false;
65 private $originalRevision =
null;
68 private $revertMethod =
null;
71 private $newestRevertedRevId =
null;
74 private $oldestRevertedRevId =
null;
77 private $revertAfterRevId =
null;
80 private $revisionStore;
83 private $softwareTags;
101 $this->revisionStore = $revisionStore;
102 $this->softwareTags = $softwareTags;
103 $this->options = $options;
110 if ( $this->revisionRecord === null ) {
112 'Revision was not set prior to building an EditResult'
117 $this->guessOriginalRevisionId();
120 $this->detectManualRevert();
124 $this->originalRevisionId,
126 $this->oldestRevertedRevId,
127 $this->newestRevertedRevId,
128 $this->isExactRevert(),
130 $this->getRevertTags()
141 $this->revisionRecord = $revisionRecord;
151 $this->isNew = $isNew;
165 int $newestRevertedRevId,
166 int $revertAfterRevId =
null
174 'must be one of REVERT_UNDO, REVERT_ROLLBACK, REVERT_MANUAL'
176 $this->revertAfterRevId = $revertAfterRevId;
178 if ( $newestRevertedRevId ) {
179 $this->revertMethod = $revertMethod;
180 $this->newestRevertedRevId = $newestRevertedRevId;
181 $revertAfterRevision = $revertAfterRevId ?
182 $this->revisionStore->getRevisionById( $revertAfterRevId ) :
184 $oldestRevertedRev = $revertAfterRevision ?
185 $this->revisionStore->getNextRevision( $revertAfterRevision ) :
null;
186 if ( $oldestRevertedRev ) {
187 $this->oldestRevertedRevId = $oldestRevertedRev->getId();
191 $this->oldestRevertedRevId = $this->newestRevertedRevId;
203 $this->originalRevision = $originalRevision;
204 $this->originalRevisionId = $originalRevision->getId();
206 $this->originalRevisionId = $originalRevision ??
false;
207 $this->originalRevision =
null;
218 private function detectManualRevert() {
220 if ( !$searchRadius ||
222 $this->revertMethod !==
null ||
224 $this->isNullEdit() ||
227 !$this->revisionRecord->getParentId()
232 $revertedToRev = $this->revisionStore->findIdenticalRevision( $this->revisionRecord, $searchRadius );
233 if ( !$revertedToRev ) {
236 $oldestReverted = $this->revisionStore->getNextRevision( $revertedToRev );
237 if ( !$oldestReverted ) {
241 $this->setOriginalRevision( $revertedToRev );
243 $this->oldestRevertedRevId = $oldestReverted->getId();
244 $this->newestRevertedRevId = $this->revisionRecord->getParentId();
245 $this->revertAfterRevId = $revertedToRev->getId();
251 private function guessOriginalRevisionId() {
252 if ( !$this->originalRevisionId ) {
253 if ( $this->revertAfterRevId ) {
254 $this->setOriginalRevision( $this->revertAfterRevId );
255 } elseif ( $this->newestRevertedRevId ) {
258 $undidRevision = $this->revisionStore->getRevisionById( $this->newestRevertedRevId );
259 if ( $undidRevision ) {
260 $originalRevision = $this->revisionStore->getPreviousRevision( $undidRevision );
261 if ( $originalRevision ) {
262 $this->setOriginalRevision( $originalRevision );
270 if ( $this->getOriginalRevision() &&
271 !$this->getOriginalRevision()->hasSameContent( $this->revisionRecord )
273 $this->setOriginalRevision(
false );
283 private function getOriginalRevision(): ?RevisionRecord {
284 if ( $this->originalRevision ) {
285 return $this->originalRevision;
287 if ( !$this->originalRevisionId ) {
291 $this->originalRevision = $this->revisionStore->getRevisionById( $this->originalRevisionId );
292 return $this->originalRevision;
301 private function isExactRevert(): bool {
302 if ( $this->isNew || $this->oldestRevertedRevId === null ) {
306 $originalRevision = $this->getOriginalRevision();
307 if ( !$originalRevision ) {
312 return $this->revisionRecord->hasSameContent( $originalRevision );
320 private function isNullEdit(): bool {
321 if ( $this->isNew ) {
325 return $this->getOriginalRevision() &&
326 $this->originalRevisionId === $this->revisionRecord->getParentId();
334 private function getRevertTags(): array {
335 if ( isset( self::REVERT_METHOD_TO_CHANGE_TAG[$this->revertMethod] ) ) {
336 $revertTag = self::REVERT_METHOD_TO_CHANGE_TAG[$this->revertMethod];
337 if ( in_array( $revertTag, $this->softwareTags ) ) {
338 return [ $revertTag ];