Go to the documentation of this file.
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__
327 .
' when $wgActorTableSchemaMigrationStage has SCHEMA_COMPAT_READ_NEW'
331 return [
'LEFT JOIN', [
'rev_user != 0',
'user_id = rev_user' ] ];
343 return [
'INNER JOIN', [
'page_id = rev_page' ] ];
361 throw new BadMethodCallException(
362 'Cannot use ' . __METHOD__
363 .
' when $wgActorTableSchemaMigrationStage has SCHEMA_COMPAT_READ_NEW'
373 throw new BadMethodCallException(
374 'Cannot use ' . __METHOD__ .
' when $wgMultiContentRevisionSchemaMigrationStage '
375 .
'does not have SCHEMA_COMPAT_WRITE_OLD set.'
388 'rev_actor' =>
'NULL',
399 $fields[] =
'rev_content_format';
400 $fields[] =
'rev_content_model';
421 throw new BadMethodCallException(
422 'Cannot use ' . __METHOD__
423 .
' when $wgActorTableSchemaMigrationStage has SCHEMA_COMPAT_READ_NEW'
433 throw new BadMethodCallException(
434 'Cannot use ' . __METHOD__ .
' when $wgMultiContentRevisionSchemaMigrationStage '
435 .
'does not have SCHEMA_COMPAT_WRITE_OLD set.'
449 'ar_actor' =>
'NULL',
460 $fields[] =
'ar_content_format';
461 $fields[] =
'ar_content_model';
504 return [
'user_name' ];
563 $this->mRecord = $row;
564 } elseif ( is_array( $row ) ) {
567 if ( !isset( $row[
'user'] ) && !isset( $row[
'user_text'] ) ) {
568 $row[
'user'] = $wgUser;
576 } elseif ( is_object( $row ) ) {
583 throw new InvalidArgumentException(
584 '$row must be a row object, an associative array, or a RevisionRecord'
604 if ( is_array( $row ) ) {
605 if ( isset( $row[
'title'] ) ) {
606 if ( !( $row[
'title'] instanceof
Title ) ) {
607 throw new MWException(
'title field must contain a Title object.' );
610 return $row[
'title'];
613 $pageId = $row[
'page'] ?? 0;
614 $revId = $row[
'id'] ?? 0;
616 $pageId = $row->rev_page ?? 0;
617 $revId = $row->rev_id ?? 0;
628 $title->resetArticleID( $pageId );
647 return $this->mRecord->getId();
664 $this->mRecord->setId( intval( $id ) );
666 throw new MWException( __METHOD__ .
' is not supported on this instance' );
687 $this->mRecord->setUser(
$user );
689 throw new MWException( __METHOD__ .
' is not supported on this instance' );
714 return $slot->hasAddress()
726 return $this->mRecord->getParentId();
736 return $this->mRecord->getSize();
749 return $this->mRecord->getSha1();
764 $linkTarget = $this->mRecord->getPageAsLinkTarget();
776 if ( !
$title->equals( $this->getTitle() ) ) {
777 throw new InvalidArgumentException(
779 .
' is not the same as '
780 . $this->mRecord->getPageAsLinkTarget()->__toString()
791 return $this->mRecord->getPageId();
810 if ( $audience === self::FOR_THIS_USER && !
$user ) {
814 $user = $this->mRecord->getUser( $audience,
$user );
834 if ( $audience === self::FOR_THIS_USER && !
$user ) {
838 $user = $this->mRecord->getUser( $audience,
$user );
857 if ( $audience === self::FOR_THIS_USER && !
$user ) {
861 $comment = $this->mRecord->getComment( $audience,
$user );
862 return $comment ===
null ? null : $comment->text;
869 return $this->mRecord->isMinor();
898 return $this->mRecord->isDeleted( $field );
907 return $this->mRecord->getVisibility();
927 if ( $audience === self::FOR_THIS_USER && !
$user ) {
949 return $slot->getContent()->serialize();
982 if ( $format ===
null ) {
1004 return $this->mRecord->getTimestamp();
1022 return $rec ===
null ? null :
new Revision( $rec, self::READ_NORMAL,
$title );
1033 return $rec ===
null ? null :
new Revision( $rec, self::READ_NORMAL,
$title );
1051 $textField = $prefix .
'text';
1052 $flagsField = $prefix .
'flags';
1054 if ( isset( $row->$flagsField ) ) {
1055 $flags = explode(
',', $row->$flagsField );
1060 if ( isset( $row->$textField ) ) {
1061 $text = $row->$textField;
1066 $cacheKey = isset( $row->old_id )
1067 ? SqlBlobStore::makeAddressFromTextId( $row->old_id )
1072 if ( $revisionText ===
false ) {
1073 if ( isset( $row->old_id ) ) {
1074 wfLogWarning( __METHOD__ .
": Bad data in text row {$row->old_id}! " );
1076 wfLogWarning( __METHOD__ .
": Bad data in text row! " );
1081 return $revisionText;
1106 if ( $text ===
false ) {
1130 $this->mRecord->setUser( $wgUser );
1132 throw new MWException(
'Cannot insert revision with no associated user.' );
1138 $this->mRecord = $rec;
1143 return $rec->getId();
1185 return $rec ?
new Revision( $rec ) :
null;
1279 if ( is_int( $db ) ) {
1309 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.
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 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.
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.
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.
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.
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 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.
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.
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 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)
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.
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.