MediaWiki REL1_37
MergeHistory Class Reference

Handles the backend logic of merging the histories of two pages. More...

Collaboration diagram for MergeHistory:

Public Member Functions

 __construct (PageIdentity $source, PageIdentity $dest, ?string $timestamp, ILoadBalancer $loadBalancer, IContentHandlerFactory $contentHandlerFactory, RevisionStore $revisionStore, WatchedItemStoreInterface $watchedItemStore, SpamChecker $spamChecker, HookContainer $hookContainer, WikiPageFactory $wikiPageFactory, TitleFormatter $titleFormatter, TitleFactory $titleFactory)
 
 authorizeMerge (Authority $performer, string $reason=null)
 Authorize the merge by $performer.
 
 getMergedRevisionCount ()
 Get the number of revisions that were moved Used in the SpecialMergeHistory success message.
 
 getRevisionCount ()
 Get the number of revisions that will be moved.
 
 isValidMerge ()
 Does various sanity checks that the merge is valid.
 
 merge (Authority $performer, $reason='')
 Actually attempt the history move.
 
 probablyCanMerge (Authority $performer, string $reason=null)
 Check whether $performer can execute the merge.
 

Public Attributes

const REVISION_LIMIT = 5000
 Maximum number of revisions that can be merged at once.
 

Protected Attributes

IDatabase $dbw
 Database that we are using.
 
PageIdentity $dest
 Page to which history will be merged.
 
MWTimestamp false $maxTimestamp = false
 Maximum timestamp that we can use (oldest timestamp of dest).
 
int $revisionsMerged
 Number of revisions merged (for Special:MergeHistory success message)
 
PageIdentity $source
 Page from which history will be merged.
 
MWTimestamp false null $timestampLimit = false
 Timestamp upto which history from the source will be merged.
 
string false null $timeWhere = false
 SQL WHERE condition that selects source revisions to insert into destination.
 

Private Member Functions

 authorizeInternal (callable $authorizer, Authority $performer, string $reason)
 
 getMaxTimestamp ()
 Get the maximum timestamp that we can use (oldest timestamp of dest)
 
 getTimestampLimit ()
 Get the timestamp upto which history from the source will be merged, or null if something went wrong.
 
 getTimeWhere ()
 Get the SQL WHERE condition that selects source revisions to insert into destination, or null if something went wrong.
 
 initTimestampLimits ()
 Lazily initializes timestamp limits and conditions.
 
 updateSourcePage ( $status, $user, $reason)
 Do various cleanup work and updates to the source page.
 

Private Attributes

IContentHandlerFactory $contentHandlerFactory
 
HookRunner $hookRunner
 
RevisionStore $revisionStore
 
SpamChecker $spamChecker
 
string $timestamp
 Timestamp up to which history from the source will be merged.
 
TitleFactory $titleFactory
 
TitleFormatter $titleFormatter
 
WatchedItemStoreInterface $watchedItemStore
 
WikiPageFactory $wikiPageFactory
 

Detailed Description

Handles the backend logic of merging the histories of two pages.

Since
1.27

Definition at line 46 of file MergeHistory.php.

Constructor & Destructor Documentation

◆ __construct()

MergeHistory::__construct ( PageIdentity  $source,
PageIdentity  $dest,
?string  $timestamp,
ILoadBalancer  $loadBalancer,
IContentHandlerFactory  $contentHandlerFactory,
RevisionStore  $revisionStore,
WatchedItemStoreInterface  $watchedItemStore,
SpamChecker  $spamChecker,
HookContainer  $hookContainer,
WikiPageFactory  $wikiPageFactory,
TitleFormatter  $titleFormatter,
TitleFactory  $titleFactory 
)
Parameters
PageIdentity$sourcePage from which history will be merged
PageIdentity$destPage to which history will be merged
?string$timestamp Timestamp up to which history from the source will be merged
ILoadBalancer$loadBalancer
IContentHandlerFactory$contentHandlerFactory
RevisionStore$revisionStore
WatchedItemStoreInterface$watchedItemStore
SpamChecker$spamChecker
HookContainer$hookContainer
WikiPageFactory$wikiPageFactory
TitleFormatter$titleFormatter
TitleFactory$titleFactory

Definition at line 122 of file MergeHistory.php.

References $source, DB_PRIMARY, and Wikimedia\Rdbms\ILoadBalancer\getConnection().

Member Function Documentation

◆ authorizeInternal()

MergeHistory::authorizeInternal ( callable  $authorizer,
Authority  $performer,
string  $reason 
)
private
Parameters
callable$authorizer( string $action, PageIdentity $target, PermissionStatus $status )
Authority$performer
string$reason
Returns
PermissionStatus

Definition at line 183 of file MergeHistory.php.

References MediaWiki\Permissions\Authority\isAllowed().

Referenced by probablyCanMerge().

◆ authorizeMerge()

MergeHistory::authorizeMerge ( Authority  $performer,
string  $reason = null 
)

Authorize the merge by $performer.

Note
this method should be used right before the actual merge is performed. To check whether a current performer has the potential to merge the history, use self::probablyCanMerge instead.
Parameters
Authority$performer
string | null$reason
Returns
PermissionStatus

Definition at line 239 of file MergeHistory.php.

References MediaWiki\Permissions\Authority\authorizeWrite().

◆ getMaxTimestamp()

MergeHistory::getMaxTimestamp ( )
private

Get the maximum timestamp that we can use (oldest timestamp of dest)

Returns
MWTimestamp

Definition at line 515 of file MergeHistory.php.

◆ getMergedRevisionCount()

MergeHistory::getMergedRevisionCount ( )

Get the number of revisions that were moved Used in the SpecialMergeHistory success message.

Returns
int

Definition at line 173 of file MergeHistory.php.

