MediaWiki  master
MutableRevisionRecord.php
Go to the documentation of this file.
1 <?php
23 namespace MediaWiki\Revision;
24 
26 use Content;
31 use Title;
33 
42 
52  public static function newFromParentRevision( RevisionRecord $parent ) {
53  // TODO: ideally, we wouldn't need a Title here
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 
77  function __construct( Title $title, $dbDomain = false ) {
78  $slots = new MutableRevisionSlots();
79 
80  parent::__construct( $title, $slots, $dbDomain );
81 
82  $this->mSlots = $slots; // redundant, but nice for static analysis
83  }
84 
88  public function setParentId( $parentId ) {
89  Assert::parameterType( 'integer', $parentId, '$parentId' );
90 
91  $this->mParentId = $parentId;
92  }
93 
109  public function setSlot( SlotRecord $slot ) {
110  if ( $slot->hasRevision() && $slot->getRevision() !== $this->getId() ) {
111  throw new InvalidArgumentException(
112  'The given slot must be an unsaved, unattached one. '
113  . 'This slot is already attached to revision ' . $slot->getRevision() . '. '
114  . 'Use inheritSlot() instead to preserve a slot from a previous revision.'
115  );
116  }
117 
118  $this->mSlots->setSlot( $slot );
119  $this->resetAggregateValues();
120  }
121 
131  public function inheritSlot( SlotRecord $parentSlot ) {
132  $this->mSlots->inheritSlot( $parentSlot );
133  $this->resetAggregateValues();
134  }
135 
150  public function setContent( $role, Content $content ) {
151  $this->mSlots->setContent( $role, $content );
152  $this->resetAggregateValues();
153  }
154 
167  public function removeSlot( $role ) {
168  $this->mSlots->removeSlot( $role );
169  $this->resetAggregateValues();
170  }
171 
177  public function applyUpdate( RevisionSlotsUpdate $update ) {
178  $update->apply( $this->mSlots );
179  }
180 
184  public function setComment( CommentStoreComment $comment ) {
185  $this->mComment = $comment;
186  }
187 
197  public function setSha1( $sha1 ) {
198  Assert::parameterType( 'string', $sha1, '$sha1' );
199 
200  $this->mSha1 = $sha1;
201  }
202 
212  public function setSize( $size ) {
213  Assert::parameterType( 'integer', $size, '$size' );
214 
215  $this->mSize = $size;
216  }
217 
221  public function setVisibility( $visibility ) {
222  Assert::parameterType( 'integer', $visibility, '$visibility' );
223 
224  $this->mDeleted = $visibility;
225  }
226 
230  public function setTimestamp( $timestamp ) {
231  Assert::parameterType( 'string', $timestamp, '$timestamp' );
232 
233  $this->mTimestamp = wfTimestamp( TS_MW, $timestamp );
234  }
235 
239  public function setMinorEdit( $minorEdit ) {
240  Assert::parameterType( 'boolean', $minorEdit, '$minorEdit' );
241 
242  $this->mMinorEdit = $minorEdit;
243  }
244 
256  public function setId( $id ) {
257  Assert::parameterType( 'integer', $id, '$id' );
258 
259  $this->mId = $id;
260  }
261 
267  public function setUser( UserIdentity $user ) {
268  $this->mUser = $user;
269  }
270 
274  public function setPageId( $pageId ) {
275  Assert::parameterType( 'integer', $pageId, '$pageId' );
276 
277  if ( $this->mTitle->exists() && $pageId !== $this->mTitle->getArticleID() ) {
278  throw new InvalidArgumentException(
279  'The given Title does not belong to page ID ' . $this->mPageId
280  );
281  }
282 
283  $this->mPageId = $pageId;
284  }
285 
293  public function getSize() {
294  // If not known, re-calculate and remember. Will be reset when slots change.
295  if ( $this->mSize === null ) {
296  $this->mSize = $this->mSlots->computeSize();
297  }
298 
299  return $this->mSize;
300  }
301 
309  public function getSha1() {
310  // If not known, re-calculate and remember. Will be reset when slots change.
311  if ( $this->mSha1 === null ) {
312  $this->mSha1 = $this->mSlots->computeSha1();
313  }
314 
315  return $this->mSha1;
316  }
317 
324  public function getSlots() {
325  // Overwritten just guarantee the more narrow return type.
326  return parent::getSlots();
327  }
328 
332  private function resetAggregateValues() {
333  $this->mSize = null;
334  $this->mSha1 = null;
335  }
336 
337 }
338 
343 class_alias( MutableRevisionRecord::class, 'MediaWiki\Storage\MutableRevisionRecord' );
applyUpdate(RevisionSlotsUpdate $update)
Applies the given update to the slots of this revision.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
resetAggregateValues()
Invalidate cached aggregate values such as hash and size.
Value object representing a content slot associated with a page revision.
Definition: SlotRecord.php:39
Mutable RevisionRecord implementation, for building new revision entries programmatically.
Created by PhpStorm.
getSize()
Returns the nominal size of this revision.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
setSlot(SlotRecord $slot)
Sets the given slot.
setSize( $size)
Set nominal revision size, for optimization.
getPageAsLinkTarget()
Returns the title of the page this revision is associated with as a LinkTarget object.
getSlotRoles()
Returns the slot names (roles) of all slots present in this revision.
setComment(CommentStoreComment $comment)
getSlots()
Returns the slots defined for this revision as a MutableRevisionSlots instance, which can be modified...
getSha1()
Returns the base36 sha1 of this revision.
getRevision()
Returns the ID of the revision this slot is associated with.
Definition: SlotRecord.php:396
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:767
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:912
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:1748
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:9
static newFromParentRevision(RevisionRecord $parent)
Returns an incomplete MutableRevisionRecord which uses $parent as its parent revision, and inherits all slots form it.
setSha1( $sha1)
Set revision hash, for optimization.
static newFromLinkTarget(LinkTarget $linkTarget, $forceClone='')
Returns a Title given a LinkTarget.
Definition: Title.php:273
inheritSlot(SlotRecord $parentSlot)
"Inherits" the given slot&#39;s content.
getSlot( $role, $audience=self::FOR_PUBLIC, User $user=null)
Returns meta-data for the given slot.
getId()
Get revision ID.
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:35
setId( $id)
Set the revision ID.
hasRevision()
Whether this slot has revision ID associated.
Definition: SlotRecord.php:480
$parent
Definition: pageupdater.txt:71
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
removeSlot( $role)
Removes the slot with the given role from this revision.
getWikiId()
Get the ID of the wiki this revision belongs to.
setUser(UserIdentity $user)
Sets the user identity associated with the revision.
Page revision base class.
Mutable version of RevisionSlots, for constructing a new revision.
__construct(Title $title, $dbDomain=false)
$content
Definition: pageupdater.txt:72
setContent( $role, Content $content)
Sets the content for the slot with the given role.
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1454
getPageId()
Get the page ID.