46 private const REVERT_METHOD_TO_CHANGE_TAG = [
53 private $revisionRecord =
null;
56 private $isNew =
false;
59 private $originalRevisionId =
false;
62 private $originalRevision =
null;
65 private $revertMethod =
null;
68 private $newestRevertedRevId =
null;
71 private $oldestRevertedRevId =
null;
74 private $revertAfterRevId =
null;
77 private $revisionStore;
80 private $softwareTags;
98 $this->revisionStore = $revisionStore;
99 $this->softwareTags = $softwareTags;
100 $this->options = $options;
107 if ( $this->revisionRecord === null ) {
109 'Revision was not set prior to building an EditResult'
114 $this->guessOriginalRevisionId();
117 $this->detectManualRevert();
121 $this->originalRevisionId,
123 $this->oldestRevertedRevId,
124 $this->newestRevertedRevId,
125 $this->isExactRevert(),
127 $this->getRevertTags()
138 $this->revisionRecord = $revisionRecord;
148 $this->isNew = $isNew;
162 int $newestRevertedRevId,
163 ?
int $revertAfterRevId =
null
171 'must be one of REVERT_UNDO, REVERT_ROLLBACK, REVERT_MANUAL'
173 $this->revertAfterRevId = $revertAfterRevId;
175 if ( $newestRevertedRevId ) {
176 $this->revertMethod = $revertMethod;
177 $this->newestRevertedRevId = $newestRevertedRevId;
178 $revertAfterRevision = $revertAfterRevId ?
179 $this->revisionStore->getRevisionById( $revertAfterRevId ) :
181 $oldestRevertedRev = $revertAfterRevision ?
182 $this->revisionStore->getNextRevision( $revertAfterRevision ) :
null;
183 if ( $oldestRevertedRev ) {
184 $this->oldestRevertedRevId = $oldestRevertedRev->getId();
188 $this->oldestRevertedRevId = $this->newestRevertedRevId;
200 $this->originalRevision = $originalRevision;
201 $this->originalRevisionId = $originalRevision->getId();
203 $this->originalRevisionId = $originalRevision ??
false;
204 $this->originalRevision =
null;
215 private function detectManualRevert() {
217 if ( !$searchRadius ||
219 $this->revertMethod !==
null ||
221 $this->isNullEdit() ||
224 !$this->revisionRecord->getParentId()
229 $revertedToRev = $this->revisionStore->findIdenticalRevision( $this->revisionRecord, $searchRadius );
230 if ( !$revertedToRev ) {
233 $oldestReverted = $this->revisionStore->getNextRevision( $revertedToRev );
234 if ( !$oldestReverted ) {
238 $this->setOriginalRevision( $revertedToRev );
240 $this->oldestRevertedRevId = $oldestReverted->getId();
241 $this->newestRevertedRevId = $this->revisionRecord->getParentId();
242 $this->revertAfterRevId = $revertedToRev->getId();
248 private function guessOriginalRevisionId() {
249 if ( !$this->originalRevisionId ) {
250 if ( $this->revertAfterRevId ) {
251 $this->setOriginalRevision( $this->revertAfterRevId );
252 } elseif ( $this->newestRevertedRevId ) {
255 $undidRevision = $this->revisionStore->getRevisionById( $this->newestRevertedRevId );
256 if ( $undidRevision ) {
257 $originalRevision = $this->revisionStore->getPreviousRevision( $undidRevision );
258 if ( $originalRevision ) {
259 $this->setOriginalRevision( $originalRevision );
267 if ( $this->getOriginalRevision() &&
268 !$this->getOriginalRevision()->hasSameContent( $this->revisionRecord )
270 $this->setOriginalRevision(
false );
280 private function getOriginalRevision(): ?RevisionRecord {
281 if ( $this->originalRevision ) {
282 return $this->originalRevision;
284 if ( !$this->originalRevisionId ) {
288 $this->originalRevision = $this->revisionStore->getRevisionById( $this->originalRevisionId );
289 return $this->originalRevision;
298 private function isExactRevert(): bool {
299 if ( $this->isNew || $this->oldestRevertedRevId === null ) {
303 $originalRevision = $this->getOriginalRevision();
304 if ( !$originalRevision ) {
309 return $this->revisionRecord->hasSameContent( $originalRevision );
317 private function isNullEdit(): bool {
318 if ( $this->isNew ) {
322 return $this->getOriginalRevision() &&
323 $this->originalRevisionId === $this->revisionRecord->getParentId();
331 private function getRevertTags(): array {
332 if ( isset( self::REVERT_METHOD_TO_CHANGE_TAG[$this->revertMethod] ) ) {
333 $revertTag = self::REVERT_METHOD_TO_CHANGE_TAG[$this->revertMethod];
334 if ( in_array( $revertTag, $this->softwareTags ) ) {
335 return [ $revertTag ];