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 
85  public function __construct(
86  bool $isNew,
88  ?int $revertMethod,
89  ?int $oldestReverted,
90  ?int $newestReverted,
91  bool $isExactRevert,
92  bool $isNullEdit,
93  array $revertTags
94  ) {
95  $this->isNew = $isNew;
96  $this->originalRevisionId = $originalRevisionId;
97  $this->revertMethod = $revertMethod;
98  $this->oldestRevertedRevId = $oldestReverted;
99  $this->newestRevertedRevId = $newestReverted;
100  $this->isExactRevert = $isExactRevert;
101  $this->isNullEdit = $isNullEdit;
102  $this->revertTags = $revertTags;
103  }
104 
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 
217  public function isRevert() : bool {
218  return !$this->isNew() && $this->getOldestRevertedRevisionId();
219  }
220 
231  public function getRevertMethod() : ?int {
232  return $this->revertMethod;
233  }
234 
241  public function isExactRevert() : bool {
242  return $this->isExactRevert;
243  }
244 
251  public function isNullEdit() : bool {
252  return $this->isNullEdit;
253  }
254 
260  public function getRevertTags() : array {
261  return $this->revertTags;
262  }
263 
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)
EditResult constructor.
Definition: EditResult.php:85
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:241
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:231
MediaWiki\Storage\EditResult\isRevert
isRevert()
Whether the edit was a revert, not necessarily exact.
Definition: EditResult.php:217
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:260
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:251