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 
128  public static function newFromArray( array $a ) {
129  return new self(
130  $a['isNew'],
131  $a['originalRevisionId'],
132  $a['revertMethod'],
133  $a['oldestRevertedRevId'],
134  $a['newestRevertedRevId'],
135  $a['isExactRevert'],
136  $a['isNullEdit'],
137  $a['revertTags']
138  );
139  }
140 
150  public function getNewestRevertedRevisionId() : ?int {
152  }
153 
163  public function getOldestRevertedRevisionId() : ?int {
165  }
166 
173  public function getUndidRevId() : int {
174  if ( $this->getRevertMethod() !== self::REVERT_UNDO ) {
175  return 0;
176  }
177  return $this->getOldestRevertedRevisionId() ?? 0;
178  }
179 
191  public function getOriginalRevisionId() {
193  }
194 
200  public function isNew() : bool {
201  return $this->isNew;
202  }
203 
221  public function isRevert() : bool {
222  return !$this->isNew() && $this->getOldestRevertedRevisionId();
223  }
224 
235  public function getRevertMethod() : ?int {
236  return $this->revertMethod;
237  }
238 
245  public function isExactRevert() : bool {
246  return $this->isExactRevert;
247  }
248 
255  public function isNullEdit() : bool {
256  return $this->isNullEdit;
257  }
258 
264  public function getRevertTags() : array {
265  return $this->revertTags;
266  }
267 
280  public function jsonSerialize() {
281  return [
282  'isNew' => $this->isNew,
283  'originalRevisionId' => $this->originalRevisionId,
284  'revertMethod' => $this->revertMethod,
285  'newestRevertedRevId' => $this->newestRevertedRevId,
286  'oldestRevertedRevId' => $this->oldestRevertedRevId,
287  'isExactRevert' => $this->isExactRevert,
288  'isNullEdit' => $this->isNullEdit,
289  'revertTags' => $this->revertTags,
291  ];
292  }
293 }
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:280
MediaWiki\Storage\EditResult\getUndidRevId
getUndidRevId()
If the edit was an undo, returns the oldest revision that was undone.
Definition: EditResult.php:173
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:150
MediaWiki\Storage\EditResult\isExactRevert
isExactRevert()
Whether the edit was an exact revert, i.e.
Definition: EditResult.php:245
MediaWiki\Storage\EditResult\getOriginalRevisionId
getOriginalRevisionId()
Returns the ID of an earlier revision that is being repeated or restored.
Definition: EditResult.php:191
MediaWiki\Storage\EditResult\isNew
isNew()
Whether the edit created a new page.
Definition: EditResult.php:200
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:163
MediaWiki\Storage\EditResult\newFromArray
static newFromArray(array $a)
Recreate the EditResult object from its array representation.
Definition: EditResult.php:128
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:235
MediaWiki\Storage\EditResult\isRevert
isRevert()
Whether the edit was a revert, not necessarily exact.
Definition: EditResult.php:221
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:264
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:255