◆ getRevisionCount()

MergeHistory::getRevisionCount ( )

Get the number of revisions that will be moved.

Returns
int

Definition at line 158 of file MergeHistory.php.

◆ getTimestampLimit()

MergeHistory::getTimestampLimit ( )
private

Get the timestamp upto which history from the source will be merged, or null if something went wrong.

Returns
?MWTimestamp

Definition at line 528 of file MergeHistory.php.

◆ getTimeWhere()

MergeHistory::getTimeWhere ( )
private

Get the SQL WHERE condition that selects source revisions to insert into destination, or null if something went wrong.

Returns
?string

Definition at line 541 of file MergeHistory.php.

◆ initTimestampLimits()

MergeHistory::initTimestampLimits ( )
private

Lazily initializes timestamp limits and conditions.

Definition at line 551 of file MergeHistory.php.

◆ isValidMerge()

MergeHistory::isValidMerge ( )

Does various sanity checks that the merge is valid.

Only things based on the two pages should be checked here.

Returns
Status

Definition at line 256 of file MergeHistory.php.

References Message\numParam().

◆ merge()

MergeHistory::merge ( Authority  $performer,
  $reason = '' 
)

Actually attempt the history move.

Todo:
if all versions of page A are moved to B and then a user tries to do a reverse-merge via the "unmerge" log link, then page A will still be a redirect (as it was after the original merge), though it will have the old revisions back from before (as expected). The user may have to "undo" the redirect manually to finish the "unmerge". Maybe this should delete redirects at the source page of merges?
Parameters
Authority$performer
string$reason
Returns
Status status of the history merge

Definition at line 304 of file MergeHistory.php.

References $wgActorTableSchemaMigrationStage, MediaWiki\Permissions\Authority\getUser(), SCHEMA_COMPAT_WRITE_TEMP, and wfMessage().

◆ probablyCanMerge()

MergeHistory::probablyCanMerge ( Authority  $performer,
string  $reason = null 
)

Check whether $performer can execute the merge.

Note
this method does not guarantee full permissions check, so it should only be used to to decide whether to show a merge form. To authorize the merge action use self::authorizeMerge instead.
Parameters
Authority$performer
string | null$reason
Returns
PermissionStatus

Definition at line 218 of file MergeHistory.php.

References authorizeInternal(), and MediaWiki\Permissions\Authority\probablyCan().

◆ updateSourcePage()

MergeHistory::updateSourcePage (   $status,
  $user,
  $reason 
)
private

Do various cleanup work and updates to the source page.

This method will only be called if no revision is remaining on the page.

At the end, there would be either a redirect page or a deleted page, depending on whether the content model of the page supports redirects or not.

Parameters
Status$status
UserIdentity$user
string$reason
Returns
Status

Definition at line 417 of file MergeHistory.php.

References wfMessage(), and wfTimestampNow().

Member Data Documentation

◆ $contentHandlerFactory

IContentHandlerFactory MergeHistory::$contentHandlerFactory
private

Definition at line 85 of file MergeHistory.php.

◆ $dbw

IDatabase MergeHistory::$dbw
protected

Database that we are using.

Definition at line 58 of file MergeHistory.php.

◆ $dest

PageIdentity MergeHistory::$dest
protected

Page to which history will be merged.

Definition at line 55 of file MergeHistory.php.

◆ $hookRunner

HookRunner MergeHistory::$hookRunner
private

Definition at line 97 of file MergeHistory.php.

◆ $maxTimestamp

MWTimestamp false MergeHistory::$maxTimestamp = false
protected

Maximum timestamp that we can use (oldest timestamp of dest).

Use ::getMaxTimestamp to lazily initialize.

Definition at line 67 of file MergeHistory.php.

◆ $revisionsMerged

int MergeHistory::$revisionsMerged
protected

Number of revisions merged (for Special:MergeHistory success message)

Definition at line 82 of file MergeHistory.php.

◆ $revisionStore

RevisionStore MergeHistory::$revisionStore
private

Definition at line 88 of file MergeHistory.php.

◆ $source

PageIdentity MergeHistory::$source
protected

Page from which history will be merged.

Definition at line 52 of file MergeHistory.php.

◆ $spamChecker

SpamChecker MergeHistory::$spamChecker
private

Definition at line 94 of file MergeHistory.php.

◆ $timestamp

string MergeHistory::$timestamp
private

Timestamp up to which history from the source will be merged.

Definition at line 61 of file MergeHistory.php.

◆ $timestampLimit

MWTimestamp false null MergeHistory::$timestampLimit = false
protected

Timestamp upto which history from the source will be merged.

Use getTimestampLimit to lazily initialize.

Definition at line 79 of file MergeHistory.php.

◆ $timeWhere

string false null MergeHistory::$timeWhere = false
protected

SQL WHERE condition that selects source revisions to insert into destination.

Use ::getTimeWhere to lazy-initialize.

Definition at line 73 of file MergeHistory.php.

◆ $titleFactory

TitleFactory MergeHistory::$titleFactory
private

Definition at line 106 of file MergeHistory.php.

◆ $titleFormatter

TitleFormatter MergeHistory::$titleFormatter
private

Definition at line 103 of file MergeHistory.php.

◆ $watchedItemStore

WatchedItemStoreInterface MergeHistory::$watchedItemStore
private

Definition at line 91 of file MergeHistory.php.

◆ $wikiPageFactory

WikiPageFactory MergeHistory::$wikiPageFactory
private

Definition at line 100 of file MergeHistory.php.

◆ REVISION_LIMIT

const MergeHistory::REVISION_LIMIT = 5000

Maximum number of revisions that can be merged at once.

Definition at line 49 of file MergeHistory.php.


The documentation for this class was generated from the following file: