57 const RAW = RevisionRecord::RAW;
65 return MediaWikiServices::getInstance()->getRevisionStore();
72 return MediaWikiServices::getInstance()->getRevisionLookup();
79 return MediaWikiServices::getInstance()->getRevisionFactory();
88 $store = MediaWikiServices::getInstance()
89 ->getBlobStoreFactory()
90 ->newSqlBlobStore( $wiki );
93 throw new RuntimeException(
94 'The backwards compatibility code in Revision currently requires the BlobStore '
95 .
'service to be an SqlBlobStore instance, but it is a ' . get_class( $store )
115 $rec = self::getRevisionLookup()->getRevisionById( $id, $flags );
116 return $rec ===
null ? null :
new Revision( $rec, $flags );
134 $rec = self::getRevisionLookup()->getRevisionByTitle( $linkTarget, $id, $flags );
135 return $rec ===
null ? null :
new Revision( $rec, $flags );
153 $rec = self::getRevisionLookup()->getRevisionByPageId( $pageId, $revId, $flags );
154 return $rec ===
null ? null :
new Revision( $rec, $flags );
174 if ( array_key_exists(
'page', $overrides ) ) {
175 $overrides[
'page_id'] = $overrides[
'page'];
176 unset( $overrides[
'page'] );
185 if ( isset( $overrides[
'title'] ) ) {
186 if ( !( $overrides[
'title'] instanceof
Title ) ) {
187 throw new MWException(
'title field override must contain a Title object.' );
190 $title = $overrides[
'title'];
192 if ( $title !==
null ) {
193 if ( isset( $row->ar_namespace ) && isset( $row->ar_title ) ) {
194 $title = Title::makeTitle( $row->ar_namespace, $row->ar_title );
196 throw new InvalidArgumentException(
197 'A Title or ar_namespace and ar_title must be given'
202 $rec = self::getRevisionFactory()->newRevisionFromArchiveRow( $row, 0, $title, $overrides );
203 return new Revision( $rec, self::READ_NORMAL, $title );
219 if ( is_array( $row ) ) {
220 $rec = self::getRevisionFactory()->newMutableRevisionFromArray( $row );
222 $rec = self::getRevisionFactory()->newRevisionFromRow( $row );
240 $rec = self::getRevisionStore()->loadRevisionFromId( $db, $id );
241 return $rec ===
null ? null :
new Revision( $rec );
257 $rec = self::getRevisionStore()->loadRevisionFromPageId( $db, $pageid, $id );
258 return $rec ===
null ? null :
new Revision( $rec );
274 $rec = self::getRevisionStore()->loadRevisionFromTitle( $db, $title, $id );
275 return $rec ===
null ? null :
new Revision( $rec );
292 $rec = self::getRevisionStore()->loadRevisionFromTimestamp( $db, $title, $timestamp );
293 return $rec ===
null ? null :
new Revision( $rec );
325 throw new BadMethodCallException(
326 'Cannot use ' . __METHOD__ .
' when $wgActorTableSchemaMigrationStage > MIGRATION_WRITE_BOTH'
330 return [
'LEFT JOIN', [
'rev_user != 0',
'user_id = rev_user' ] ];
342 return [
'INNER JOIN', [
'page_id = rev_page' ] ];
359 throw new BadMethodCallException(
360 'Cannot use ' . __METHOD__ .
' when $wgActorTableSchemaMigrationStage > MIGRATION_WRITE_BOTH'
373 'rev_actor' =>
'NULL',
381 $fields += CommentStore::getStore()->getFields(
'rev_comment' );
384 $fields[] =
'rev_content_format';
385 $fields[] =
'rev_content_model';
405 throw new BadMethodCallException(
406 'Cannot use ' . __METHOD__ .
' when $wgActorTableSchemaMigrationStage > MIGRATION_WRITE_BOTH'
420 'ar_actor' =>
'NULL',
428 $fields += CommentStore::getStore()->getFields(
'ar_comment' );
431 $fields[] =
'ar_content_format';
432 $fields[] =
'ar_content_model';
475 return [
'user_name' ];
493 return self::getRevisionStore()->getQueryInfo(
$options );
507 return self::getRevisionStore()->getArchiveQueryInfo();
520 return self::getRevisionStore()->listRevisionSizes( $db, $revIds );
534 $this->mRecord = $row;
535 } elseif ( is_array( $row ) ) {
538 if ( !isset( $row[
'user'] ) && !isset( $row[
'user_text'] ) ) {
542 $this->mRecord = self::getRevisionFactory()->newMutableRevisionFromArray(
547 } elseif ( is_object( $row ) ) {
548 $this->mRecord = self::getRevisionFactory()->newRevisionFromRow(
554 throw new InvalidArgumentException(
555 '$row must be a row object, an associative array, or a RevisionRecord'
570 private function ensureTitle( $row, $queryFlags, $title =
null ) {
575 if ( is_array( $row ) ) {
576 if ( isset( $row[
'title'] ) ) {
577 if ( !( $row[
'title'] instanceof
Title ) ) {
578 throw new MWException(
'title field must contain a Title object.' );
581 return $row[
'title'];
584 $pageId = isset( $row[
'page'] ) ? $row[
'page'] : 0;
585 $revId = isset( $row[
'id'] ) ? $row[
'id'] : 0;
587 $pageId = isset( $row->rev_page ) ? $row->rev_page : 0;
588 $revId = isset( $row->rev_id ) ? $row->rev_id : 0;
592 $title = self::getRevisionStore()->getTitle( $pageId, $revId, $queryFlags );
598 $title = Title::makeTitleSafe(
NS_SPECIAL,
"Badtitle/ID=$pageId" );
599 $title->resetArticleID( $pageId );
609 return $this->mRecord;
618 return $this->mRecord->getId();
635 $this->mRecord->setId( intval( $id ) );
637 throw new MWException( __METHOD__ .
' is not supported on this instance' );
658 $this->mRecord->setUser( $user );
660 throw new MWException( __METHOD__ .
' is not supported on this instance' );
668 return $this->mRecord->getSlot(
'main', RevisionRecord::RAW );
685 return $slot->hasAddress()
686 ? self::getBlobStore()->getTextIdFromAddress( $slot->getAddress() )
697 return $this->mRecord->getParentId();
707 return $this->mRecord->getSize();
720 return $this->mRecord->getSha1();
735 $linkTarget = $this->mRecord->getPageAsLinkTarget();
736 return Title::newFromLinkTarget( $linkTarget );
747 if ( !$title->equals( $this->getTitle() ) ) {
748 throw new InvalidArgumentException(
749 $title->getPrefixedText()
750 .
' is not the same as '
751 . $this->mRecord->getPageAsLinkTarget()->__toString()
762 return $this->mRecord->getPageId();
778 public function getUser( $audience = self::FOR_PUBLIC,
User $user =
null ) {
781 if ( $audience === self::FOR_THIS_USER && !$user ) {
785 $user = $this->mRecord->getUser( $audience, $user );
786 return $user ? $user->getId() : 0;
797 return $this->
getUser( self::RAW );
816 if ( $audience === self::FOR_THIS_USER && !$user ) {
820 $user = $this->mRecord->getUser( $audience, $user );
821 return $user ? $user->getName() :
'';
851 if ( $audience === self::FOR_THIS_USER && !$user ) {
855 $comment = $this->mRecord->getComment( $audience, $user );
856 return $comment ===
null ? null : $comment->text;
874 return $this->mRecord->isMinor();
881 return self::getRevisionStore()->getRcIdIfUnpatrolled( $this->mRecord );
894 return self::getRevisionStore()->getRecentChange( $this->mRecord, $flags );
903 return $this->mRecord->isDeleted( $field );
912 return $this->mRecord->getVisibility();
932 if ( $audience === self::FOR_THIS_USER && !$user ) {
937 return $this->mRecord->getContent(
'main', $audience, $user );
954 return $slot->getContent()->serialize();
987 if ( $format ===
null ) {
1002 return ContentHandler::getForModelID( $this->getContentModel() );
1009 return $this->mRecord->getTimestamp();
1026 $rec = self::getRevisionLookup()->getPreviousRevision( $this->mRecord, $title );
1027 return $rec ===
null ? null :
new Revision( $rec, self::READ_NORMAL, $title );
1037 $rec = self::getRevisionLookup()->getNextRevision( $this->mRecord, $title );
1038 return $rec ===
null ? null :
new Revision( $rec, self::READ_NORMAL, $title );
1056 $textField = $prefix .
'text';
1057 $flagsField = $prefix .
'flags';
1059 if ( isset( $row->$flagsField ) ) {
1060 $flags = explode(
',', $row->$flagsField );
1065 if ( isset( $row->$textField ) ) {
1066 $text = $row->$textField;
1071 $cacheKey = isset( $row->old_id ) ? (
'tt:' . $row->old_id ) :
null;
1073 return self::getBlobStore( $wiki )->expandBlob( $text, $flags, $cacheKey );
1087 return self::getBlobStore()->compressData( $text );
1098 return self::getBlobStore()->decompressData( $text, $flags );
1115 if ( $this->mRecord->getUser( RevisionRecord::RAW ) ===
null ) {
1117 $this->mRecord->setUser(
$wgUser );
1119 throw new MWException(
'Cannot insert revision with no associated user.' );
1123 $rec = self::getRevisionStore()->insertRevisionOn( $this->mRecord, $dbw );
1125 $this->mRecord = $rec;
1130 Hooks::run(
'RevisionInsertComplete', [ &$revision,
null,
null ] );
1132 return $rec->getId();
1141 return SlotRecord::base36Sha1( $text );
1165 $comment = CommentStoreComment::newUnsavedComment( $summary,
null );
1167 $title = Title::newFromID( $pageId, Title::GAID_FOR_UPDATE );
1168 if ( $title ===
null ) {
1172 $rec = self::getRevisionStore()->newNullRevision( $dbw, $title, $comment, $minor, $user );
1188 return self::userCanBitfield( $this->
getVisibility(), $field, $user );
1214 return RevisionRecord::userCanBitfield( $bitfield, $field, $user, $title );
1226 return self::getRevisionStore()->getTimestampFromId( $title, $id, $flags );
1237 return self::getRevisionStore()->countRevisionsByPageId( $db, $id );
1248 return self::getRevisionStore()->countRevisionsByTitle( $db, $title );
1268 if ( is_int( $db ) ) {
1272 return self::getRevisionStore()->userWasLastToEdit( $db, $pageId, $userId, $since );
1289 $title = $pageIdOrTitle instanceof
Title
1291 : Title::newFromID( $pageIdOrTitle );
1297 $record = self::getRevisionLookup()->getKnownCurrentRevision( $title, $revId );
1298 return $record ?
new Revision( $record ) :
false;
$wgContentHandlerUseDB
Set to false to disable use of the database fields introduced by the ContentHandler facility.
int $wgActorTableSchemaMigrationStage
Actor table schema migration stage.
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)
Throws 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.
static getRevisionStore()
getTitle()
Returns the title of the page associated with this entry.
static selectArchiveFields()
Return the list of revision fields that should be selected to create a new revision from an archive r...
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.
getRawUser()
Fetch revision's user id without regard for the current user's permissions.
static userJoinCond()
Return the value of a select() JOIN conds array for the user table.
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)
Fetch revision comment if it's available to the specified audience.
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 selectTextFields()
Return the list of text fields that should be selected to read the revision text.
static newFromPageId( $pageId, $revId=0, $flags=0)
Load either the current, or a specified, revision that's attached to a given page ID.
static selectPageFields()
Return the list of page fields that should be selected from page table.
getContentFormat()
Returns the content format for the main slot of this revision.
static selectFields()
Return the list of revision fields that should be selected to create a new 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 loadFromId( $db, $id)
Load a page revision from a given revision ID number.
static getTimestampFromId( $title, $id, $flags=0)
Get rev_timestamp from rev_id, without loading the rest of the row.
static selectUserFields()
Return the list of user fields that should be selected from user table.
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 pageJoinCond()
Return the value of a select() page conds array for the page table.
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.
getRawComment()
Fetch revision comment without regard for the current user's permissions.
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.
getRawUserText()
Fetch revision's username without regard for view restrictions.
static getParentLengths( $db, array $revIds)
Do a batched query to get the parent revision lengths.
static getRevisionLookup()
static fetchRevision(LinkTarget $title)
Return a wrapper for a series of database rows to fetch all of a given page's revisions in turn.
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)
Static factory method for creation from an ID, name, and/or actor ID.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
namespace and then decline to actually register it file or subcat img or subcat $title
returning false will NOT prevent logging $e
const MIGRATION_WRITE_BOTH
Interface for database access objects.