MediaWiki REL1_31
MediaWiki\Storage\SlotRecord Class Reference

Value object representing a content slot associated with a page revision. More...

Collaboration diagram for MediaWiki\Storage\SlotRecord:

Public Member Functions

 __construct ( $row, $content)
 SlotRecord constructor.
 
 __sleep ()
 Implemented to defy serialization.
 
 getAddress ()
 Returns the address of this slot's content.
 
 getContent ()
 Returns the Content of the given slot.
 
 getContentId ()
 Returns the ID of the content meta data row associated with the slot.
 
 getFormat ()
 Returns the blob serialization format as a MIME type.
 
 getModel ()
 Returns the content model.
 
 getOrigin ()
 Returns the revision ID of the revision that originated the slot's content.
 
 getRevision ()
 Returns the ID of the revision this slot is associated with.
 
 getRole ()
 Returns the role of the slot.
 
 getSha1 ()
 Returns the content size.
 
 getSize ()
 Returns the content size.
 
 hasAddress ()
 Whether this slot has an address.
 
 hasRevision ()
 Whether this slot has revision ID associated.
 
 isInherited ()
 Whether this slot was inherited from an older revision.
 

Static Public Member Functions

static base36Sha1 ( $blob)
 Get the base 36 SHA-1 value for a string of text.
 
static newInherited (SlotRecord $slot)
 Constructs a new SlotRecord for a new revision, inheriting the content of the given SlotRecord of a previous revision.
 
static newSaved ( $revisionId, $contentId, $contentAddress, SlotRecord $protoSlot)
 Constructs a complete SlotRecord for a newly saved revision, based on the incomplete proto-slot.
 
static newUnsaved ( $role, Content $content)
 Constructs a new Slot from a Content object for a new revision.
 
static newWithSuppressedContent (SlotRecord $slot)
 Returns a new SlotRecord just like the given $slot, except that calling getContent() will fail with an exception.
 

Private Member Functions

 getField ( $name)
 Returns the string value of a data field from the database row supplied to the constructor.
 
 getIntField ( $name)
 Returns the int value of a data field from the database row supplied to the constructor.
 
 getStringField ( $name)
 Returns the string value of a data field from the database row supplied to the constructor.
 
 hasField ( $name)
 
 setField ( $name, $value)
 

Static Private Member Functions

static newDerived (SlotRecord $slot, array $overrides=[])
 Constructs a new SlotRecord from an existing SlotRecord, overriding some fields.
 

Private Attributes

Content callable $content
 
object $row
 database result row, as a raw object
 

Detailed Description

Value object representing a content slot associated with a page revision.

SlotRecord provides direct access to a Content object. That access may be implemented through a callback.

Since
1.31

Definition at line 38 of file SlotRecord.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Storage\SlotRecord::__construct (   $row,
  $content 
)

SlotRecord constructor.

The following fields are supported by the $row parameter:

$row->blob_data $row->blob_address

Parameters
object$rowA database row composed of fields of the slot and content tables, as a raw object. Any field value can be a callback that produces the field value given this SlotRecord as a parameter. However, plain strings cannot be used as callbacks here, for security reasons.
Content | callable$contentThe content object associated with the slot, or a callback that will return that Content object, given this SlotRecord as a parameter.

Definition at line 230 of file SlotRecord.php.

References MediaWiki\Storage\SlotRecord\$content, MediaWiki\Storage\SlotRecord\$row, and content.

Member Function Documentation

◆ __sleep()

MediaWiki\Storage\SlotRecord::__sleep ( )

Implemented to defy serialization.

Exceptions
LogicExceptionalways

Definition at line 284 of file SlotRecord.php.

◆ base36Sha1()

static MediaWiki\Storage\SlotRecord::base36Sha1 (   $blob)
static

Get the base 36 SHA-1 value for a string of text.

MCR migration note: this replaces Revision::base36Sha1

Parameters
string$blob
Returns
string

Definition at line 564 of file SlotRecord.php.

References $blob.

Referenced by MediaWiki\Storage\RevisionSlots\computeSha1(), and MediaWiki\Storage\SlotRecord\getSha1().

◆ getAddress()

MediaWiki\Storage\SlotRecord::getAddress ( )

Returns the address of this slot's content.

This address can be used with BlobStore to load the Content object.

Returns
string

Definition at line 459 of file SlotRecord.php.

References MediaWiki\Storage\SlotRecord\getStringField().

