MediaWiki REL1_37
|
Value object representing a content slot associated with a page revision. More...
Public Member Functions | |
__construct (\stdClass $row, $content, bool $derived=false) | |
The following fields are supported by the $row parameter: | |
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. | |
hasContentId () | |
Whether this slot has a content ID. | |
hasOrigin () | |
Whether this slot has an origin (revision ID that originated the slot's content. | |
hasRevision () | |
Whether this slot has revision ID associated. | |
hasSameContent (SlotRecord $other) | |
Returns true if $other has the same content as this slot. | |
isDerived () | |
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 | newDerived (string $role, Content $content) |
Returns a SlotRecord for a derived slot. | |
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 (int $revisionId, ?int $contentId, string $contentAddress, SlotRecord $protoSlot) |
Constructs a complete SlotRecord for a newly saved revision, based on the incomplete proto-slot. | |
static | newUnsaved (string $role, Content $content, bool $derived=false) |
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. | |
Public Attributes | |
const | MAIN = 'main' |
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 | newFromSlotRecord (SlotRecord $slot, array $overrides=[]) |
Constructs a new SlotRecord from an existing SlotRecord, overriding some fields. | |
Private Attributes | |
Content callable | $content |
bool | $derived |
stdClass | $row |
database result row, as a raw object. | |
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.
Definition at line 40 of file SlotRecord.php.
MediaWiki\Revision\SlotRecord::__construct | ( | \stdClass | $row, |
$content, | |||
bool | $derived = false |
||
) |
The following fields are supported by the $row parameter:
$row->blob_data $row->blob_address
\\stdClass | $row | A 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 | $content | The content object associated with the slot, or a callback that will return that Content object, given this SlotRecord as a parameter. |
bool | $derived | Is this handler for a derived slot? Derived slots allow information that is derived from the content of a page to be stored even if it is generated asynchronously or updated later. Their size is not included in the revision size, their hash does not contribute to the revision hash, and updates are not included in revision history. |
Definition at line 258 of file SlotRecord.php.
References MediaWiki\Revision\SlotRecord\$content, MediaWiki\Revision\SlotRecord\$derived, and MediaWiki\Revision\SlotRecord\$row.
|
static |
Get the base 36 SHA-1 value for a string of text.
MCR migration note: this replaced Revision::base36Sha1
string | $blob |
Definition at line 630 of file SlotRecord.php.
References $blob.
Referenced by MediaWiki\Revision\SlotRecord\getSha1().
MediaWiki\Revision\SlotRecord::getAddress | ( | ) |
Returns the address of this slot's content.
This address can be used with BlobStore to load the Content object.
Definition at line 517 of file SlotRecord.php.
References MediaWiki\Revision\SlotRecord\getStringField().
Referenced by FindBadBlobs\checkSlot(), MediaWiki\Revision\SlotRecord\hasSameContent(), MediaWiki\Revision\RevisionStore\insertSlotOn(), MediaWiki\Revision\RevisionStore\loadSlotContent(), FindBadBlobs\markBlob(), MediaWiki\Revision\SlotRecord\newInherited(), MediaWiki\Revision\SlotRecord\newSaved(), and XmlDumpWriter\writeSlot().
MediaWiki\Revision\SlotRecord::getContent | ( | ) |
Returns the Content of the given slot.
SuppressedDataException | if access to the content is not allowed according to the audience check performed by RevisionRecord::getSlot(). |
Definition at line 317 of file SlotRecord.php.
References MediaWiki\Revision\SlotRecord\$content.
Referenced by ApiQueryRevisionsBase\extractSlotInfo(), MediaWiki\Revision\SlotRecord\getModel(), MediaWiki\Revision\SlotRecord\getSha1(), MediaWiki\Revision\SlotRecord\getSize(), MediaWiki\Revision\RevisionStore\storeContentBlob(), and XmlDumpWriter\writeSlot().
MediaWiki\Revision\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.
Note that this method may return an emulated value during schema migration in SCHEMA_COMPAT_WRITE_OLD mode. See RevisionStore::emulateContentId for more information.
Definition at line 531 of file SlotRecord.php.
References MediaWiki\Revision\SlotRecord\getIntField().
Referenced by MediaWiki\Revision\RevisionStore\insertSlotOn(), FindBadBlobs\markBlob(), and MediaWiki\Revision\SlotRecord\newSaved().
|
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.
string | $name |
OutOfBoundsException | |
IncompleteRevisionException |
Definition at line 344 of file SlotRecord.php.
References MediaWiki\Revision\SlotRecord\setField().
Referenced by MediaWiki\Revision\SlotRecord\getIntField(), MediaWiki\Revision\SlotRecord\getStringField(), and MediaWiki\Revision\SlotRecord\hasField().
MediaWiki\Revision\SlotRecord::getFormat | ( | ) |
Returns the blob serialization format as a MIME type.
Definition at line 604 of file SlotRecord.php.
References MediaWiki\Revision\SlotRecord\getStringField(), and MediaWiki\Revision\SlotRecord\hasField().
|
private |
Returns the int value of a data field from the database row supplied to the constructor.
string | $name |
OutOfBoundsException | |
IncompleteRevisionException |
Definition at line 390 of file SlotRecord.php.
References MediaWiki\Revision\SlotRecord\getField().
Referenced by MediaWiki\Revision\SlotRecord\getContentId(), MediaWiki\Revision\SlotRecord\getOrigin(), MediaWiki\Revision\SlotRecord\getRevision(), and MediaWiki\Revision\SlotRecord\getSize().
MediaWiki\Revision\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().
Definition at line 584 of file SlotRecord.php.
References MediaWiki\Revision\SlotRecord\getContent(), MediaWiki\Revision\SlotRecord\getStringField(), and MediaWiki\Revision\SlotRecord\setField().
Referenced by ApiQueryRevisionsBase\extractSlotInfo(), MediaWiki\Revision\SlotRecord\hasSameContent(), MediaWiki\Revision\RevisionStore\insertContentRowOn(), MediaWiki\Revision\RevisionStore\loadSlotContent(), and XmlDumpWriter\writeSlot().
MediaWiki\Revision\SlotRecord::getOrigin | ( | ) |
Returns the revision ID of the revision that originated the slot's content.
Definition at line 423 of file SlotRecord.php.
References MediaWiki\Revision\SlotRecord\getIntField().
Referenced by MediaWiki\Revision\RevisionStore\insertSlotRowOn(), MediaWiki\Revision\SlotRecord\isInherited(), MediaWiki\Revision\SlotRecord\newInherited(), MediaWiki\Revision\SlotRecord\newSaved(), and XmlDumpWriter\writeSlot().
MediaWiki\Revision\SlotRecord::getRevision | ( | ) |
Returns the ID of the revision this slot is associated with.
Definition at line 414 of file SlotRecord.php.
References MediaWiki\Revision\SlotRecord\getIntField().
Referenced by MediaWiki\Revision\SlotRecord\isInherited(), MediaWiki\Revision\RevisionStore\loadSlotContent(), MediaWiki\Revision\SlotRecord\newInherited(), MediaWiki\Revision\SlotRecord\newSaved(), MediaWiki\Revision\MutableRevisionRecord\setSlot(), and XmlDumpWriter\writeSlot().
MediaWiki\Revision\SlotRecord::getRole | ( | ) |
Returns the role of the slot.
Definition at line 507 of file SlotRecord.php.
References MediaWiki\Revision\SlotRecord\getStringField().
Referenced by MediaWiki\Revision\RevisionStore\insertSlotRowOn(), MediaWiki\Revision\RevisionStore\loadSlotContent(), MediaWiki\Storage\RevisionSlotsUpdate\modifySlot(), MediaWiki\Revision\MutableRevisionSlots\setSlot(), MediaWiki\Storage\PageUpdater\setSlot(), MediaWiki\Revision\RevisionStore\storeContentBlob(), and XmlDumpWriter\writeSlot().
MediaWiki\Revision\SlotRecord::getSha1 | ( | ) |
Returns the content size.
Definition at line 556 of file SlotRecord.php.
References MediaWiki\Revision\SlotRecord\base36Sha1(), MediaWiki\Revision\SlotRecord\getContent(), MediaWiki\Revision\SlotRecord\getStringField(), MediaWiki\Revision\SlotRecord\hasField(), and MediaWiki\Revision\SlotRecord\setField().
Referenced by ApiQueryRevisionsBase\extractSlotInfo(), MediaWiki\Revision\SlotRecord\hasSameContent(), MediaWiki\Revision\RevisionStore\insertContentRowOn(), MediaWiki\Revision\RevisionStore\storeContentBlob(), and XmlDumpWriter\writeSlot().
MediaWiki\Revision\SlotRecord::getSize | ( | ) |
Returns the content size.
Definition at line 540 of file SlotRecord.php.
References MediaWiki\Revision\SlotRecord\getContent(), MediaWiki\Revision\SlotRecord\getIntField(), and MediaWiki\Revision\SlotRecord\setField().
Referenced by ApiQueryRevisionsBase\extractSlotInfo(), MediaWiki\Revision\SlotRecord\hasSameContent(), MediaWiki\Revision\RevisionStore\insertContentRowOn(), and XmlDumpWriter\writeSlot().
|
private |
Returns the string value of a data field from the database row supplied to the constructor.
string | $name |
OutOfBoundsException | |
IncompleteRevisionException |
Definition at line 377 of file SlotRecord.php.
References MediaWiki\Revision\SlotRecord\getField().
Referenced by MediaWiki\Revision\SlotRecord\getAddress(), MediaWiki\Revision\SlotRecord\getFormat(), MediaWiki\Revision\SlotRecord\getModel(), MediaWiki\Revision\SlotRecord\getRole(), and MediaWiki\Revision\SlotRecord\getSha1().
MediaWiki\Revision\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.
Definition at line 453 of file SlotRecord.php.
References MediaWiki\Revision\SlotRecord\hasField().
Referenced by MediaWiki\Revision\SlotRecord\hasSameContent(), MediaWiki\Revision\RevisionStore\insertSlotOn(), MediaWiki\Revision\SlotRecord\isInherited(), MediaWiki\Revision\RevisionStore\loadSlotContent(), and MediaWiki\Revision\SlotRecord\newSaved().
MediaWiki\Revision\SlotRecord::hasContentId | ( | ) |
Whether this slot has a content ID.
Slots will have a content ID if their content has been stored in the content table. While building a new revision, SlotRecords will not have an ID associated.
Also, during schema migration, hasContentId() may return false when encountering an un-migrated database entry in SCHEMA_COMPAT_WRITE_BOTH mode. It will however always return true for saved revisions on SCHEMA_COMPAT_READ_NEW mode, or without SCHEMA_COMPAT_WRITE_NEW mode. In the latter case, an emulated content ID is used, derived from the revision's text ID.
Note that hasContentId() returning false while hasRevision() returns true always indicates an unmigrated row in SCHEMA_COMPAT_WRITE_BOTH mode, as described above. For an unsaved slot, both these methods would return false.
Definition at line 487 of file SlotRecord.php.
References MediaWiki\Revision\SlotRecord\hasField().
Referenced by MediaWiki\Revision\RevisionStore\insertSlotOn(), and MediaWiki\Revision\SlotRecord\newSaved().
|
private |
string | $name |
Definition at line 398 of file SlotRecord.php.
References MediaWiki\Revision\SlotRecord\getField().
Referenced by MediaWiki\Revision\SlotRecord\getFormat(), MediaWiki\Revision\SlotRecord\getSha1(), MediaWiki\Revision\SlotRecord\hasAddress(), MediaWiki\Revision\SlotRecord\hasContentId(), MediaWiki\Revision\SlotRecord\hasOrigin(), MediaWiki\Revision\SlotRecord\hasRevision(), and MediaWiki\Revision\SlotRecord\newSaved().
MediaWiki\Revision\SlotRecord::hasOrigin | ( | ) |
Whether this slot has an origin (revision ID that originated the slot's content.
Definition at line 464 of file SlotRecord.php.
References MediaWiki\Revision\SlotRecord\hasField().
Referenced by MediaWiki\Revision\RevisionStore\insertSlotRowOn().
MediaWiki\Revision\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.
Definition at line 498 of file SlotRecord.php.
References MediaWiki\Revision\SlotRecord\hasField().
Referenced by MediaWiki\Revision\SlotRecord\isInherited(), MediaWiki\Revision\SlotRecord\newSaved(), and MediaWiki\Revision\MutableRevisionRecord\setSlot().
MediaWiki\Revision\SlotRecord::hasSameContent | ( | SlotRecord | $other | ) |
Returns true if $other has the same content as this slot.
The check is performed based on the model, address size, and hash. Two slots can have the same content if they use different content addresses, but if they have the same address and the same model, they have the same content. Two slots can have the same content if they belong to different revisions or pages.
Note that hasSameContent() may return false even if Content::equals returns true for the content of two slots. This may happen if the two slots have different serializations representing equivalent Content. Such false negatives are considered acceptable. Code that has to be absolutely sure the Content is really not the same if hasSameContent() returns false should call getContent() and compare the Content objects directly.
SlotRecord | $other |
Definition at line 653 of file SlotRecord.php.
References MediaWiki\Revision\SlotRecord\getAddress(), MediaWiki\Revision\SlotRecord\getModel(), MediaWiki\Revision\SlotRecord\getSha1(), MediaWiki\Revision\SlotRecord\getSize(), and MediaWiki\Revision\SlotRecord\hasAddress().
MediaWiki\Revision\SlotRecord::isDerived | ( | ) |
Definition at line 684 of file SlotRecord.php.
Referenced by MediaWiki\Revision\SlotRecord\newFromSlotRecord().
MediaWiki\Revision\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.
Definition at line 438 of file SlotRecord.php.
References MediaWiki\Revision\SlotRecord\getOrigin(), MediaWiki\Revision\SlotRecord\getRevision(), MediaWiki\Revision\SlotRecord\hasAddress(), and MediaWiki\Revision\SlotRecord\hasRevision().
Referenced by MediaWiki\Revision\RevisionSlots\getOriginalSlots(), and MediaWiki\Revision\SlotRecord\newSaved().
|
static |
Returns a SlotRecord for a derived slot.
string | $role | |
Content | $content | Initial content |
Definition at line 93 of file SlotRecord.php.
References MediaWiki\Revision\SlotRecord\$content, and MediaWiki\Revision\SlotRecord\newUnsaved().
|
staticprivate |
Constructs a new SlotRecord from an existing SlotRecord, overriding some fields.
The slot's content cannot be overwritten.
SlotRecord | $slot | |
array | $overrides |
Definition at line 106 of file SlotRecord.php.
References MediaWiki\Revision\SlotRecord\$row, and MediaWiki\Revision\SlotRecord\isDerived().
Referenced by MediaWiki\Revision\SlotRecord\newInherited(), and MediaWiki\Revision\SlotRecord\newSaved().
|
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.
SlotRecord | $slot |
Definition at line 129 of file SlotRecord.php.
References MediaWiki\Revision\SlotRecord\getAddress(), MediaWiki\Revision\SlotRecord\getOrigin(), MediaWiki\Revision\SlotRecord\getRevision(), and MediaWiki\Revision\SlotRecord\newFromSlotRecord().
Referenced by MediaWiki\Revision\MutableRevisionSlots\inheritSlot(), and MediaWiki\Revision\MutableRevisionSlots\newFromParentRevisionSlots().
|
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, content ID and content address.
int | $revisionId | the revision the slot is to be associated with (field slot_revision_id). If $protoSlot already has a revision, it must be the same. |
int | null | $contentId | the 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 | $contentAddress | the slot's content address (field content_address). If $protoSlot already has an address, it must be the same. |
SlotRecord | $protoSlot | The proto-slot that was provided as input for creating a new revision. $protoSlot must have a content address if inherited. |
Definition at line 188 of file SlotRecord.php.
References MediaWiki\Revision\SlotRecord\getAddress(), MediaWiki\Revision\SlotRecord\getContentId(), MediaWiki\Revision\SlotRecord\getOrigin(), MediaWiki\Revision\SlotRecord\getRevision(), MediaWiki\Revision\SlotRecord\hasAddress(), MediaWiki\Revision\SlotRecord\hasContentId(), MediaWiki\Revision\SlotRecord\hasField(), MediaWiki\Revision\SlotRecord\hasRevision(), MediaWiki\Revision\SlotRecord\isInherited(), and MediaWiki\Revision\SlotRecord\newFromSlotRecord().
|
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.
string | $role | |
Content | $content | |
bool | $derived |
Definition at line 155 of file SlotRecord.php.
References MediaWiki\Revision\SlotRecord\$content, MediaWiki\Revision\SlotRecord\$derived, MediaWiki\Revision\SlotRecord\$row, and Content\getModel().
Referenced by MediaWiki\Revision\SlotRecord\newDerived(), and MediaWiki\Revision\MutableRevisionSlots\setContent().
|
static |
Returns a new SlotRecord just like the given $slot, except that calling getContent() will fail with an exception.
SlotRecord | $slot |
Definition at line 70 of file SlotRecord.php.
References MediaWiki\Revision\SlotRecord\$row.
|
private |
string | $name | |
string | int | null | $value |
Definition at line 618 of file SlotRecord.php.
Referenced by MediaWiki\Revision\SlotRecord\getField(), MediaWiki\Revision\SlotRecord\getModel(), MediaWiki\Revision\SlotRecord\getSha1(), and MediaWiki\Revision\SlotRecord\getSize().
|
private |
Definition at line 55 of file SlotRecord.php.
Referenced by MediaWiki\Revision\SlotRecord\__construct(), MediaWiki\Revision\SlotRecord\getContent(), MediaWiki\Revision\SlotRecord\newDerived(), and MediaWiki\Revision\SlotRecord\newUnsaved().
|
private |
Definition at line 60 of file SlotRecord.php.
Referenced by MediaWiki\Revision\SlotRecord\__construct(), and MediaWiki\Revision\SlotRecord\newUnsaved().
|
private |
database result row, as a raw object.
Callbacks are supported for field values, to enable on-demand emulation of these values. This is primarily intended for use during schema migration.
Definition at line 50 of file SlotRecord.php.
Referenced by MediaWiki\Revision\SlotRecord\__construct(), MediaWiki\Revision\SlotRecord\newFromSlotRecord(), MediaWiki\Revision\SlotRecord\newUnsaved(), and MediaWiki\Revision\SlotRecord\newWithSuppressedContent().
const MediaWiki\Revision\SlotRecord::MAIN = 'main' |
Definition at line 43 of file SlotRecord.php.
Referenced by MediaWiki\Revision\RevisionRenderer\combineSlotOutput(), MediaWiki\Revision\RevisionStore\insertRevisionOn(), and MediaWiki\Revision\RenderedRevision\setRevisionParserOutput().