MediaWiki  1.33.0
MutableRevisionRecord.php
Go to the documentation of this file.
1 <?php
23 namespace MediaWiki\Revision;
24 
26 use Content;
27 use InvalidArgumentException;
31 use Title;
32 use 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 
344 class_alias( MutableRevisionRecord::class, 'MediaWiki\Storage\MutableRevisionRecord' );
Revision\MutableRevisionRecord\getSlots
getSlots()
Returns the slots defined for this revision as a MutableRevisionSlots instance, which can be modified...
Definition: MutableRevisionRecord.php:325
Revision\MutableRevisionRecord\setMinorEdit
setMinorEdit( $minorEdit)
Definition: MutableRevisionRecord.php:240
$user
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1476
Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:45
Revision\MutableRevisionRecord\setSha1
setSha1( $sha1)
Set revision hash, for optimization.
Definition: MutableRevisionRecord.php:198
Revision\MutableRevisionRecord\setParentId
setParentId( $parentId)
Definition: MutableRevisionRecord.php:89
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1912
Revision\MutableRevisionRecord\inheritSlot
inheritSlot(SlotRecord $parentSlot)
"Inherits" the given slot's content.
Definition: MutableRevisionRecord.php:132
Revision\MutableRevisionRecord\newFromParentRevision
static newFromParentRevision(RevisionRecord $parent)
Returns an incomplete MutableRevisionRecord which uses $parent as its parent revision,...
Definition: MutableRevisionRecord.php:52
Revision\MutableRevisionRecord\setPageId
setPageId( $pageId)
Definition: MutableRevisionRecord.php:275
Revision\MutableRevisionRecord\__construct
__construct(Title $title, $wikiId=false)
Definition: MutableRevisionRecord.php:78
Revision\MutableRevisionRecord\setId
setId( $id)
Set the revision ID.
Definition: MutableRevisionRecord.php:257
Revision\MutableRevisionSlots
Mutable version of RevisionSlots, for constructing a new revision.
Definition: MutableRevisionSlots.php:33
Revision\SlotRecord\getRevision
getRevision()
Returns the ID of the revision this slot is associated with.
Definition: SlotRecord.php:396
Revision\MutableRevisionRecord\removeSlot
removeSlot( $role)
Removes the slot with the given role from this revision.
Definition: MutableRevisionRecord.php:168
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:35
MediaWiki\Revision
Created by PhpStorm.
Definition: FallbackSlotRoleHandler.php:23
MWException
MediaWiki exception.
Definition: MWException.php:26
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
Revision\MutableRevisionRecord\setUser
setUser(UserIdentity $user)
Sets the user identity associated with the revision.
Definition: MutableRevisionRecord.php:268
Revision\MutableRevisionRecord\applyUpdate
applyUpdate(RevisionSlotsUpdate $update)
Applies the given update to the slots of this revision.
Definition: MutableRevisionRecord.php:178
Revision\MutableRevisionRecord\setVisibility
setVisibility( $visibility)
Definition: MutableRevisionRecord.php:222
Revision\MutableRevisionRecord\setContent
setContent( $role, Content $content)
Sets the content for the slot with the given role.
Definition: MutableRevisionRecord.php:151
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
Revision\SlotRecord\hasRevision
hasRevision()
Whether this slot has revision ID associated.
Definition: SlotRecord.php:480
Revision\RevisionRecord\getId
getId()
Get revision ID.
Definition: RevisionRecord.php:273
MediaWiki\Storage\RevisionSlotsUpdate
Value object representing a modification of revision slots.
Definition: RevisionSlotsUpdate.php:36
Revision\MutableRevisionRecord
Mutable RevisionRecord implementation, for building new revision entries programmatically.
Definition: MutableRevisionRecord.php:41
Revision\RevisionRecord\$mSize
int null $mSize
Definition: RevisionRecord.php:76
Title\newFromLinkTarget
static newFromLinkTarget(LinkTarget $linkTarget, $forceClone='')
Returns a Title given a LinkTarget.
Definition: Title.php:269
Revision\MutableRevisionRecord\resetAggregateValues
resetAggregateValues()
Invalidate cached aggregate values such as hash and size.
Definition: MutableRevisionRecord.php:333
Content
Base interface for content objects.
Definition: Content.php:34
$parent
$parent
Definition: pageupdater.txt:71
Title
Represents a title within MediaWiki.
Definition: Title.php:40
$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:1769
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:9
$content
$content
Definition: pageupdater.txt:72
Revision\MutableRevisionRecord\setSlot
setSlot(SlotRecord $slot)
Sets the given slot.
Definition: MutableRevisionRecord.php:110
Revision\MutableRevisionRecord\getSha1
getSha1()
Returns the base36 sha1 of this revision.
Definition: MutableRevisionRecord.php:310
Revision\MutableRevisionRecord\setTimestamp
setTimestamp( $timestamp)
Definition: MutableRevisionRecord.php:231
class
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
Revision\MutableRevisionRecord\setSize
setSize( $size)
Set nominal revision size, for optimization.
Definition: MutableRevisionRecord.php:213
Revision\MutableRevisionRecord\getSize
getSize()
Returns the nominal size of this revision.
Definition: MutableRevisionRecord.php:294
Revision\RevisionRecord\$mSha1
string null $mSha1
Definition: RevisionRecord.php:78
CommentStoreComment
CommentStoreComment represents a comment stored by CommentStore.
Definition: CommentStoreComment.php:29
Revision\MutableRevisionRecord\setComment
setComment(CommentStoreComment $comment)
Definition: MutableRevisionRecord.php:185
Revision\SlotRecord
Value object representing a content slot associated with a page revision.
Definition: SlotRecord.php:39