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 
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 
344 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:780
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
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:1766
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:271
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
__construct(Title $title, $wikiId=false)
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.
$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:1473
getPageId()
Get the page ID.