MediaWiki  master
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, $timestamp=false, ILoadBalancer $loadBalancer=null, IContentHandlerFactory $contentHandlerFactory=null, RevisionStore $revisionStore=null, WatchedItemStoreInterface $watchedItemStore=null, SpamChecker $spamChecker=null, HookContainer $hookContainer=null, WikiPageFactory $wikiPageFactory=null, TitleFormatter $titleFormatter=null, TitleFactory $titleFactory=null)
 Since 1.35 dependencies are injected and not providing them is hard deprecated; use the MergeHistoryFactory service. More...
 
 authorizeMerge (Authority $performer, string $reason=null)
 Authorize the merge by $performer. More...
 
 checkPermissions (Authority $performer, $reason)
 Check if the merge is possible. More...
 
 getMergedRevisionCount ()
 Get the number of revisions that were moved Used in the SpecialMergeHistory success message. More...
 
 getRevisionCount ()
 Get the number of revisions that will be moved. More...
 
 isValidMerge ()
 Does various sanity checks that the merge is valid. More...
 
 merge (Authority $performer, $reason='')
 Actually attempt the history move. More...
 
 probablyCanMerge (Authority $performer, string $reason=null)
 Check whether $performer can execute the merge. More...
 

Public Attributes

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

Protected Attributes

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

Private Member Functions

 authorizeInternal (callable $authorizer, Authority $performer, string $reason)
 
 updateSourcePage ( $status, $user, $reason)
 Do various cleanup work and updates to the source page. More...
 

Private Attributes

IContentHandlerFactory $contentHandlerFactory
 
HookRunner $hookRunner
 
RevisionStore $revisionStore
 
SpamChecker $spamChecker
 
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 47 of file MergeHistory.php.

Constructor & Destructor Documentation

◆ __construct()

MergeHistory::__construct ( PageIdentity  $source,
PageIdentity  $dest,
  $timestamp = false,
ILoadBalancer  $loadBalancer = null,
IContentHandlerFactory  $contentHandlerFactory = null,
RevisionStore  $revisionStore = null,
WatchedItemStoreInterface  $watchedItemStore = null,
SpamChecker  $spamChecker = null,
HookContainer  $hookContainer = null,
WikiPageFactory  $wikiPageFactory = null,
TitleFormatter  $titleFormatter = null,
TitleFactory  $titleFactory = null 
)

Since 1.35 dependencies are injected and not providing them is hard deprecated; use the MergeHistoryFactory service.

Parameters
PageIdentity$sourcePage from which history will be merged
PageIdentity$destPage to which history will be merged
string | bool$timestampTimestamp up to which history from the source will be merged
ILoadBalancer | null$loadBalancer
IContentHandlerFactory | null$contentHandlerFactory
RevisionStore | null$revisionStore
WatchedItemStoreInterface | null$watchedItemStore
SpamChecker | null$spamChecker
HookContainer | null$hookContainer
WikiPageFactory | null$wikiPageFactory
TitleFormatter | null$titleFormatter
TitleFactory | null$titleFactory

Definition at line 114 of file MergeHistory.php.

References $contentHandlerFactory, $dest, $maxTimestamp, $revisionStore, $source, $spamChecker, $titleFactory, $titleFormatter, $watchedItemStore, $wikiPageFactory, DB_PRIMARY, and wfDeprecatedMsg().

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 246 of file MergeHistory.php.

References MediaWiki\Permissions\Authority\isAllowed().

Referenced by authorizeMerge(), checkPermissions(), and 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 302 of file MergeHistory.php.

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

Referenced by merge().

◆ checkPermissions()

MergeHistory::checkPermissions ( Authority  $performer,
  $reason 
)

Check if the merge is possible.

Deprecated:
since 1.36. Use ::authorizeMerge or ::probablyCanMerge instead.
Parameters
Authority$performer
string$reason
Returns
Status

Definition at line 319 of file MergeHistory.php.

References authorizeInternal(), MediaWiki\Permissions\Authority\definitelyCan(), wfDeprecated(), and Status\wrap().

◆ getMergedRevisionCount()

MergeHistory::getMergedRevisionCount ( )

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

Returns
int

Definition at line 236 of file MergeHistory.php.

References $revisionsMerged.

◆ getRevisionCount()

MergeHistory::getRevisionCount ( )

Get the number of revisions that will be moved.

Returns
int

Definition at line 221 of file MergeHistory.php.

Referenced by isValidMerge().

◆ 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 338 of file MergeHistory.php.

References getRevisionCount(), and Message\numParam().

Referenced by merge().

◆ 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 386 of file MergeHistory.php.

References authorizeMerge(), MediaWiki\Permissions\Authority\getUser(), isValidMerge(), TitleValue\newFromPage(), updateSourcePage(), wfMessage(), and Status\wrap().

◆ 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 281 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 497 of file MergeHistory.php.

References MediaWiki\Logger\LoggerFactory\getInstance(), CommentStoreComment\newUnsavedComment(), wfMessage(), and wfTimestampNow().

Referenced by merge().

Member Data Documentation

◆ $contentHandlerFactory

IContentHandlerFactory MergeHistory::$contentHandlerFactory
private

Definition at line 74 of file MergeHistory.php.

Referenced by __construct().

◆ $dbw

IDatabase MergeHistory::$dbw
protected

Database that we are using.

Definition at line 59 of file MergeHistory.php.

◆ $dest

PageIdentity MergeHistory::$dest
protected

Page to which history will be merged.

Definition at line 56 of file MergeHistory.php.

Referenced by __construct().

◆ $hookRunner

HookRunner MergeHistory::$hookRunner
private

Definition at line 86 of file MergeHistory.php.

◆ $maxTimestamp

MWTimestamp MergeHistory::$maxTimestamp
protected

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

Definition at line 62 of file MergeHistory.php.

Referenced by __construct().

◆ $revisionsMerged

int MergeHistory::$revisionsMerged
protected

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

Definition at line 71 of file MergeHistory.php.

Referenced by getMergedRevisionCount().

◆ $revisionStore

RevisionStore MergeHistory::$revisionStore
private

Definition at line 77 of file MergeHistory.php.

Referenced by __construct().

◆ $source

PageIdentity MergeHistory::$source
protected

Page from which history will be merged.

Definition at line 53 of file MergeHistory.php.

Referenced by __construct().

◆ $spamChecker

SpamChecker MergeHistory::$spamChecker
private

Definition at line 83 of file MergeHistory.php.

Referenced by __construct().

◆ $timestampLimit

MWTimestamp bool MergeHistory::$timestampLimit
protected

Timestamp upto which history from the source will be merged.

Definition at line 68 of file MergeHistory.php.

◆ $timeWhere

string MergeHistory::$timeWhere
protected

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

Definition at line 65 of file MergeHistory.php.

◆ $titleFactory

TitleFactory MergeHistory::$titleFactory
private

Definition at line 95 of file MergeHistory.php.

Referenced by __construct().

◆ $titleFormatter

TitleFormatter MergeHistory::$titleFormatter
private

Definition at line 92 of file MergeHistory.php.

Referenced by __construct().

◆ $watchedItemStore

WatchedItemStoreInterface MergeHistory::$watchedItemStore
private

Definition at line 80 of file MergeHistory.php.

Referenced by __construct().

◆ $wikiPageFactory

WikiPageFactory MergeHistory::$wikiPageFactory
private

Definition at line 89 of file MergeHistory.php.

Referenced by __construct().

◆ REVISION_LIMIT

const MergeHistory::REVISION_LIMIT = 5000

Maximum number of revisions that can be merged at once.

Definition at line 50 of file MergeHistory.php.


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