Go to the documentation of this file.
32 use Wikimedia\Assert\Assert;
65 return MediaWikiServices::getInstance()->getRevisionStoreFactory()
66 ->getRevisionStore( $wiki );
68 return MediaWikiServices::getInstance()->getRevisionStore();
76 return MediaWikiServices::getInstance()->getRevisionLookup();
83 return MediaWikiServices::getInstance()->getRevisionFactory();
92 $store = MediaWikiServices::getInstance()
93 ->getBlobStoreFactory()
94 ->newSqlBlobStore( $wiki );
97 throw new RuntimeException(
98 'The backwards compatibility code in Revision currently requires the BlobStore '
99 .
'service to be an SqlBlobStore instance, but it is a ' . get_class( $store )
120 return $rec ?
new Revision( $rec, $flags ) :
null;
139 return $rec ?
new Revision( $rec, $flags ) :
null;
158 return $rec ?
new Revision( $rec, $flags ) :
null;
178 if ( array_key_exists(
'page', $overrides ) ) {
179 $overrides[
'page_id'] = $overrides[
'page'];
180 unset( $overrides[
'page'] );
189 if ( isset( $overrides[
'title'] ) ) {
190 if ( !( $overrides[
'title'] instanceof
Title ) ) {
191 throw new MWException(
'title field override must contain a Title object.' );
194 $title = $overrides[
'title'];
197 if ( isset( $row->ar_namespace ) && isset( $row->ar_title ) ) {
200 throw new InvalidArgumentException(
201 'A Title or ar_namespace and ar_title must be given'
223 if ( is_array( $row ) ) {
245 return $rec ?
new Revision( $rec ) :
null;
262 return $rec ?
new Revision( $rec ) :
null;
279 return $rec ?
new Revision( $rec ) :
null;
297 return $rec ?
new Revision( $rec ) :
null;
315 throw new BadMethodCallException(
316 'Cannot use ' . __METHOD__
317 .
' when $wgActorTableSchemaMigrationStage has SCHEMA_COMPAT_READ_NEW'
321 return [
'LEFT JOIN', [
'rev_user != 0',
'user_id = rev_user' ] ];
333 return [
'JOIN', [
'page_id = rev_page' ] ];
351 throw new BadMethodCallException(
352 'Cannot use ' . __METHOD__
353 .
' when $wgActorTableSchemaMigrationStage has SCHEMA_COMPAT_READ_NEW'
363 throw new BadMethodCallException(
364 'Cannot use ' . __METHOD__ .
' when $wgMultiContentRevisionSchemaMigrationStage '
365 .
'does not have SCHEMA_COMPAT_WRITE_OLD set.'
378 'rev_actor' =>
'NULL',
389 $fields[] =
'rev_content_format';
390 $fields[] =
'rev_content_model';
411 throw new BadMethodCallException(
412 'Cannot use ' . __METHOD__
413 .
' when $wgActorTableSchemaMigrationStage has SCHEMA_COMPAT_READ_NEW'
423 throw new BadMethodCallException(
424 'Cannot use ' . __METHOD__ .
' when $wgMultiContentRevisionSchemaMigrationStage '
425 .
'does not have SCHEMA_COMPAT_WRITE_OLD set.'
439 'ar_actor' =>
'NULL',
450 $fields[] =
'ar_content_format';
451 $fields[] =
'ar_content_model';
494 return [
'user_name' ];
553 $this->mRecord = $row;
554 } elseif ( is_array( $row ) ) {
557 if ( !isset( $row[
'user'] ) && !isset( $row[
'user_text'] ) ) {
558 $row[
'user'] = $wgUser;
566 } elseif ( is_object( $row ) ) {
573 throw new InvalidArgumentException(
574 '$row must be a row object, an associative array, or a RevisionRecord'
578 Assert::postcondition( $this->mRecord !==
null,
'Failed to construct a RevisionRecord' );
596 if ( is_array( $row ) ) {
597 if ( isset( $row[
'title'] ) ) {
598 if ( !( $row[
'title'] instanceof
Title ) ) {
599 throw new MWException(
'title field must contain a Title object.' );
602 return $row[
'title'];
605 $pageId = $row[
'page'] ?? 0;
606 $revId = $row[
'id'] ?? 0;
608 $pageId = $row->rev_page ?? 0;
609 $revId = $row->rev_id ?? 0;
620 $title->resetArticleID( $pageId );
639 return $this->mRecord->getId();
656 $this->mRecord->setId( intval( $id ) );
658 throw new MWException( __METHOD__ .
' is not supported on this instance' );
679 $this->mRecord->setUser(
$user );
681 throw new MWException( __METHOD__ .
' is not supported on this instance' );
706 return $slot->hasAddress()
718 return $this->mRecord->getParentId();
728 return $this->mRecord->getSize();
741 return $this->mRecord->getSha1();
756 $linkTarget = $this->mRecord->getPageAsLinkTarget();
768 if ( !
$title->equals( $this->getTitle() ) ) {
769 throw new InvalidArgumentException(
771 .
' is not the same as '
772 . $this->mRecord->getPageAsLinkTarget()->__toString()
783 return $this->mRecord->getPageId();
802 if ( $audience === self::FOR_THIS_USER && !
$user ) {
806 $user = $this->mRecord->getUser( $audience,
$user );
826 if ( $audience === self::FOR_THIS_USER && !
$user ) {
830 $user = $this->mRecord->getUser( $audience,
$user );
848 if ( $audience === self::FOR_THIS_USER && !
$user ) {
852 $comment = $this->mRecord->getComment( $audience,
$user );
853 return $comment ===
null ?
null : $comment->text;
860 return $this->mRecord->isMinor();
889 return $this->mRecord->isDeleted( $field );
898 return $this->mRecord->getVisibility();
918 if ( $audience === self::FOR_THIS_USER && !
$user ) {
940 return $slot->getContent()->serialize();
973 if ( $format ===
null ) {
995 return $this->mRecord->getTimestamp();
1013 return $rec ?
new Revision( $rec, self::READ_NORMAL,
$title ) :
null;
1024 return $rec ?
new Revision( $rec, self::READ_NORMAL,
$title ) :
null;
1055 $textField = $prefix .
'text';
1056 $flagsField = $prefix .
'flags';
1058 if ( isset( $row->$textField ) ) {
1064 throw new LogicException(
1065 'Cannot use ' . __METHOD__ .
' with the ' . $textField .
' field when'
1066 .
' $wgMultiContentRevisionSchemaMigrationStage does not include'
1067 .
' SCHEMA_COMPAT_WRITE_OLD. The field may not be populated for all revisions!'
1071 $text = $row->$textField;
1078 wfDeprecated( __METHOD__ .
' (MCR without SCHEMA_COMPAT_WRITE_OLD)',
'1.32' );
1082 $rev = $prefix ===
'ar_'
1083 ? $store->newRevisionFromArchiveRow( $row )
1084 : $store->newRevisionFromRow( $row );
1090 if ( isset( $row->$flagsField ) ) {
1091 $flags = explode(
',', $row->$flagsField );
1096 $cacheKey = isset( $row->old_id )
1097 ? SqlBlobStore::makeAddressFromTextId( $row->old_id )
1102 if ( $revisionText ===
false ) {
1103 if ( isset( $row->old_id ) ) {
1104 wfLogWarning( __METHOD__ .
": Bad data in text row {$row->old_id}! " );
1106 wfLogWarning( __METHOD__ .
": Bad data in text row! " );
1111 return $revisionText;
1136 if ( $text ===
false ) {
1160 $this->mRecord->setUser( $wgUser );
1162 throw new MWException(
'Cannot insert revision with no associated user.' );
1168 $this->mRecord = $rec;
1169 Assert::postcondition( $this->mRecord !==
null,
'Failed to acquire a RevisionRecord' );
1171 return $rec->getId();
1213 return $rec ?
new Revision( $rec ) :
null;
1307 if ( is_int( $db ) ) {
1337 return $record ?
new Revision( $record ) :
false;
static newFromArchiveRow( $row, $overrides=[])
Make a fake revision object from an archive table row.
static getForModelID( $modelId)
Returns the ContentHandler singleton for the given model ID.
return true to allow those checks to and false if checking is done & $user
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.
const SCHEMA_COMPAT_READ_NEW
static newFromId( $id, $flags=0)
Load a page revision from a given revision ID number.
static pageJoinCond()
Return the value of a select() page conds array for the page table.
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)
int $wgMultiContentRevisionSchemaMigrationStage
RevisionStore table schema migration stage (content, slots, content_models & slot_roles tables).
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 newFromAnyId( $userId, $userName, $actorId)
Static factory method for creation from an ID, name, and/or actor ID.
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.
static loadFromId( $db, $id)
Load a page revision from a given revision ID number.
Interface for database access objects.
getContentModel()
Returns the content model for the main slot of this revision.
$wgContentHandlerUseDB
Set to false to disable use of the database fields introduced by the ContentHandler facility.
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.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
static selectTextFields()
Return the list of text fields that should be selected to read the revision 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.
namespace and then decline to actually register it file or subcat img or subcat $title
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
setUserIdAndName( $id, $name)
Set the user ID/name.
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.
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
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)
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
static selectPageFields()
Return the list of page fields that should be selected from page table.
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.
Allows to change the fields on the form that will be generated $name
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 selectArchiveFields()
Return the list of revision fields that should be selected to create a new revision from an archive r...
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
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,...
const SCHEMA_COMPAT_WRITE_OLD
const GAID_FOR_UPDATE
Used to be GAID_FOR_UPDATE define.
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.
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
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
static userJoinCond()
Return the value of a select() JOIN conds array for the user table.
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 selectUserFields()
Return the list of user fields that should be selected from user table.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
static selectFields()
Return the list of revision fields that should be selected to create a new revision.
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()
int $wgActorTableSchemaMigrationStage
Actor table schema migration stage.