32use Wikimedia\Assert\Assert;
56 const RAW = RevisionRecord::RAW;
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 ) ) {
198 $title = Title::makeTitle( $row->ar_namespace, $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',
386 $fields += CommentStore::getStore()->getFields(
'rev_comment' );
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',
447 $fields += CommentStore::getStore()->getFields(
'ar_comment' );
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' );
591 private function ensureTitle( $row, $queryFlags, $title =
null ) {
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' );
689 return $this->mRecord->getSlot( SlotRecord::MAIN, RevisionRecord::RAW );
706 return $slot->hasAddress()
718 return $this->mRecord->getParentId();
728 return $this->mRecord->getSize();
741 return $this->mRecord->getSha1();
756 $linkTarget = $this->mRecord->getPageAsLinkTarget();
757 return Title::newFromLinkTarget( $linkTarget );
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();
799 public function getUser( $audience = self::FOR_PUBLIC,
User $user =
null ) {
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 ) {
923 return $this->mRecord->getContent( SlotRecord::MAIN, $audience,
$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 ) {
1158 if ( $this->mRecord->getUser( RevisionRecord::RAW ) ===
null ) {
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();
1180 return SlotRecord::base36Sha1( $text );
1204 $comment = CommentStoreComment::newUnsavedComment( $summary,
null );
1206 $title = Title::newFromID( $pageId, Title::GAID_FOR_UPDATE );
1213 return $rec ?
new Revision( $rec ) :
null;
1253 return RevisionRecord::userCanBitfield( $bitfield, $field,
$user,
$title );
1307 if ( is_int( $db ) ) {
1330 : Title::newFromID( $pageIdOrTitle );
1337 return $record ?
new Revision( $record ) :
false;
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
int $wgMultiContentRevisionSchemaMigrationStage
RevisionStore table schema migration stage (content, slots, content_models & slot_roles tables).
$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.
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.
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)
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 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.
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)
Static factory method for creation from an ID, name, and/or actor ID.
const SCHEMA_COMPAT_READ_NEW
const SCHEMA_COMPAT_WRITE_OLD
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
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
Allows to change the fields on the form that will be generated $name
return true to allow those checks to and false if checking is done & $user
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
returning false will NOT prevent logging $e
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
Interface for database access objects.
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))