Referenced by MediaWiki\Storage\RevisionStore\loadSlotContent(), MediaWiki\Storage\SlotRecord\newInherited(), and MediaWiki\Storage\SlotRecord\newSaved().

◆ getContent()

MediaWiki\Storage\SlotRecord::getContent ( )

Returns the Content of the given slot.

Note
This is free to load Content from whatever subsystem is necessary, performing potentially expensive operations and triggering I/O-related failure modes.
This method does not apply audience filtering.
Exceptions
SuppressedDataExceptionif access to the content is not allowed according to the audience check performed by RevisionRecord::getSlot().
Returns
Content The slot's content. This is a direct reference to the internal instance, copy before exposing to application logic!

Definition at line 303 of file SlotRecord.php.

References MediaWiki\Storage\SlotRecord\$content, and content.

Referenced by MediaWiki\Tests\Storage\RevisionStoreDbTest\assertSlotRecordsEqual(), MediaWiki\Storage\SlotRecord\getModel(), MediaWiki\Storage\SlotRecord\getSha1(), and MediaWiki\Storage\SlotRecord\getSize().

◆ getContentId()

MediaWiki\Storage\SlotRecord::getContentId ( )

Returns the ID of the content meta data row associated with the slot.

This information should be irrelevant to application logic, it is here to allow the construction of a full row for the revision table.

Returns
int

Definition at line 470 of file SlotRecord.php.

References MediaWiki\Storage\SlotRecord\getIntField().

Referenced by MediaWiki\Storage\SlotRecord\newSaved().

◆ getField()

MediaWiki\Storage\SlotRecord::getField (   $name)
private

Returns the string value of a data field from the database row supplied to the constructor.

If the field was set to a callback, that callback is invoked and the result returned.

Parameters
string$name
Exceptions
OutOfBoundsException
IncompleteRevisionException
Returns
mixed Returns the field's value, never null.

Definition at line 330 of file SlotRecord.php.

References $name, $value, and MediaWiki\Storage\SlotRecord\setField().

Referenced by MediaWiki\Storage\SlotRecord\getIntField(), and MediaWiki\Storage\SlotRecord\getStringField().

◆ getFormat()

MediaWiki\Storage\SlotRecord::getFormat ( )

Returns the blob serialization format as a MIME type.

Note
When this method returns null, the caller is expected to auto-detect the serialization format, or to rely on the default format associated with the content model.
Returns
string|null

Definition at line 538 of file SlotRecord.php.

References MediaWiki\Storage\SlotRecord\getStringField(), and MediaWiki\Storage\SlotRecord\hasField().

Referenced by MediaWiki\Tests\Storage\RevisionStoreDbTest\assertSlotRecordsEqual().

◆ getIntField()

MediaWiki\Storage\SlotRecord::getIntField (   $name)
private

Returns the int value of a data field from the database row supplied to the constructor.

Parameters
string$name
Exceptions
OutOfBoundsException
IncompleteRevisionException
Returns
int Returns the int value

Definition at line 373 of file SlotRecord.php.

References $name, and MediaWiki\Storage\SlotRecord\getField().

Referenced by MediaWiki\Storage\SlotRecord\getContentId(), MediaWiki\Storage\SlotRecord\getOrigin(), MediaWiki\Storage\SlotRecord\getRevision(), and MediaWiki\Storage\SlotRecord\getSize().

◆ getModel()

MediaWiki\Storage\SlotRecord::getModel ( )

Returns the content model.

This is the model name that decides which ContentHandler is appropriate for interpreting the data of the blob referenced by the address returned by getAddress().

Returns
string the content model of the content

Definition at line 518 of file SlotRecord.php.

References MediaWiki\Storage\SlotRecord\getContent(), MediaWiki\Storage\SlotRecord\getStringField(), and MediaWiki\Storage\SlotRecord\setField().

Referenced by MediaWiki\Tests\Storage\RevisionStoreDbTest\assertSlotRecordsEqual(), and MediaWiki\Storage\RevisionStore\loadSlotContent().

◆ getOrigin()

MediaWiki\Storage\SlotRecord::getOrigin ( )

◆ getRevision()

◆ getRole()

MediaWiki\Storage\SlotRecord::getRole ( )

◆ getSha1()

◆ getSize()

MediaWiki\Storage\SlotRecord::getSize ( )

Returns the content size.

