MediaWiki REL1_32
MutableRevisionRecord.php
Go to the documentation of this file.
1<?php
23namespace MediaWiki\Revision;
24
26use Content;
27use InvalidArgumentException;
30use MWException;
31use Title;
32use Wikimedia\Assert\Assert;
33
42
52 public static function newFromParentRevision( RevisionRecord $parent ) {
53 // TODO: ideally, we wouldn't need a Title here
54 $title = Title::newFromLinkTarget( $parent->getPageAsLinkTarget() );
55 $rev = new MutableRevisionRecord( $title, $parent->getWikiId() );
56
57 foreach ( $parent->getSlotRoles() as $role ) {
58 $slot = $parent->getSlot( $role, self::RAW );
59 $rev->inheritSlot( $slot );
60 }
61
62 $rev->setPageId( $parent->getPageId() );
63 $rev->setParentId( $parent->getId() );
64
65 return $rev;
66 }
67
78 function __construct( Title $title, $wikiId = false ) {
79 $slots = new MutableRevisionSlots();
80
81 parent::__construct( $title, $slots, $wikiId );
82
83 $this->mSlots = $slots; // redundant, but nice for static analysis
84 }
85
89 public function setParentId( $parentId ) {
90 Assert::parameterType( 'integer', $parentId, '$parentId' );
91
92 $this->mParentId = $parentId;
93 }
94
110 public function setSlot( SlotRecord $slot ) {
111 if ( $slot->hasRevision() && $slot->getRevision() !== $this->getId() ) {
112 throw new InvalidArgumentException(
113 'The given slot must be an unsaved, unattached one. '
114 . 'This slot is already attached to revision ' . $slot->getRevision() . '. '
115 . 'Use inheritSlot() instead to preserve a slot from a previous revision.'
116 );
117 }
118
119 $this->mSlots->setSlot( $slot );
120 $this->resetAggregateValues();
121 }
122
132 public function inheritSlot( SlotRecord $parentSlot ) {
133 $this->mSlots->inheritSlot( $parentSlot );
134 $this->resetAggregateValues();
135 }
136
151 public function setContent( $role, Content $content ) {
152 $this->mSlots->setContent( $role, $content );
153 $this->resetAggregateValues();
154 }
155
168 public function removeSlot( $role ) {
169 $this->mSlots->removeSlot( $role );
170 $this->resetAggregateValues();
171 }
172
178 public function applyUpdate( RevisionSlotsUpdate $update ) {
179 $update->apply( $this->mSlots );
180 }
181
185 public function setComment( CommentStoreComment $comment ) {
186 $this->mComment = $comment;
187 }
188
198 public function setSha1( $sha1 ) {
199 Assert::parameterType( 'string', $sha1, '$sha1' );
200
201 $this->mSha1 = $sha1;
202 }
203
213 public function setSize( $size ) {
214 Assert::parameterType( 'integer', $size, '$size' );
215
216 $this->mSize = $size;
217 }
218
222 public function setVisibility( $visibility ) {
223 Assert::parameterType( 'integer', $visibility, '$visibility' );
224
225 $this->mDeleted = $visibility;
226 }
227
231 public function setTimestamp( $timestamp ) {
232 Assert::parameterType( 'string', $timestamp, '$timestamp' );
233
234 $this->mTimestamp = wfTimestamp( TS_MW, $timestamp );
235 }
236
240 public function setMinorEdit( $minorEdit ) {
241 Assert::parameterType( 'boolean', $minorEdit, '$minorEdit' );
242
243 $this->mMinorEdit = $minorEdit;
244 }
245
257 public function setId( $id ) {
258 Assert::parameterType( 'integer', $id, '$id' );
259
260 $this->mId = $id;
261 }
262
268 public function setUser( UserIdentity $user ) {
269 $this->mUser = $user;
270 }
271
275 public function setPageId( $pageId ) {
276 Assert::parameterType( 'integer', $pageId, '$pageId' );
277
278 if ( $this->mTitle->exists() && $pageId !== $this->mTitle->getArticleID() ) {
279 throw new InvalidArgumentException(
280 'The given Title does not belong to page ID ' . $this->mPageId
281 );
282 }
283
284 $this->mPageId = $pageId;
285 }
286
294 public function getSize() {
295 // If not known, re-calculate and remember. Will be reset when slots change.
296 if ( $this->mSize === null ) {
297 $this->mSize = $this->mSlots->computeSize();
298 }
299
300 return $this->mSize;
301 }
302
310 public function getSha1() {
311 // If not known, re-calculate and remember. Will be reset when slots change.
312 if ( $this->mSha1 === null ) {
313 $this->mSha1 = $this->mSlots->computeSha1();
314 }
315
316 return $this->mSha1;
317 }
318
325 public function getSlots() {
326 // Overwritten just guarantee the more narrow return type.
327 return parent::getSlots();
328 }
329
333 private function resetAggregateValues() {
334 $this->mSize = null;
335 $this->mSha1 = null;
336 }
337
338}
339
344class_alias( MutableRevisionRecord::class, 'MediaWiki\Storage\MutableRevisionRecord' );
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
CommentStoreComment represents a comment stored by CommentStore.
MediaWiki exception.
Mutable RevisionRecord implementation, for building new revision entries programmatically.
setSlot(SlotRecord $slot)
Sets the given slot.
setUser(UserIdentity $user)
Sets the user identity associated with the revision.
removeSlot( $role)
Removes the slot with the given role from this revision.
resetAggregateValues()
Invalidate cached aggregate values such as hash and size.
applyUpdate(RevisionSlotsUpdate $update)
Applies the given update to the slots of this revision.
setSize( $size)
Set nominal revision size, for optimization.
getSha1()
Returns the base36 sha1 of this revision.
setContent( $role, Content $content)
Sets the content for the slot with the given role.
setSha1( $sha1)
Set revision hash, for optimization.
getSize()
Returns the nominal size of this revision.
static newFromParentRevision(RevisionRecord $parent)
Returns an incomplete MutableRevisionRecord which uses $parent as its parent revision,...
inheritSlot(SlotRecord $parentSlot)
"Inherits" the given slot's content.
getSlots()
Returns the slots defined for this revision as a MutableRevisionSlots instance, which can be modified...
Mutable version of RevisionSlots, for constructing a new revision.
Page revision base class.
Value object representing a content slot associated with a page revision.
hasRevision()
Whether this slot has revision ID associated.
getRevision()
Returns the ID of the revision this slot is associated with.
Value object representing a modification of revision slots.
Represents a title within MediaWiki.
Definition Title.php:39
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
Definition hooks.txt:1818
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition hooks.txt:247
Base interface for content objects.
Definition Content.php:34
Interface for objects representing user identity.
$parent
$content