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 ) ) {
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'
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',
396 $fields += CommentStore::getStore()->getFields(
'rev_comment' );
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',
457 $fields += CommentStore::getStore()->getFields(
'ar_comment' );
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'
599 private function ensureTitle( $row, $queryFlags, $title =
null ) {
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' );
697 return $this->mRecord->getSlot( SlotRecord::MAIN, RevisionRecord::RAW );
714 return $slot->hasAddress()
726 return $this->mRecord->getParentId();
736 return $this->mRecord->getSize();
749 return $this->mRecord->getSha1();
764 $linkTarget = $this->mRecord->getPageAsLinkTarget();
765 return Title::newFromLinkTarget( $linkTarget );
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();
807 public function getUser( $audience = self::FOR_PUBLIC,
User $user =
null ) {
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 ) {
932 return $this->mRecord->getContent( SlotRecord::MAIN, $audience,
$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 ) {
1128 if ( $this->mRecord->getUser( RevisionRecord::RAW ) ===
null ) {
1130 $this->mRecord->setUser( $wgUser );
1132 throw new MWException(
'Cannot insert revision with no associated user.' );
1138 $this->mRecord = $rec;
1143 return $rec->getId();
1152 return SlotRecord::base36Sha1( $text );
1176 $comment = CommentStoreComment::newUnsavedComment( $summary,
null );
1178 $title = Title::newFromID( $pageId, Title::GAID_FOR_UPDATE );
1185 return $rec ?
new Revision( $rec ) :
null;
1225 return RevisionRecord::userCanBitfield( $bitfield, $field,
$user,
$title );
1279 if ( is_int( $db ) ) {
1302 : Title::newFromID( $pageIdOrTitle );
1309 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.
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.
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.
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()
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.
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
Allows to change the fields on the form that will be generated $name
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 local account $user
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))