Go to the documentation of this file.
33 use Wikimedia\Assert\Assert;
66 return MediaWikiServices::getInstance()->getRevisionStoreFactory()
67 ->getRevisionStore( $wiki );
69 return MediaWikiServices::getInstance()->getRevisionStore();
77 return MediaWikiServices::getInstance()->getRevisionLookup();
84 return MediaWikiServices::getInstance()->getRevisionFactory();
93 $store = MediaWikiServices::getInstance()
94 ->getBlobStoreFactory()
95 ->newSqlBlobStore( $wiki );
98 throw new RuntimeException(
99 'The backwards compatibility code in Revision currently requires the BlobStore '
100 .
'service to be an SqlBlobStore instance, but it is a ' . get_class( $store )
124 return $rec ?
new Revision( $rec, $flags ) :
null;
146 return $rec ?
new Revision( $rec, $flags ) :
null;
168 return $rec ?
new Revision( $rec, $flags ) :
null;
192 if ( array_key_exists(
'page', $overrides ) ) {
193 $overrides[
'page_id'] = $overrides[
'page'];
194 unset( $overrides[
'page'] );
203 if ( isset( $overrides[
'title'] ) ) {
204 if ( !( $overrides[
'title'] instanceof
Title ) ) {
205 throw new MWException(
'title field override must contain a Title object.' );
208 $title = $overrides[
'title'];
211 if ( isset( $row->ar_namespace ) && isset( $row->ar_title ) ) {
214 throw new InvalidArgumentException(
215 'A Title or ar_namespace and ar_title must be given'
239 if ( is_array( $row ) ) {
264 return $rec ?
new Revision( $rec ) :
null;
283 return $rec ?
new Revision( $rec ) :
null;
302 return $rec ?
new Revision( $rec ) :
null;
371 $this->mRecord = $row;
372 } elseif ( is_array( $row ) ) {
375 if ( !isset( $row[
'user'] ) && !isset( $row[
'user_text'] ) ) {
376 $row[
'user'] = $wgUser;
384 } elseif ( is_object( $row ) ) {
391 throw new InvalidArgumentException(
392 '$row must be a row object, an associative array, or a RevisionRecord'
396 Assert::postcondition( $this->mRecord !==
null,
'Failed to construct a RevisionRecord' );
414 if ( is_array( $row ) ) {
415 if ( isset( $row[
'title'] ) ) {
416 if ( !( $row[
'title'] instanceof
Title ) ) {
417 throw new MWException(
'title field must contain a Title object.' );
420 return $row[
'title'];
423 $pageId = $row[
'page'] ?? 0;
424 $revId = $row[
'id'] ?? 0;
426 $pageId = $row->rev_page ?? 0;
427 $revId = $row->rev_id ?? 0;
438 $title->resetArticleID( $pageId );
462 return $this->mRecord->getId();
481 $this->mRecord->setId( intval( $id ) );
483 throw new MWException( __METHOD__ .
' is not supported on this instance' );
503 $this->mRecord->setUser( $user );
505 throw new MWException( __METHOD__ .
' is not supported on this instance' );
536 return $slot && $slot->hasAddress()
551 return $this->mRecord->getParentId();
564 return $this->mRecord->getSize();
580 return $this->mRecord->getSha1();
598 $linkTarget = $this->mRecord->getPageAsLinkTarget();
612 if ( !
$title->equals( $this->getTitle() ) ) {
613 throw new InvalidArgumentException(
615 .
' is not the same as '
616 . $this->mRecord->getPageAsLinkTarget()->__toString()
630 return $this->mRecord->getPageId();
648 public function getUser( $audience = self::FOR_PUBLIC,
User $user =
null ) {
650 if ( $audience === self::FOR_THIS_USER && !$user ) {
655 $user = $this->mRecord->getUser( $audience, $user );
656 return $user ? $user->getId() : 0;
676 if ( $audience === self::FOR_THIS_USER && !$user ) {
681 $user = $this->mRecord->getUser( $audience, $user );
682 return $user ? $user->getName() :
'';
700 if ( $audience === self::FOR_THIS_USER && !$user ) {
705 $comment = $this->mRecord->getComment( $audience, $user );
706 return $comment ===
null ? null : $comment->text;
716 return $this->mRecord->isMinor();
753 return $this->mRecord->isDeleted( $field );
765 return $this->mRecord->getVisibility();
789 if ( $audience === self::FOR_THIS_USER && !$user ) {
812 return $slot ? $slot->getContent()->serialize() :
'';
833 return $slot->getModel();
835 $slotRoleRegistry = MediaWikiServices::getInstance()->getSlotRoleRegistry();
837 return $slotRoleHandler->getDefaultModel( $this->
getTitle() );
858 if ( $format ===
null ) {
877 return MediaWikiServices::getInstance()
878 ->getContentHandlerFactory()
889 return $this->mRecord->getTimestamp();
899 return $this->mRecord->isCurrent();
912 return $rec ?
new Revision( $rec, self::READ_NORMAL, $this->
getTitle() ) :
null;
925 return $rec ?
new Revision( $rec, self::READ_NORMAL, $this->
getTitle() ) :
null;
956 $textField = $prefix .
'text';
958 if ( isset( $row->$textField ) ) {
959 throw new LogicException(
960 'Cannot use ' . __METHOD__ .
' with the ' . $textField .
' field since 1.35.'
966 $rev = $prefix ===
'ar_'
967 ? $store->newRevisionFromArchiveRow( $row )
968 : $store->newRevisionFromRow( $row );
1002 if ( $text ===
false ) {
1030 $this->mRecord->setUser( $wgUser );
1032 throw new MWException(
'Cannot insert revision with no associated user.' );
1038 $this->mRecord = $rec;
1039 Assert::postcondition( $this->mRecord !==
null,
'Failed to acquire a RevisionRecord' );
1041 return $rec->getId();
1089 return $rec ?
new Revision( $rec ) :
null;
1200 if ( is_int( $db ) ) {
1232 return $record ?
new Revision( $record ) :
false;
static newFromArchiveRow( $row, $overrides=[])
Make a fake revision object from an archive table row.
static newKnownCurrent(IDatabase $db, $pageIdOrTitle, $revId=0)
Load a revision based on a known page ID and current revision ID from the DB.
getUserText( $audience=self::FOR_PUBLIC, User $user=null)
Fetch revision's username if it's available to the specified audience.
static newFromId( $id, $flags=0)
Load a page revision from a given revision ID number.
getUser( $audience=self::FOR_PUBLIC, User $user=null)
Fetch revision's user id if it's available to the specified audience.
static userCanBitfield( $bitfield, $field, User $user=null, Title $title=null)
Determine if the current user is allowed to view a particular field of this revision,...
getSize()
Returns the length of the text in this revision, or null if unknown.
setId( $id)
Set the revision ID.
getContent( $audience=self::FOR_PUBLIC, User $user=null)
Fetch revision content if it's available to the specified audience.
getPage()
Get the page ID.
static getBlobStore( $wiki=false)
static getRevisionText( $row, $prefix='old_', $wiki=false)
Get revision text associated with an old or archive row.
getParentId()
Get parent revision ID (the original previous page revision)
setTitle( $title)
Set the title of the revision.
getContentHandler()
Returns the content handler appropriate for this revision's content model.
static getArchiveQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new archived revision objec...
getSerializedData()
Get original serialized data (without checking view restrictions)
wfLogWarning( $msg, $callerOffset=1, $level=E_USER_WARNING)
Send a warning as a PHP error and the debug log.
getRecentChange( $flags=0)
Get the RC object belonging to the current revision, if there's one.
static newFromPageId( $pageId, $revId=0, $flags=0)
Load either the current, or a specified, revision that's attached to a given page ID.
getSha1()
Returns the base36 sha1 of the content in this revision, or null if unknown.
Interface for database access objects.
getContentModel()
Returns the content model for the main slot of this revision.
insertOn( $dbw)
Insert a new revision into the database, returning the new revision ID number on success and dies hor...
static getRevisionFactory()
static base36Sha1( $text)
Get the base 36 SHA-1 value for a string of text.
static newFromTitle(LinkTarget $linkTarget, $id=0, $flags=0)
Load either the current, or a specified, revision that's attached to a given link target.
static getQueryInfo( $options=[])
Return the tables, fields, and join conditions to be selected to create a new revision object.
getNext()
Get next revision for this title.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
setUserIdAndName( $id, $name)
This should only be used for proposed revisions that turn out to be null edits.
static getTimestampFromId( $title, $id, $flags=0)
Get rev_timestamp from rev_id, without loading the rest of the row.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
static loadFromPageId( $db, $pageid, $id=0)
Load either the current, or a specified, revision that's attached to a given page.
static compressRevisionText(&$text)
If $wgCompressRevisions is enabled, we will compress data.
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
static newFromAnyId( $userId, $userName, $actorId, $dbDomain=false)
Static factory method for creation from an ID, name, and/or actor ID.
static countByTitle( $db, $title)
Get count of revisions per page...not very efficient.
getPrevious()
Get previous revision for this title.
static countByPageId( $db, $id)
Get count of revisions per page...not very efficient.
static getRevisionStore( $wiki=false)
ensureTitle( $row, $queryFlags, $title=null)
Make sure we have some Title object for use by the constructor.
getTitle()
Returns the title of the page associated with this entry.
static userWasLastToEdit( $db, $pageId, $userId, $since)
Check if no edits were made by other users since the time a user started editing the page.
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
static getParentLengths( $db, array $revIds)
Do a batched query to get the parent revision lengths.
getVisibility()
Get the deletion bitfield of the revision.
getTextId()
Get the ID of the row of the text table that contains the content of the revision's main slot,...
static newFromLinkTarget(LinkTarget $linkTarget, $forceClone='')
Returns a Title given a LinkTarget.
getContentFormat()
Returns the content format for the main slot of this revision.
Represents a title within MediaWiki.
static loadFromTimestamp( $db, $title, $timestamp)
Load the revision for the given title with the given timestamp.
getComment( $audience=self::FOR_PUBLIC, User $user=null)
static newNullRevision( $dbw, $pageId, $summary, $minor, $user=null)
Create a new null-revision for insertion into a page's history.
__construct( $row, $queryFlags=0, Title $title=null)
static decompressRevisionText( $text, $flags)
Re-converts revision text according to it's flags.
static loadFromTitle( $db, $title, $id=0)
Load either the current, or a specified, revision that's attached to a given page.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
static newFromID( $id, $flags=0)
Create a new Title from an article ID.
userCan( $field, User $user=null)
Determine if the current user is allowed to view a particular field of this revision,...
static getRevisionLookup()