Go to the documentation of this file.
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 )
116 return $rec ===
null ? null :
new Revision( $rec, $flags );
135 return $rec ===
null ? null :
new Revision( $rec, $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'];
193 if ( isset( $row->ar_namespace ) && isset( $row->ar_title ) ) {
196 throw new InvalidArgumentException(
197 'A Title or ar_namespace and ar_title must be given'
219 if ( is_array( $row ) ) {
241 return $rec ===
null ? null :
new Revision( $rec );
258 return $rec ===
null ? null :
new Revision( $rec );
275 return $rec ===
null ? null :
new Revision( $rec );
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',
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',
431 $fields[] =
'ar_content_format';
432 $fields[] =
'ar_content_model';
475 return [
'user_name' ];
534 $this->mRecord = $row;
535 } elseif ( is_array( $row ) ) {
538 if ( !isset( $row[
'user'] ) && !isset( $row[
'user_text'] ) ) {
547 } elseif ( is_object( $row ) ) {
554 throw new InvalidArgumentException(
555 '$row must be a row object, an associative array, or a RevisionRecord'
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;
599 $title->resetArticleID( $pageId );
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()
697 return $this->mRecord->getParentId();
707 return $this->mRecord->getSize();
720 return $this->mRecord->getSha1();
735 $linkTarget = $this->mRecord->getPageAsLinkTarget();
747 if ( !
$title->equals( $this->getTitle() ) ) {
748 throw new InvalidArgumentException(
750 .
' is not the same as '
751 . $this->mRecord->getPageAsLinkTarget()->__toString()
762 return $this->mRecord->getPageId();
781 if ( $audience === self::FOR_THIS_USER && !
$user ) {
785 $user = $this->mRecord->getUser( $audience,
$user );
797 return $this->
getUser( self::RAW );
816 if ( $audience === self::FOR_THIS_USER && !
$user ) {
820 $user = $this->mRecord->getUser( $audience,
$user );
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();
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 ) {
1009 return $this->mRecord->getTimestamp();
1027 return $rec ===
null ? null :
new Revision( $rec, self::READ_NORMAL,
$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;
1115 if ( $this->mRecord->getUser( RevisionRecord::RAW ) ===
null ) {
1117 $this->mRecord->setUser(
$wgUser );
1119 throw new MWException(
'Cannot insert revision with no associated user.' );
1125 $this->mRecord = $rec;
1130 Hooks::run(
'RevisionInsertComplete', [ &$revision,
null,
null ] );
1132 return $rec->getId();
1141 return SlotRecord::base36Sha1( $text );
1214 return RevisionRecord::userCanBitfield( $bitfield, $field,
$user,
$title );
1268 if ( is_int( $db ) ) {
1298 return $record ?
new Revision( $record ) :
false;
static newFromArchiveRow( $row, $overrides=[])
Make a fake revision object from an archive table row.
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
static getForModelID( $modelId)
Returns the ContentHandler singleton for the given model ID.
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.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
static newFromId( $id, $flags=0)
Load a page revision from a given revision ID number.
getRawUser()
Fetch revision's user id without regard for the current user's permissions.
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,...
the array() calling protocol came about after MediaWiki 1.4rc1.
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)
const MIGRATION_WRITE_BOTH
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.
static getRevisionStore()
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.
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.
static newFromLinkTarget(LinkTarget $linkTarget)
Create a new Title from a LinkTarget.
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.
namespace and then decline to actually register it file or subcat img or subcat $title
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
when a variable name is used in a it is silently declared as a new masking the global
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.
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
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.
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...
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 GAID_FOR_UPDATE
Used to be GAID_FOR_UPDATE define.
getRawUserText()
Fetch revision's username without regard for view restrictions.
getContentFormat()
Returns the content format for the main slot of this revision.
static fetchRevision(LinkTarget $title)
Return a wrapper for a series of database rows to fetch all of a given page's revisions in turn.
Represents a title within MediaWiki.
Allows to change the fields on the form that will be generated $name
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.
getRawComment()
Fetch revision comment without regard for the current user's permissions.
getComment( $audience=self::FOR_PUBLIC, User $user=null)
Fetch revision comment if it's available to the specified audience.
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.
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
userCan( $field, User $user=null)
Determine if the current user is allowed to view a particular field of this revision,...
static getRevisionLookup()
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
int $wgActorTableSchemaMigrationStage
Actor table schema migration stage.