Returns
int size of the content, in bogo-bytes, as reported by Content::getSize.

Definition at line 479 of file SlotRecord.php.

References MediaWiki\Storage\SlotRecord\getContent(), MediaWiki\Storage\SlotRecord\getIntField(), and MediaWiki\Storage\SlotRecord\setField().

Referenced by MediaWiki\Tests\Storage\RevisionStoreDbTest\assertSlotRecordsEqual(), and MediaWiki\Storage\RevisionSlots\computeSize().

◆ getStringField()

MediaWiki\Storage\SlotRecord::getStringField (   $name)
private

Returns the string value of a data field from the database row supplied to the constructor.

Parameters
string$name
Exceptions
OutOfBoundsException
IncompleteRevisionException
Returns
string Returns the string value

Definition at line 360 of file SlotRecord.php.

References $name, and MediaWiki\Storage\SlotRecord\getField().

Referenced by MediaWiki\Storage\SlotRecord\getAddress(), MediaWiki\Storage\SlotRecord\getFormat(), MediaWiki\Storage\SlotRecord\getModel(), MediaWiki\Storage\SlotRecord\getRole(), and MediaWiki\Storage\SlotRecord\getSha1().

◆ hasAddress()

MediaWiki\Storage\SlotRecord::hasAddress ( )

Whether this slot has an address.

Slots will have an address if their content has been stored. While building a new revision, SlotRecords will not have an address associated.

Returns
bool

Definition at line 429 of file SlotRecord.php.

References MediaWiki\Storage\SlotRecord\hasField().

Referenced by MediaWiki\Tests\Storage\RevisionStoreDbTest\assertSlotCompleteness(), MediaWiki\Tests\Storage\RevisionStoreDbTest\assertSlotRecordsEqual(), MediaWiki\Storage\SlotRecord\isInherited(), MediaWiki\Storage\RevisionStore\loadSlotContent(), and MediaWiki\Storage\SlotRecord\newSaved().

◆ hasField()

MediaWiki\Storage\SlotRecord::hasField (   $name)
private

◆ hasRevision()

MediaWiki\Storage\SlotRecord::hasRevision ( )

Whether this slot has revision ID associated.

Slots will have a revision ID associated only if they were loaded as part of an existing revision. While building a new revision, Slotrecords will not have a revision ID associated.

Returns
bool

Definition at line 440 of file SlotRecord.php.

References MediaWiki\Storage\SlotRecord\hasField().

Referenced by MediaWiki\Tests\Storage\RevisionStoreDbTest\assertSlotRecordsEqual(), MediaWiki\Storage\SlotRecord\isInherited(), MediaWiki\Storage\SlotRecord\newSaved(), and MediaWiki\Storage\MutableRevisionRecord\setSlot().

◆ isInherited()

MediaWiki\Storage\SlotRecord::isInherited ( )

Whether this slot was inherited from an older revision.

If this SlotRecord is already attached to a revision, this returns true if the slot's revision of origin is the same as the revision it belongs to.

If this SlotRecord is not yet attached to a revision, this returns true if the slot already has an address.

Returns
bool

Definition at line 414 of file SlotRecord.php.

References MediaWiki\Storage\SlotRecord\getOrigin(), MediaWiki\Storage\SlotRecord\getRevision(), MediaWiki\Storage\SlotRecord\hasAddress(), and MediaWiki\Storage\SlotRecord\hasRevision().

Referenced by MediaWiki\Storage\MutableRevisionSlots\getInheritedSlots(), MediaWiki\Storage\MutableRevisionSlots\getTouchedSlots(), and MediaWiki\Storage\SlotRecord\newSaved().

◆ newDerived()

static MediaWiki\Storage\SlotRecord::newDerived ( SlotRecord  $slot,
array  $overrides = [] 
)
staticprivate

Constructs a new SlotRecord from an existing SlotRecord, overriding some fields.

The slot's content cannot be overwritten.

Parameters
SlotRecord$slot
array$overrides
Returns
SlotRecord

Definition at line 75 of file SlotRecord.php.

References MediaWiki\Storage\SlotRecord\$row, $value, and as.

Referenced by MediaWiki\Storage\SlotRecord\newInherited(), and MediaWiki\Storage\SlotRecord\newSaved().

◆ newInherited()

static MediaWiki\Storage\SlotRecord::newInherited ( SlotRecord  $slot)
static

