MediaWiki REL1_31
MutableRevisionRecord.php
Go to the documentation of this file.
1<?php
23namespace MediaWiki\Storage;
24
27use InvalidArgumentException;
31use Wikimedia\Assert\Assert;
32
40
53 public static function newFromParentRevision(
54 RevisionRecord $parent,
55 CommentStoreComment $comment,
56 UserIdentity $user,
57 $timestamp
58 ) {
59 // TODO: ideally, we wouldn't need a Title here
60 $title = Title::newFromLinkTarget( $parent->getPageAsLinkTarget() );
61 $rev = new MutableRevisionRecord( $title, $parent->getWikiId() );
62
63 $rev->setComment( $comment );
64 $rev->setUser( $user );
65 $rev->setTimestamp( $timestamp );
66
67 foreach ( $parent->getSlotRoles() as $role ) {
68 $slot = $parent->getSlot( $role, self::RAW );
69 $rev->inheritSlot( $slot );
70 }
71
72 $rev->setPageId( $parent->getPageId() );
73 $rev->setParentId( $parent->getId() );
74
75 return $rev;
76 }
77
88 function __construct( Title $title, $wikiId = false ) {
89 $slots = new MutableRevisionSlots();
90
91 parent::__construct( $title, $slots, $wikiId );
92
93 $this->mSlots = $slots; // redundant, but nice for static analysis
94 }
95
99 public function setParentId( $parentId ) {
100 Assert::parameterType( 'integer', $parentId, '$parentId' );
101
102 $this->mParentId = $parentId;
103 }
104
120 public function setSlot( SlotRecord $slot ) {
121 if ( $slot->hasRevision() && $slot->getRevision() !== $this->getId() ) {
122 throw new InvalidArgumentException(
123 'The given slot must be an unsaved, unattached one. '
124 . 'This slot is already attached to revision ' . $slot->getRevision() . '. '
125 . 'Use inheritSlot() instead to preserve a slot from a previous revision.'
126 );
127 }
128
129 $this->mSlots->setSlot( $slot );
130 $this->resetAggregateValues();
131 }
132
142 public function inheritSlot( SlotRecord $parentSlot ) {
143 $slot = SlotRecord::newInherited( $parentSlot );
144 $this->setSlot( $slot );
145 }
146
161 public function setContent( $role, Content $content ) {
162 $this->mSlots->setContent( $role, $content );
163 $this->resetAggregateValues();
164 }
165
178 public function removeSlot( $role ) {
179 $this->mSlots->removeSlot( $role );
180 $this->resetAggregateValues();
181 }
182
186 public function setComment( CommentStoreComment $comment ) {
187 $this->mComment = $comment;
188 }
189
199 public function setSha1( $sha1 ) {
200 Assert::parameterType( 'string', $sha1, '$sha1' );
201
202 $this->mSha1 = $sha1;
203 }
204
214 public function setSize( $size ) {
215 Assert::parameterType( 'integer', $size, '$size' );
216
217 $this->mSize = $size;
218 }
219
223 public function setVisibility( $visibility ) {
224 Assert::parameterType( 'integer', $visibility, '$visibility' );
225
226 $this->mDeleted = $visibility;
227 }
228
232 public function setTimestamp( $timestamp ) {
233 Assert::parameterType( 'string', $timestamp, '$timestamp' );
234
235 $this->mTimestamp = wfTimestamp( TS_MW, $timestamp );
236 }
237
241 public function setMinorEdit( $minorEdit ) {
242 Assert::parameterType( 'boolean', $minorEdit, '$minorEdit' );
243
244 $this->mMinorEdit = $minorEdit;
245 }
246
258 public function setId( $id ) {
259 Assert::parameterType( 'integer', $id, '$id' );
260
261 $this->mId = $id;
262 }
263
269 public function setUser( UserIdentity $user ) {
270 $this->mUser = $user;
271 }
272
276 public function setPageId( $pageId ) {
277 Assert::parameterType( 'integer', $pageId, '$pageId' );
278
279 if ( $this->mTitle->exists() && $pageId !== $this->mTitle->getArticleID() ) {
280 throw new InvalidArgumentException(
281 'The given Title does not belong to page ID ' . $this->mPageId
282 );
283 }
284
285 $this->mPageId = $pageId;
286 }
287
295 public function getSize() {
296 // If not known, re-calculate and remember. Will be reset when slots change.
297 if ( $this->mSize === null ) {
298 $this->mSize = $this->mSlots->computeSize();
299 }
300
301 return $this->mSize;
302 }
303
311 public function getSha1() {
312 // If not known, re-calculate and remember. Will be reset when slots change.
313 if ( $this->mSha1 === null ) {
314 $this->mSha1 = $this->mSlots->computeSha1();
315 }
316
317 return $this->mSha1;
318 }
319
323 private function resetAggregateValues() {
324 $this->mSize = null;
325 $this->mSha1 = null;
326 }
327
328}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
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.
inheritSlot(SlotRecord $parentSlot)
"Inherits" the given slot's content.
getSha1()
Returns the base36 sha1 of this revision.
setUser(UserIdentity $user)
Sets the user identity associated with the revision.
getSize()
Returns the nominal size of this revision.
setContent( $role, Content $content)
Sets the content for the slot with the given role.
setSlot(SlotRecord $slot)
Sets the given slot.
setSize( $size)
Set nominal revision size, for optimization.
resetAggregateValues()
Invalidate cached aggregate values such as hash and size.
static newFromParentRevision(RevisionRecord $parent, CommentStoreComment $comment, UserIdentity $user, $timestamp)
Returns an incomplete MutableRevisionRecord which uses $parent as its parent revision,...
removeSlot( $role)
Removes the slot with the given role from this revision.
setSha1( $sha1)
Set revision hash, for optimization.
Mutable version of RevisionSlots, for constructing a new revision.
Page revision base class.
getSlot( $role, $audience=self::FOR_PUBLIC, User $user=null)
Returns meta-data for the given slot.
getSlotRoles()
Returns the slot names (roles) of all slots present in this revision.
getWikiId()
Get the ID of the wiki this revision belongs to.
getPageAsLinkTarget()
Returns the title of the page this revision is associated with as a LinkTarget object.
Value object representing a content slot associated with a page revision.
static newInherited(SlotRecord $slot)
Constructs a new SlotRecord for a new revision, inheriting the content of the given SlotRecord of a p...
hasRevision()
Whether this slot has revision ID associated.
getRevision()
Returns the ID of the revision this slot is associated with.
Represents a title within MediaWiki.
Definition Title.php:39
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:964
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:1777
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
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
Base interface for content objects.
Definition Content.php:34
Interface for objects representing user identity.