MediaWiki  REL1_31
MutableRevisionRecord.php
Go to the documentation of this file.
1 <?php
23 namespace MediaWiki\Storage;
24 
26 use Content;
27 use InvalidArgumentException;
30 use Title;
31 use Wikimedia\Assert\Assert;
32 
40 
53  public static function newFromParentRevision(
54  RevisionRecord $parent,
55  CommentStoreComment $comment,
57  $timestamp
58  ) {
59  // TODO: ideally, we wouldn't need a Title here
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 }
MediaWiki\Storage\MutableRevisionRecord\getSize
getSize()
Returns the nominal size of this revision.
Definition: MutableRevisionRecord.php:295
$user
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 account $user
Definition: hooks.txt:247
MediaWiki\Storage\MutableRevisionRecord\inheritSlot
inheritSlot(SlotRecord $parentSlot)
"Inherits" the given slot's content.
Definition: MutableRevisionRecord.php:142
use
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Definition: APACHE-LICENSE-2.0.txt:10
MediaWiki\Storage\SlotRecord\getRevision
getRevision()
Returns the ID of the revision this slot is associated with.
Definition: SlotRecord.php:390
MediaWiki\Storage\RevisionRecord\getSlot
getSlot( $role, $audience=self::FOR_PUBLIC, User $user=null)
Returns meta-data for the given slot.
Definition: RevisionRecord.php:189
MediaWiki\Storage\MutableRevisionRecord\setVisibility
setVisibility( $visibility)
Definition: MutableRevisionRecord.php:223
MediaWiki\Storage\RevisionRecord\$mSha1
string null $mSha1
Definition: RevisionRecord.php:76
MediaWiki\Storage\MutableRevisionRecord\setParentId
setParentId( $parentId)
Definition: MutableRevisionRecord.php:99
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1980
MediaWiki\Storage\MutableRevisionRecord\setId
setId( $id)
Set the revision ID.
Definition: MutableRevisionRecord.php:258
MediaWiki\Storage\RevisionRecord\getWikiId
getWikiId()
Get the ID of the wiki this revision belongs to.
Definition: RevisionRecord.php:290
MediaWiki\Storage\MutableRevisionRecord\resetAggregateValues
resetAggregateValues()
Invalidate cached aggregate values such as hash and size.
Definition: MutableRevisionRecord.php:323
MediaWiki\User\UserIdentity
Interface for objects representing user identity.
Definition: UserIdentity.php:32
php
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
MediaWiki\Storage\MutableRevisionRecord\getSha1
getSha1()
Returns the base36 sha1 of this revision.
Definition: MutableRevisionRecord.php:311
MediaWiki\Storage\MutableRevisionRecord\setComment
setComment(CommentStoreComment $comment)
Definition: MutableRevisionRecord.php:186
MediaWiki\Storage\MutableRevisionRecord\setUser
setUser(UserIdentity $user)
Sets the user identity associated with the revision.
Definition: MutableRevisionRecord.php:269
MWException
MediaWiki exception.
Definition: MWException.php:26
MediaWiki\Storage\RevisionRecord\getSlotRoles
getSlotRoles()
Returns the slot names (roles) of all slots present in this revision.
Definition: RevisionRecord.php:216
MediaWiki\Storage\MutableRevisionRecord\__construct
__construct(Title $title, $wikiId=false)
Definition: MutableRevisionRecord.php:88
Title\newFromLinkTarget
static newFromLinkTarget(LinkTarget $linkTarget)
Create a new Title from a LinkTarget.
Definition: Title.php:244
MediaWiki\Storage\MutableRevisionRecord\setContent
setContent( $role, Content $content)
Sets the content for the slot with the given role.
Definition: MutableRevisionRecord.php:161
MediaWiki\Storage\SlotRecord\newInherited
static newInherited(SlotRecord $slot)
Constructs a new SlotRecord for a new revision, inheriting the content of the given SlotRecord of a p...
Definition: SlotRecord.php:98
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:964
MediaWiki\Storage\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:44
MediaWiki\Storage\RevisionRecord\getPageAsLinkTarget
getPageAsLinkTarget()
Returns the title of the page this revision is associated with as a LinkTarget object.
Definition: RevisionRecord.php:301
MediaWiki\Storage\MutableRevisionRecord\setSha1
setSha1( $sha1)
Set revision hash, for optimization.
Definition: MutableRevisionRecord.php:199
MediaWiki\Storage\RevisionRecord\$mSize
int null $mSize
Definition: RevisionRecord.php:74
MediaWiki\Storage\SlotRecord\hasRevision
hasRevision()
Whether this slot has revision ID associated.
Definition: SlotRecord.php:440
MediaWiki\Storage\MutableRevisionRecord\setSlot
setSlot(SlotRecord $slot)
Sets the given slot.
Definition: MutableRevisionRecord.php:120
MediaWiki\Storage\MutableRevisionRecord\setMinorEdit
setMinorEdit( $minorEdit)
Definition: MutableRevisionRecord.php:241
MediaWiki\Storage
Definition: BlobAccessException.php:23
Content
Base interface for content objects.
Definition: Content.php:34
MediaWiki\Storage\MutableRevisionRecord\removeSlot
removeSlot( $role)
Removes the slot with the given role from this revision.
Definition: MutableRevisionRecord.php:178
$rev
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
Title
Represents a title within MediaWiki.
Definition: Title.php:39
MediaWiki\Storage\MutableRevisionRecord
Mutable RevisionRecord implementation, for building new revision entries programmatically.
Definition: MutableRevisionRecord.php:39
MediaWiki\Storage\MutableRevisionRecord\newFromParentRevision
static newFromParentRevision(RevisionRecord $parent, CommentStoreComment $comment, UserIdentity $user, $timestamp)
Returns an incomplete MutableRevisionRecord which uses $parent as its parent revision,...
Definition: MutableRevisionRecord.php:53
MediaWiki\Storage\SlotRecord
Value object representing a content slot associated with a page revision.
Definition: SlotRecord.php:38
as
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
Definition: distributors.txt:22
MediaWiki\Storage\MutableRevisionRecord\setSize
setSize( $size)
Set nominal revision size, for optimization.
Definition: MutableRevisionRecord.php:214
MediaWiki\Storage\MutableRevisionRecord\setTimestamp
setTimestamp( $timestamp)
Definition: MutableRevisionRecord.php:232
MediaWiki\Storage\RevisionRecord\getId
getId()
Get revision ID.
Definition: RevisionRecord.php:229
MediaWiki\Storage\MutableRevisionSlots
Mutable version of RevisionSlots, for constructing a new revision.
Definition: MutableRevisionSlots.php:32
MediaWiki\Storage\MutableRevisionRecord\setPageId
setPageId( $pageId)
Definition: MutableRevisionRecord.php:276
CommentStoreComment
CommentStoreComment represents a comment stored by CommentStore.
Definition: CommentStoreComment.php:28
MediaWiki\Storage\RevisionRecord\getPageId
getPageId()
Get the page ID.
Definition: RevisionRecord.php:281