Constructs a new SlotRecord for a new revision, inheriting the content of the given SlotRecord of a previous revision.

Note that a SlotRecord constructed this way are intended as prototypes, to be used wit newSaved(). They are incomplete, so some getters such as getRevision() will fail.

Parameters
SlotRecord$slot
Returns
SlotRecord

Definition at line 98 of file SlotRecord.php.

References MediaWiki\Storage\SlotRecord\getAddress(), MediaWiki\Storage\SlotRecord\getOrigin(), MediaWiki\Storage\SlotRecord\getRevision(), and MediaWiki\Storage\SlotRecord\newDerived().

Referenced by MediaWiki\Storage\MutableRevisionRecord\inheritSlot(), and MediaWiki\Storage\MutableRevisionSlots\newFromParentRevisionSlots().

◆ newSaved()

static MediaWiki\Storage\SlotRecord::newSaved (   $revisionId,
  $contentId,
  $contentAddress,
SlotRecord  $protoSlot 
)
static

Constructs a complete SlotRecord for a newly saved revision, based on the incomplete proto-slot.

This adds information that has only become available during saving, particularly the revision ID and content address.

Parameters
int$revisionIdthe revision the slot is to be associated with (field slot_revision_id). If $protoSlot already has a revision, it must be the same.
int$contentIdthe ID of the row in the content table describing the content referenced by $contentAddress (field slot_content_id). If $protoSlot already has a content ID, it must be the same.
string$contentAddressthe slot's content address (field content_address). If $protoSlot already has an address, it must be the same.
SlotRecord$protoSlotThe proto-slot that was provided as input for creating a new revision. $protoSlot must have a content address if inherited.
Returns
SlotRecord If the state of $protoSlot is inappropriate for saving a new revision.

Definition at line 159 of file SlotRecord.php.

References MediaWiki\Storage\SlotRecord\getAddress(), MediaWiki\Storage\SlotRecord\getContentId(), MediaWiki\Storage\SlotRecord\getOrigin(), MediaWiki\Storage\SlotRecord\getRevision(), MediaWiki\Storage\SlotRecord\hasAddress(), MediaWiki\Storage\SlotRecord\hasField(), MediaWiki\Storage\SlotRecord\hasRevision(), MediaWiki\Storage\SlotRecord\isInherited(), and MediaWiki\Storage\SlotRecord\newDerived().

Referenced by MediaWiki\Storage\RevisionStore\insertRevisionOn().

◆ newUnsaved()

static MediaWiki\Storage\SlotRecord::newUnsaved (   $role,
Content  $content 
)
static

Constructs a new Slot from a Content object for a new revision.

This is the preferred way to construct a slot for storing Content that resulted from a user edit. The slot is assumed to be not inherited.

Note that a SlotRecord constructed this way are intended as prototypes, to be used wit newSaved(). They are incomplete, so some getters such as getAddress() will fail.

Parameters
string$role
Content$content
Returns
SlotRecord An incomplete proto-slot object, to be used with newSaved() later.

Definition at line 124 of file SlotRecord.php.

References MediaWiki\Storage\SlotRecord\$content, MediaWiki\Storage\SlotRecord\$row, and Content\getModel().

Referenced by MediaWiki\Storage\MutableRevisionSlots\setContent().

◆ newWithSuppressedContent()

static MediaWiki\Storage\SlotRecord::newWithSuppressedContent ( SlotRecord  $slot)
static

Returns a new SlotRecord just like the given $slot, except that calling getContent() will fail with an exception.

Parameters
SlotRecord$slot
Returns
SlotRecord

Definition at line 58 of file SlotRecord.php.

References MediaWiki\Storage\SlotRecord\$row.

Referenced by MediaWiki\Storage\RevisionRecord\getSlot().

◆ setField()

MediaWiki\Storage\SlotRecord::setField (   $name,
  $value 
)
private
Parameters
string$name
string | int | null$value

Definition at line 552 of file SlotRecord.php.

References $value.

Referenced by MediaWiki\Storage\SlotRecord\getField(), MediaWiki\Storage\SlotRecord\getModel(), MediaWiki\Storage\SlotRecord\getSha1(), and MediaWiki\Storage\SlotRecord\getSize().

Member Data Documentation

◆ $content

Content callable MediaWiki\Storage\SlotRecord::$content
private

◆ $row

object MediaWiki\Storage\SlotRecord::$row
private

The documentation for this class was generated from the following file: