33use Wikimedia\Assert\Assert;
56 public const RAW = RevisionRecord::RAW;
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 ) ) {
212 $title = Title::makeTitle( $row->ar_namespace, $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' );
505 $this->mRecord->setUser( $user );
507 throw new MWException( __METHOD__ .
' is not supported on this instance' );
515 if ( !$this->mRecord->hasSlot( SlotRecord::MAIN ) ) {
519 return $this->mRecord->getSlot( SlotRecord::MAIN, RevisionRecord::RAW );
538 return $slot && $slot->hasAddress()
553 return $this->mRecord->getParentId();
566 return $this->mRecord->getSize();
582 return $this->mRecord->getSha1();
600 $linkTarget = $this->mRecord->getPageAsLinkTarget();
601 return Title::newFromLinkTarget( $linkTarget );
614 if ( !
$title->equals( $this->getTitle() ) ) {
615 throw new InvalidArgumentException(
617 .
' is not the same as '
618 . $this->mRecord->getPageAsLinkTarget()->__toString()
632 return $this->mRecord->getPageId();
650 public function getUser( $audience = self::FOR_PUBLIC,
User $user =
null ) {
652 if ( $audience === self::FOR_THIS_USER && !$user ) {
657 $user = $this->mRecord->getUser( $audience, $user );
658 return $user ? $user->getId() : 0;
678 if ( $audience === self::FOR_THIS_USER && !$user ) {
683 $user = $this->mRecord->getUser( $audience, $user );
684 return $user ? $user->getName() :
'';
702 if ( $audience === self::FOR_THIS_USER && !$user ) {
707 $comment = $this->mRecord->getComment( $audience, $user );
708 return $comment ===
null ? null : $comment->text;
718 return $this->mRecord->isMinor();
755 return $this->mRecord->isDeleted( $field );
767 return $this->mRecord->getVisibility();
791 if ( $audience === self::FOR_THIS_USER && !$user ) {
796 return $this->mRecord->getContent( SlotRecord::MAIN, $audience, $user );
814 return $slot ? $slot->getContent()->serialize() :
'';
835 return $slot->getModel();
837 $slotRoleRegistry = MediaWikiServices::getInstance()->getSlotRoleRegistry();
838 $slotRoleHandler = $slotRoleRegistry->getRoleHandler( SlotRecord::MAIN );
839 return $slotRoleHandler->getDefaultModel( $this->
getTitle() );
860 if ( $format ===
null ) {
879 return MediaWikiServices::getInstance()
880 ->getContentHandlerFactory()
891 return $this->mRecord->getTimestamp();
901 return $this->mRecord->isCurrent();
914 return $rec ?
new Revision( $rec, self::READ_NORMAL, $this->
getTitle() ) :
null;
927 return $rec ?
new Revision( $rec, self::READ_NORMAL, $this->
getTitle() ) :
null;
958 $textField = $prefix .
'text';
960 if ( isset( $row->$textField ) ) {
961 throw new LogicException(
962 'Cannot use ' . __METHOD__ .
' with the ' . $textField .
' field since 1.35.'
968 $rev = $prefix ===
'ar_'
969 ? $store->newRevisionFromArchiveRow( $row )
970 : $store->newRevisionFromRow( $row );
972 $content = $rev->getContent( SlotRecord::MAIN );
1004 if ( $text ===
false ) {
1030 if ( $this->mRecord->getUser( RevisionRecord::RAW ) ===
null ) {
1032 $this->mRecord->setUser( $wgUser );
1034 throw new MWException(
'Cannot insert revision with no associated user.' );
1040 $this->mRecord = $rec;
1041 Assert::postcondition( $this->mRecord !==
null,
'Failed to acquire a RevisionRecord' );
1043 return $rec->getId();
1054 return SlotRecord::base36Sha1( $text );
1082 $comment = CommentStoreComment::newUnsavedComment( $summary,
null );
1084 $title = Title::newFromID( $pageId, Title::READ_LATEST );
1091 return $rec ?
new Revision( $rec ) :
null;
1112 return RevisionRecord::userCanBitfield( $this->mRecord->getVisibility(), $field, $user );
1138 return RevisionRecord::userCanBitfield( $bitfield, $field, $user,
$title );
1202 if ( is_int( $db ) ) {
1227 : Title::newFromID( $pageIdOrTitle );
1234 return $record ?
new Revision( $record ) :
false;
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfLogWarning( $msg, $callerOffset=1, $level=E_USER_WARNING)
Send a warning as a PHP error and the debug log.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
getRecentChange( $flags=0)
Get the RC object belonging to the current revision, if there's one.
getUserText( $audience=self::FOR_PUBLIC, User $user=null)
Fetch revision's username if it's available to the specified audience.
getTitle()
Returns the title of the page associated with this entry.
getPrevious()
Get previous revision for this title.
ensureTitle( $row, $queryFlags, $title=null)
Make sure we have some Title object for use by the constructor.
getSize()
Returns the length of the text in this revision, or null if unknown.
getSerializedData()
Get original serialized data (without checking view restrictions)
static compressRevisionText(&$text)
If $wgCompressRevisions is enabled, we will compress data.
static decompressRevisionText( $text, $flags)
Re-converts revision text according to it's flags.
setUserIdAndName( $id, $name)
Set the user ID/name.
getContentHandler()
Returns the content handler appropriate for this revision's content model.
static newKnownCurrent(IDatabase $db, $pageIdOrTitle, $revId=0)
Load a revision based on a known page ID and current revision ID from the DB.
static getRevisionText( $row, $prefix='old_', $wiki=false)
Get revision text associated with an old or archive row.
getComment( $audience=self::FOR_PUBLIC, User $user=null)
static loadFromTitle( $db, $title, $id=0)
Load either the current, or a specified, revision that's attached to a given page.
getNext()
Get next revision for this title.
getTextId()
Get the ID of the row of the text table that contains the content of the revision's main slot,...
static getRevisionStore( $wiki=false)
static newFromPageId( $pageId, $revId=0, $flags=0)
Load either the current, or a specified, revision that's attached to a given page ID.
getContentFormat()
Returns the content format for the main slot of this revision.
static loadFromTimestamp( $db, $title, $timestamp)
Load the revision for the given title with the given timestamp.
static getRevisionFactory()
getPage()
Get the page ID.
static getArchiveQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new archived revision objec...
static newNullRevision( $dbw, $pageId, $summary, $minor, $user=null)
Create a new null-revision for insertion into a page's history.
static getTimestampFromId( $title, $id, $flags=0)
Get rev_timestamp from rev_id, without loading the rest of the row.
getContentModel()
Returns the content model for the main slot of this revision.
static countByPageId( $db, $id)
Get count of revisions per page...not very efficient.
getUser( $audience=self::FOR_PUBLIC, User $user=null)
Fetch revision's user id if it's available to the specified audience.
static newFromArchiveRow( $row, $overrides=[])
Make a fake revision object from an archive table row.
getContent( $audience=self::FOR_PUBLIC, User $user=null)
Fetch revision content if it's available to the specified audience.
static countByTitle( $db, $title)
Get count of revisions per page...not very efficient.
static getQueryInfo( $options=[])
Return the tables, fields, and join conditions to be selected to create a new revision object.
static base36Sha1( $text)
Get the base 36 SHA-1 value for a string of text.
getSha1()
Returns the base36 sha1 of the content in this revision, or null if unknown.
static loadFromPageId( $db, $pageid, $id=0)
Load either the current, or a specified, revision that's attached to a given page.
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,...
getVisibility()
Get the deletion bitfield of the revision.
setTitle( $title)
Set the title of the revision.
insertOn( $dbw)
Insert a new revision into the database, returning the new revision ID number on success and dies hor...
__construct( $row, $queryFlags=0, Title $title=null)
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 getParentLengths( $db, array $revIds)
Do a batched query to get the parent revision lengths.
static getRevisionLookup()
userCan( $field, User $user=null)
Determine if the current user is allowed to view a particular field of this revision,...
static getBlobStore( $wiki=false)
static newFromTitle(LinkTarget $linkTarget, $id=0, $flags=0)
Load either the current, or a specified, revision that's attached to a given link target.
getParentId()
Get parent revision ID (the original previous page revision)
setId( $id)
Set the revision ID.
static newFromId( $id, $flags=0)
Load a page revision from a given revision ID number.
Represents a title within MediaWiki.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
static newFromAnyId( $userId, $userName, $actorId, $dbDomain=false)
Static factory method for creation from an ID, name, and/or actor ID.
Interface for database access objects.