2015-12-30 04:53:34 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Copyright © 2015 Geoffrey Mon <geofbot@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
*/
|
2020-04-28 22:54:18 +00:00
|
|
|
|
|
|
|
|
use MediaWiki\Content\IContentHandlerFactory;
|
2020-05-13 21:30:46 +00:00
|
|
|
use MediaWiki\EditPage\SpamChecker;
|
2016-04-11 10:41:39 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2020-04-28 22:54:18 +00:00
|
|
|
use MediaWiki\Permissions\PermissionManager;
|
2020-03-29 21:16:50 +00:00
|
|
|
use MediaWiki\Revision\MutableRevisionRecord;
|
2020-04-28 22:54:18 +00:00
|
|
|
use MediaWiki\Revision\RevisionStore;
|
2020-03-29 21:16:50 +00:00
|
|
|
use MediaWiki\Revision\SlotRecord;
|
2017-02-10 18:09:05 +00:00
|
|
|
use Wikimedia\Rdbms\IDatabase;
|
2020-04-28 22:54:18 +00:00
|
|
|
use Wikimedia\Rdbms\ILoadBalancer;
|
2020-01-10 00:00:51 +00:00
|
|
|
use Wikimedia\Timestamp\TimestampException;
|
2015-12-30 04:53:34 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handles the backend logic of merging the histories of two
|
|
|
|
|
* pages.
|
|
|
|
|
*
|
|
|
|
|
* @since 1.27
|
|
|
|
|
*/
|
|
|
|
|
class MergeHistory {
|
|
|
|
|
|
2019-02-26 13:02:50 +00:00
|
|
|
/** Maximum number of revisions that can be merged at once */
|
2020-05-11 00:48:27 +00:00
|
|
|
public const REVISION_LIMIT = 5000;
|
2015-12-30 04:53:34 +00:00
|
|
|
|
|
|
|
|
/** @var Title Page from which history will be merged */
|
|
|
|
|
protected $source;
|
|
|
|
|
|
|
|
|
|
/** @var Title Page to which history will be merged */
|
|
|
|
|
protected $dest;
|
|
|
|
|
|
2016-09-26 22:40:07 +00:00
|
|
|
/** @var IDatabase Database that we are using */
|
2015-12-30 04:53:34 +00:00
|
|
|
protected $dbw;
|
|
|
|
|
|
|
|
|
|
/** @var MWTimestamp Maximum timestamp that we can use (oldest timestamp of dest) */
|
|
|
|
|
protected $maxTimestamp;
|
|
|
|
|
|
|
|
|
|
/** @var string SQL WHERE condition that selects source revisions to insert into destination */
|
|
|
|
|
protected $timeWhere;
|
|
|
|
|
|
2016-03-24 08:44:09 +00:00
|
|
|
/** @var MWTimestamp|bool Timestamp upto which history from the source will be merged */
|
2015-12-30 04:53:34 +00:00
|
|
|
protected $timestampLimit;
|
|
|
|
|
|
2017-08-20 11:20:59 +00:00
|
|
|
/** @var int Number of revisions merged (for Special:MergeHistory success message) */
|
2015-12-30 04:53:34 +00:00
|
|
|
protected $revisionsMerged;
|
|
|
|
|
|
2020-04-28 22:54:18 +00:00
|
|
|
/** @var PermissionManager */
|
|
|
|
|
private $permManager;
|
|
|
|
|
|
|
|
|
|
/** @var IContentHandlerFactory */
|
|
|
|
|
private $contentHandlerFactory;
|
|
|
|
|
|
|
|
|
|
/** @var RevisionStore */
|
|
|
|
|
private $revisionStore;
|
|
|
|
|
|
|
|
|
|
/** @var WatchedItemStoreInterface */
|
|
|
|
|
private $watchedItemStore;
|
|
|
|
|
|
2020-05-13 21:30:46 +00:00
|
|
|
/** @var SpamChecker */
|
|
|
|
|
private $spamChecker;
|
|
|
|
|
|
2015-12-30 04:53:34 +00:00
|
|
|
/**
|
2020-04-28 22:54:18 +00:00
|
|
|
* Since 1.35 dependencies are injected and not providing them is hard deprecated; use the
|
|
|
|
|
* MergeHistoryFactory service
|
|
|
|
|
*
|
2015-12-30 04:53:34 +00:00
|
|
|
* @param Title $source Page from which history will be merged
|
|
|
|
|
* @param Title $dest Page to which history will be merged
|
2016-03-24 08:44:09 +00:00
|
|
|
* @param string|bool $timestamp Timestamp up to which history from the source will be merged
|
2020-04-28 22:54:18 +00:00
|
|
|
* @param ILoadBalancer|null $loadBalancer
|
|
|
|
|
* @param PermissionManager|null $permManager
|
|
|
|
|
* @param IContentHandlerFactory|null $contentHandlerFactory
|
|
|
|
|
* @param RevisionStore|null $revisionStore
|
|
|
|
|
* @param WatchedItemStoreInterface|null $watchedItemStore
|
2020-05-13 21:30:46 +00:00
|
|
|
* @param SpamChecker|null $spamChecker
|
2015-12-30 04:53:34 +00:00
|
|
|
*/
|
2020-04-28 22:54:18 +00:00
|
|
|
public function __construct(
|
|
|
|
|
Title $source,
|
|
|
|
|
Title $dest,
|
|
|
|
|
$timestamp = false,
|
|
|
|
|
ILoadBalancer $loadBalancer = null,
|
|
|
|
|
PermissionManager $permManager = null,
|
|
|
|
|
IContentHandlerFactory $contentHandlerFactory = null,
|
|
|
|
|
RevisionStore $revisionStore = null,
|
2020-05-13 21:30:46 +00:00
|
|
|
WatchedItemStoreInterface $watchedItemStore = null,
|
|
|
|
|
SpamChecker $spamChecker = null
|
2020-04-28 22:54:18 +00:00
|
|
|
) {
|
|
|
|
|
if ( $loadBalancer === null ) {
|
Introduce wfDeprecatedMsg()
Deprecating something means to say something nasty about it, or to draw
its character into question. For example, "this function is lazy and good
for nothing". Deprecatory remarks by a developer are generally taken as a
warning that violence will soon be done against the function in question.
Other developers are thus warned to avoid associating with the deprecated
function.
However, since wfDeprecated() was introduced, it has become obvious that
the targets of deprecation are not limited to functions. Developers can
deprecate literally anything: a parameter, a return value, a file
format, Mondays, the concept of being, etc. wfDeprecated() requires
every deprecatory statement to begin with "use of", leading to some
awkward sentences. For example, one might say: "Use of your mouth to
cough without it being covered by your arm is deprecated since 2020."
So, introduce wfDeprecatedMsg(), which allows deprecation messages to be
specified in plain text, with the caller description being optionally
appended. Migrate incorrect or gramatically awkward uses of wfDeprecated()
to wfDeprecatedMsg().
Change-Id: Ib3dd2fe37677d98425d0f3692db5c9e988943ae8
2020-06-12 04:18:35 +00:00
|
|
|
wfDeprecatedMsg( 'Direct construction of ' . __CLASS__ .
|
|
|
|
|
' was deprecated in MediaWiki 1.35', '1.35' );
|
2020-04-28 22:54:18 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
|
|
|
|
|
|
$loadBalancer = $services->getDBLoadBalancer();
|
|
|
|
|
$permManager = $services->getPermissionManager();
|
|
|
|
|
$contentHandlerFactory = $services->getContentHandlerFactory();
|
|
|
|
|
$revisionStore = $services->getRevisionStore();
|
|
|
|
|
$watchedItemStore = $services->getWatchedItemStore();
|
2020-05-13 21:30:46 +00:00
|
|
|
$spamChecker = $services->getSpamChecker();
|
2020-04-28 22:54:18 +00:00
|
|
|
}
|
|
|
|
|
|
2015-12-30 04:53:34 +00:00
|
|
|
// Save the parameters
|
|
|
|
|
$this->source = $source;
|
|
|
|
|
$this->dest = $dest;
|
|
|
|
|
|
|
|
|
|
// Get the database
|
2020-04-28 22:54:18 +00:00
|
|
|
$this->dbw = $loadBalancer->getConnection( DB_MASTER );
|
|
|
|
|
|
|
|
|
|
$this->permManager = $permManager;
|
|
|
|
|
$this->contentHandlerFactory = $contentHandlerFactory;
|
|
|
|
|
$this->revisionStore = $revisionStore;
|
|
|
|
|
$this->watchedItemStore = $watchedItemStore;
|
2020-05-13 21:30:46 +00:00
|
|
|
$this->spamChecker = $spamChecker;
|
2015-12-30 04:53:34 +00:00
|
|
|
|
|
|
|
|
// Max timestamp should be min of destination page
|
|
|
|
|
$firstDestTimestamp = $this->dbw->selectField(
|
|
|
|
|
'revision',
|
|
|
|
|
'MIN(rev_timestamp)',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'rev_page' => $this->dest->getArticleID() ],
|
2015-12-30 04:53:34 +00:00
|
|
|
__METHOD__
|
|
|
|
|
);
|
|
|
|
|
$this->maxTimestamp = new MWTimestamp( $firstDestTimestamp );
|
|
|
|
|
|
|
|
|
|
// Get the timestamp pivot condition
|
|
|
|
|
try {
|
|
|
|
|
if ( $timestamp ) {
|
|
|
|
|
// If we have a requested timestamp, use the
|
|
|
|
|
// latest revision up to that point as the insertion point
|
|
|
|
|
$mwTimestamp = new MWTimestamp( $timestamp );
|
|
|
|
|
$lastWorkingTimestamp = $this->dbw->selectField(
|
|
|
|
|
'revision',
|
|
|
|
|
'MAX(rev_timestamp)',
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2016-10-29 16:16:39 +00:00
|
|
|
'rev_timestamp <= ' .
|
|
|
|
|
$this->dbw->addQuotes( $this->dbw->timestamp( $mwTimestamp ) ),
|
2015-12-30 04:53:34 +00:00
|
|
|
'rev_page' => $this->source->getArticleID()
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2015-12-30 04:53:34 +00:00
|
|
|
__METHOD__
|
|
|
|
|
);
|
|
|
|
|
$mwLastWorkingTimestamp = new MWTimestamp( $lastWorkingTimestamp );
|
|
|
|
|
|
|
|
|
|
$timeInsert = $mwLastWorkingTimestamp;
|
|
|
|
|
$this->timestampLimit = $mwLastWorkingTimestamp;
|
|
|
|
|
} else {
|
|
|
|
|
// If we don't, merge entire source page history into the
|
|
|
|
|
// beginning of destination page history
|
|
|
|
|
|
|
|
|
|
// Get the latest timestamp of the source
|
|
|
|
|
$lastSourceTimestamp = $this->dbw->selectField(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'page', 'revision' ],
|
2015-12-30 04:53:34 +00:00
|
|
|
'rev_timestamp',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'page_id' => $this->source->getArticleID(),
|
2015-12-30 04:53:34 +00:00
|
|
|
'page_latest = rev_id'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2015-12-30 04:53:34 +00:00
|
|
|
__METHOD__
|
|
|
|
|
);
|
|
|
|
|
$lasttimestamp = new MWTimestamp( $lastSourceTimestamp );
|
|
|
|
|
|
|
|
|
|
$timeInsert = $this->maxTimestamp;
|
|
|
|
|
$this->timestampLimit = $lasttimestamp;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-29 16:16:39 +00:00
|
|
|
$this->timeWhere = "rev_timestamp <= " .
|
|
|
|
|
$this->dbw->addQuotes( $this->dbw->timestamp( $timeInsert ) );
|
2015-12-30 04:53:34 +00:00
|
|
|
} catch ( TimestampException $ex ) {
|
|
|
|
|
// The timestamp we got is screwed up and merge cannot continue
|
|
|
|
|
// This should be detected by $this->isValidMerge()
|
|
|
|
|
$this->timestampLimit = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the number of revisions that will be moved
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function getRevisionCount() {
|
|
|
|
|
$count = $this->dbw->selectRowCount( 'revision', '1',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'rev_page' => $this->source->getArticleID(), $this->timeWhere ],
|
2015-12-30 04:53:34 +00:00
|
|
|
__METHOD__,
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'LIMIT' => self::REVISION_LIMIT + 1 ]
|
2015-12-30 04:53:34 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the number of revisions that were moved
|
|
|
|
|
* Used in the SpecialMergeHistory success message
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function getMergedRevisionCount() {
|
|
|
|
|
return $this->revisionsMerged;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if the merge is possible
|
|
|
|
|
* @param User $user
|
|
|
|
|
* @param string $reason
|
|
|
|
|
* @return Status
|
|
|
|
|
*/
|
|
|
|
|
public function checkPermissions( User $user, $reason ) {
|
|
|
|
|
$status = new Status();
|
|
|
|
|
|
|
|
|
|
// Check if user can edit both pages
|
|
|
|
|
$errors = wfMergeErrorArrays(
|
2020-04-28 22:54:18 +00:00
|
|
|
$this->permManager->getPermissionErrors( 'edit', $user, $this->source ),
|
|
|
|
|
$this->permManager->getPermissionErrors( 'edit', $user, $this->dest )
|
2015-12-30 04:53:34 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Convert into a Status object
|
|
|
|
|
if ( $errors ) {
|
|
|
|
|
foreach ( $errors as $error ) {
|
2018-06-08 02:58:35 +00:00
|
|
|
$status->fatal( ...$error );
|
2015-12-30 04:53:34 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Anti-spam
|
2020-05-13 21:30:46 +00:00
|
|
|
if ( $this->spamChecker->checkSummary( $reason ) !== false ) {
|
2015-12-30 04:53:34 +00:00
|
|
|
// This is kind of lame, won't display nice
|
|
|
|
|
$status->fatal( 'spamprotectiontext' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check mergehistory permission
|
2020-04-28 22:54:18 +00:00
|
|
|
if ( !$this->permManager->userHasRight( $user, 'mergehistory' ) ) {
|
2015-12-30 04:53:34 +00:00
|
|
|
// User doesn't have the right to merge histories
|
|
|
|
|
$status->fatal( 'mergehistory-fail-permission' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Does various sanity checks that the merge is
|
|
|
|
|
* valid. Only things based on the two pages
|
|
|
|
|
* should be checked here.
|
|
|
|
|
*
|
|
|
|
|
* @return Status
|
|
|
|
|
*/
|
|
|
|
|
public function isValidMerge() {
|
|
|
|
|
$status = new Status();
|
|
|
|
|
|
|
|
|
|
// If either article ID is 0, then revisions cannot be reliably selected
|
|
|
|
|
if ( $this->source->getArticleID() === 0 ) {
|
|
|
|
|
$status->fatal( 'mergehistory-fail-invalid-source' );
|
|
|
|
|
}
|
|
|
|
|
if ( $this->dest->getArticleID() === 0 ) {
|
|
|
|
|
$status->fatal( 'mergehistory-fail-invalid-dest' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Make sure page aren't the same
|
|
|
|
|
if ( $this->source->equals( $this->dest ) ) {
|
|
|
|
|
$status->fatal( 'mergehistory-fail-self-merge' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Make sure the timestamp is valid
|
|
|
|
|
if ( !$this->timestampLimit ) {
|
|
|
|
|
$status->fatal( 'mergehistory-fail-bad-timestamp' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// $this->timestampLimit must be older than $this->maxTimestamp
|
|
|
|
|
if ( $this->timestampLimit > $this->maxTimestamp ) {
|
|
|
|
|
$status->fatal( 'mergehistory-fail-timestamps-overlap' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check that there are not too many revisions to move
|
|
|
|
|
if ( $this->timestampLimit && $this->getRevisionCount() > self::REVISION_LIMIT ) {
|
|
|
|
|
$status->fatal( 'mergehistory-fail-toobig', Message::numParam( self::REVISION_LIMIT ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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?
|
|
|
|
|
*
|
|
|
|
|
* @param User $user
|
|
|
|
|
* @param string $reason
|
|
|
|
|
* @return Status status of the history merge
|
|
|
|
|
*/
|
|
|
|
|
public function merge( User $user, $reason = '' ) {
|
|
|
|
|
$status = new Status();
|
|
|
|
|
|
|
|
|
|
// Check validity and permissions required for merge
|
|
|
|
|
$validCheck = $this->isValidMerge(); // Check this first to check for null pages
|
|
|
|
|
if ( !$validCheck->isOK() ) {
|
|
|
|
|
return $validCheck;
|
|
|
|
|
}
|
|
|
|
|
$permCheck = $this->checkPermissions( $user, $reason );
|
|
|
|
|
if ( !$permCheck->isOK() ) {
|
|
|
|
|
return $permCheck;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-02 18:02:54 +00:00
|
|
|
$this->dbw->startAtomic( __METHOD__ );
|
|
|
|
|
|
2015-12-30 04:53:34 +00:00
|
|
|
$this->dbw->update(
|
|
|
|
|
'revision',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'rev_page' => $this->dest->getArticleID() ],
|
|
|
|
|
[ 'rev_page' => $this->source->getArticleID(), $this->timeWhere ],
|
2015-12-30 04:53:34 +00:00
|
|
|
__METHOD__
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Check if this did anything
|
|
|
|
|
$this->revisionsMerged = $this->dbw->affectedRows();
|
|
|
|
|
if ( $this->revisionsMerged < 1 ) {
|
2018-07-02 18:02:54 +00:00
|
|
|
$this->dbw->endAtomic( __METHOD__ );
|
2015-12-30 04:53:34 +00:00
|
|
|
$status->fatal( 'mergehistory-fail-no-change' );
|
2018-07-02 18:02:54 +00:00
|
|
|
|
2015-12-30 04:53:34 +00:00
|
|
|
return $status;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-10 15:24:24 +00:00
|
|
|
// Update denormalized revactor_page too
|
|
|
|
|
$this->dbw->update(
|
|
|
|
|
'revision_actor_temp',
|
|
|
|
|
[ 'revactor_page' => $this->dest->getArticleID() ],
|
|
|
|
|
[
|
|
|
|
|
'revactor_page' => $this->source->getArticleID(),
|
|
|
|
|
// Slightly hacky, but should work given the values assigned in this class
|
|
|
|
|
str_replace( 'rev_timestamp', 'revactor_timestamp', $this->timeWhere )
|
|
|
|
|
],
|
|
|
|
|
__METHOD__
|
|
|
|
|
);
|
|
|
|
|
|
2015-12-30 04:53:34 +00:00
|
|
|
// Make the source page a redirect if no revisions are left
|
2018-07-02 18:02:54 +00:00
|
|
|
$haveRevisions = $this->dbw->lockForUpdate(
|
2015-12-30 04:53:34 +00:00
|
|
|
'revision',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'rev_page' => $this->source->getArticleID() ],
|
2018-07-02 18:02:54 +00:00
|
|
|
__METHOD__
|
2015-12-30 04:53:34 +00:00
|
|
|
);
|
2020-03-29 21:16:50 +00:00
|
|
|
|
2015-12-30 04:53:34 +00:00
|
|
|
if ( !$haveRevisions ) {
|
|
|
|
|
if ( $reason ) {
|
|
|
|
|
$reason = wfMessage(
|
|
|
|
|
'mergehistory-comment',
|
|
|
|
|
$this->source->getPrefixedText(),
|
|
|
|
|
$this->dest->getPrefixedText(),
|
|
|
|
|
$reason
|
|
|
|
|
)->inContentLanguage()->text();
|
|
|
|
|
} else {
|
|
|
|
|
$reason = wfMessage(
|
|
|
|
|
'mergehistory-autocomment',
|
|
|
|
|
$this->source->getPrefixedText(),
|
|
|
|
|
$this->dest->getPrefixedText()
|
|
|
|
|
)->inContentLanguage()->text();
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-28 22:54:18 +00:00
|
|
|
$redirectContent = $this->contentHandlerFactory
|
2020-01-18 20:25:04 +00:00
|
|
|
->getContentHandler( $this->source->getContentModel() )
|
|
|
|
|
->makeRedirectContent(
|
|
|
|
|
$this->dest,
|
|
|
|
|
wfMessage( 'mergehistory-redirect-text' )->inContentLanguage()->plain()
|
|
|
|
|
);
|
2015-12-30 04:53:34 +00:00
|
|
|
|
|
|
|
|
if ( $redirectContent ) {
|
2020-03-29 21:16:50 +00:00
|
|
|
$redirectComment = CommentStoreComment::newUnsavedComment( $reason );
|
|
|
|
|
|
|
|
|
|
$redirectRevRecord = new MutableRevisionRecord( $this->source );
|
|
|
|
|
$redirectRevRecord->setContent( SlotRecord::MAIN, $redirectContent );
|
|
|
|
|
$redirectRevRecord->setPageId( $this->source->getArticleID() );
|
|
|
|
|
$redirectRevRecord->setComment( $redirectComment );
|
|
|
|
|
$redirectRevRecord->setUser( $user );
|
|
|
|
|
$redirectRevRecord->setTimestamp( wfTimestampNow() );
|
|
|
|
|
|
2020-04-28 22:54:18 +00:00
|
|
|
$insertedRevRecord = $this->revisionStore->insertRevisionOn(
|
2020-03-29 21:16:50 +00:00
|
|
|
$redirectRevRecord,
|
|
|
|
|
$this->dbw
|
|
|
|
|
);
|
|
|
|
|
|
2015-12-30 04:53:34 +00:00
|
|
|
$redirectPage = WikiPage::factory( $this->source );
|
2020-03-29 21:16:50 +00:00
|
|
|
$redirectPage->updateRevisionOn( $this->dbw, $insertedRevRecord );
|
2015-12-30 04:53:34 +00:00
|
|
|
|
|
|
|
|
// Now, we record the link from the redirect to the new title.
|
|
|
|
|
// It should have no other outgoing links...
|
|
|
|
|
$this->dbw->delete(
|
|
|
|
|
'pagelinks',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'pl_from' => $this->dest->getArticleID() ],
|
2015-12-30 04:53:34 +00:00
|
|
|
__METHOD__
|
|
|
|
|
);
|
|
|
|
|
$this->dbw->insert( 'pagelinks',
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2015-12-30 04:53:34 +00:00
|
|
|
'pl_from' => $this->dest->getArticleID(),
|
|
|
|
|
'pl_from_namespace' => $this->dest->getNamespace(),
|
|
|
|
|
'pl_namespace' => $this->dest->getNamespace(),
|
2016-02-17 09:09:32 +00:00
|
|
|
'pl_title' => $this->dest->getDBkey() ],
|
2015-12-30 04:53:34 +00:00
|
|
|
__METHOD__
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
// Warning if we couldn't create the redirect
|
|
|
|
|
$status->warning( 'mergehistory-warning-redirect-not-created' );
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$this->source->invalidateCache(); // update histories
|
|
|
|
|
}
|
|
|
|
|
$this->dest->invalidateCache(); // update histories
|
|
|
|
|
|
2016-04-11 10:41:39 +00:00
|
|
|
// Duplicate watchers of the old article to the new article on history merge
|
2020-04-28 22:54:18 +00:00
|
|
|
$this->watchedItemStore->duplicateAllAssociatedEntries( $this->source, $this->dest );
|
2016-04-11 10:41:39 +00:00
|
|
|
|
2015-12-30 04:53:34 +00:00
|
|
|
// Update our logs
|
|
|
|
|
$logEntry = new ManualLogEntry( 'merge', 'merge' );
|
|
|
|
|
$logEntry->setPerformer( $user );
|
|
|
|
|
$logEntry->setComment( $reason );
|
|
|
|
|
$logEntry->setTarget( $this->source );
|
2016-02-17 09:09:32 +00:00
|
|
|
$logEntry->setParameters( [
|
2015-12-30 04:53:34 +00:00
|
|
|
'4::dest' => $this->dest->getPrefixedText(),
|
|
|
|
|
'5::mergepoint' => $this->timestampLimit->getTimestamp( TS_MW )
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2015-12-30 04:53:34 +00:00
|
|
|
$logId = $logEntry->insert();
|
|
|
|
|
$logEntry->publish( $logId );
|
|
|
|
|
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
Hooks::runner()->onArticleMergeComplete( $this->source, $this->dest );
|
2015-12-30 04:53:34 +00:00
|
|
|
|
2018-07-02 18:02:54 +00:00
|
|
|
$this->dbw->endAtomic( __METHOD__ );
|
|
|
|
|
|
2015-12-30 04:53:34 +00:00
|
|
|
return $status;
|
|
|
|
|
}
|
|
|
|
|
}
|