MediaWiki  master
EditResult.php
Go to the documentation of this file.
1 <?php
25 namespace MediaWiki\Storage;
26 
27 use JsonSerializable;
28 
38 class EditResult implements JsonSerializable {
39 
40  // revert methods
41  public const REVERT_UNDO = 1;
42  public const REVERT_ROLLBACK = 2;
43  public const REVERT_MANUAL = 3;
44 
45  private const SERIALIZATION_FORMAT_VERSION = '1';
46 
48  private $isNew;
49 
52 
54  private $revertMethod;
55 
58 
61 
63  private $isExactRevert;
64 
66  private $isNullEdit;
67 
69  private $revertTags;
70 
83  public function __construct(
84  bool $isNew,
86  ?int $revertMethod,
87  ?int $oldestReverted,
88  ?int $newestReverted,
89  bool $isExactRevert,
90  bool $isNullEdit,
91  array $revertTags
92  ) {
93  $this->isNew = $isNew;
94  $this->originalRevisionId = $originalRevisionId;
95  $this->revertMethod = $revertMethod;
96  $this->oldestRevertedRevId = $oldestReverted;
97  $this->newestRevertedRevId = $newestReverted;
99  $this->isNullEdit = $isNullEdit;
100  $this->revertTags = $revertTags;
101  }
102 
125  public static function newFromArray( array $a ) {
126  return new self(
127  $a['isNew'],
128  $a['originalRevisionId'],
129  $a['revertMethod'],
130  $a['oldestRevertedRevId'],
131  $a['newestRevertedRevId'],
132  $a['isExactRevert'],
133  $a['isNullEdit'],
134  $a['revertTags']
135  );
136  }
137 
147  public function getNewestRevertedRevisionId(): ?int {
149  }
150 
160  public function getOldestRevertedRevisionId(): ?int {
162  }
163 
170  public function getUndidRevId(): int {
171  if ( $this->getRevertMethod() !== self::REVERT_UNDO ) {
172  return 0;
173  }
174  return $this->getOldestRevertedRevisionId() ?? 0;
175  }
176 
188  public function getOriginalRevisionId() {
190  }
191 
197  public function isNew(): bool {
198  return $this->isNew;
199  }
200 
218  public function isRevert(): bool {
219  return !$this->isNew() && $this->getOldestRevertedRevisionId();
220  }
221 
232  public function getRevertMethod(): ?int {
233  return $this->revertMethod;
234  }
235 
242  public function isExactRevert(): bool {
243  return $this->isExactRevert;
244  }
245 
252  public function isNullEdit(): bool {
253  return $this->isNullEdit;
254  }
255 
261  public function getRevertTags(): array {
262  return $this->revertTags;
263  }
264 
276  public function jsonSerialize() {
277  return [
278  'isNew' => $this->isNew,
279  'originalRevisionId' => $this->originalRevisionId,
280  'revertMethod' => $this->revertMethod,
281  'newestRevertedRevId' => $this->newestRevertedRevId,
282  'oldestRevertedRevId' => $this->oldestRevertedRevId,
283  'isExactRevert' => $this->isExactRevert,
284  'isNullEdit' => $this->isNullEdit,
285  'revertTags' => $this->revertTags,
287  ];
288  }
289 }
MediaWiki\Storage\EditResult\REVERT_ROLLBACK
const REVERT_ROLLBACK
Definition: EditResult.php:42
MediaWiki\Storage\EditResult\jsonSerialize
jsonSerialize()
Returns an array representing the EditResult object.
Definition: EditResult.php:276
MediaWiki\Storage\EditResult\getUndidRevId
getUndidRevId()
If the edit was an undo, returns the oldest revision that was undone.
Definition: EditResult.php:170
MediaWiki\Storage\EditResult\$newestRevertedRevId
int null $newestRevertedRevId
Definition: EditResult.php:57
MediaWiki\Storage\EditResult\$isExactRevert
bool $isExactRevert
Definition: EditResult.php:63
MediaWiki\Storage\EditResult\__construct
__construct(bool $isNew, $originalRevisionId, ?int $revertMethod, ?int $oldestReverted, ?int $newestReverted, bool $isExactRevert, bool $isNullEdit, array $revertTags)
Definition: EditResult.php:83
MediaWiki\Storage\EditResult\getNewestRevertedRevisionId
getNewestRevertedRevisionId()
Returns the ID of the most recent revision that was reverted by this edit.
Definition: EditResult.php:147
MediaWiki\Storage\EditResult\isExactRevert
isExactRevert()
Whether the edit was an exact revert, i.e.
Definition: EditResult.php:242
MediaWiki\Storage\EditResult\getOriginalRevisionId
getOriginalRevisionId()
Returns the ID of an earlier revision that is being repeated or restored.
Definition: EditResult.php:188
MediaWiki\Storage\EditResult\isNew
isNew()
Whether the edit created a new page.
Definition: EditResult.php:197
MediaWiki\Storage\EditResult\$originalRevisionId
bool int $originalRevisionId
Definition: EditResult.php:51
MediaWiki\Storage\EditResult\getOldestRevertedRevisionId
getOldestRevertedRevisionId()
Returns the ID of the oldest revision that was reverted by this edit.
Definition: EditResult.php:160
MediaWiki\Storage\EditResult\newFromArray
static newFromArray(array $a)
Recreate the EditResult object from its array representation.
Definition: EditResult.php:125
MediaWiki\Storage\EditResult\$isNullEdit
bool $isNullEdit
Definition: EditResult.php:66
MediaWiki\Storage\EditResult
Object for storing information about the effects of an edit.
Definition: EditResult.php:38
MediaWiki\Storage\EditResult\$revertMethod
int null $revertMethod
Definition: EditResult.php:54
MediaWiki\Storage\EditResult\$revertTags
string[] $revertTags
Definition: EditResult.php:69
MediaWiki\Storage
Definition: BlobAccessException.php:23
MediaWiki\Storage\EditResult\$isNew
bool $isNew
Definition: EditResult.php:48
MediaWiki\Storage\EditResult\SERIALIZATION_FORMAT_VERSION
const SERIALIZATION_FORMAT_VERSION
Definition: EditResult.php:45
MediaWiki\Storage\EditResult\getRevertMethod
getRevertMethod()
Returns the revert method that was used to perform the edit, if any changes were reverted.
Definition: EditResult.php:232
MediaWiki\Storage\EditResult\isRevert
isRevert()
Whether the edit was a revert, not necessarily exact.
Definition: EditResult.php:218
MediaWiki\Storage\EditResult\REVERT_UNDO
const REVERT_UNDO
Definition: EditResult.php:41
MediaWiki\Storage\EditResult\getRevertTags
getRevertTags()
Returns an array of revert-related tags that were applied automatically to this edit.
Definition: EditResult.php:261
MediaWiki\Storage\EditResult\REVERT_MANUAL
const REVERT_MANUAL
Definition: EditResult.php:43
MediaWiki\Storage\EditResult\$oldestRevertedRevId
int null $oldestRevertedRevId
Definition: EditResult.php:60
MediaWiki\Storage\EditResult\isNullEdit
isNullEdit()
An edit is a null edit if the original revision is equal to the parent revision, i....
Definition: EditResult.php:252