*
* @file
*/
+use Wikimedia\Timestamp\TimestampException;
/**
* Handles the backend logic of merging the histories of two
*/
class MergeHistory {
- /** @const int Maximum number of revisions that can be merged at once (avoid too much slave lag) */
+ /** @const int Maximum number of revisions that can be merged at once */
const REVISION_LIMIT = 5000;
/** @var Title Page from which history will be merged */
/** @var Title Page to which history will be merged */
protected $dest;
- /** @var DatabaseBase Database that we are using */
+ /** @var IDatabase Database that we are using */
protected $dbw;
/** @var MWTimestamp Maximum timestamp that we can use (oldest timestamp of dest) */
/** @var string SQL WHERE condition that selects source revisions to insert into destination */
protected $timeWhere;
- /** @var MWTimestamp|boolean Timestamp upto which history from the source will be merged */
+ /** @var MWTimestamp|bool Timestamp upto which history from the source will be merged */
protected $timestampLimit;
/** @var integer Number of revisions merged (for Special:MergeHistory success message) */
* MergeHistory constructor.
* @param Title $source Page from which history will be merged
* @param Title $dest Page to which history will be merged
- * @param string|boolean $timestamp Timestamp up to which history from the source will be merged
+ * @param string|bool $timestamp Timestamp up to which history from the source will be merged
*/
public function __construct( Title $source, Title $dest, $timestamp = false ) {
// Save the parameters
$firstDestTimestamp = $this->dbw->selectField(
'revision',
'MIN(rev_timestamp)',
- array( 'rev_page' => $this->dest->getArticleID() ),
+ [ 'rev_page' => $this->dest->getArticleID() ],
__METHOD__
);
$this->maxTimestamp = new MWTimestamp( $firstDestTimestamp );
$lastWorkingTimestamp = $this->dbw->selectField(
'revision',
'MAX(rev_timestamp)',
- array(
- 'rev_timestamp <= ' . $this->dbw->timestamp( $mwTimestamp ),
+ [
+ 'rev_timestamp <= ' .
+ $this->dbw->addQuotes( $this->dbw->timestamp( $mwTimestamp ) ),
'rev_page' => $this->source->getArticleID()
- ),
+ ],
__METHOD__
);
$mwLastWorkingTimestamp = new MWTimestamp( $lastWorkingTimestamp );
// Get the latest timestamp of the source
$lastSourceTimestamp = $this->dbw->selectField(
- array( 'page', 'revision' ),
+ [ 'page', 'revision' ],
'rev_timestamp',
- array( 'page_id' => $this->source->getArticleID(),
+ [ 'page_id' => $this->source->getArticleID(),
'page_latest = rev_id'
- ),
+ ],
__METHOD__
);
$lasttimestamp = new MWTimestamp( $lastSourceTimestamp );
$this->timestampLimit = $lasttimestamp;
}
- $this->timeWhere = "rev_timestamp <= {$this->dbw->timestamp( $timeInsert )}";
+ $this->timeWhere = "rev_timestamp <= " .
+ $this->dbw->addQuotes( $this->dbw->timestamp( $timeInsert ) );
} catch ( TimestampException $ex ) {
// The timestamp we got is screwed up and merge cannot continue
// This should be detected by $this->isValidMerge()
*/
public function getRevisionCount() {
$count = $this->dbw->selectRowCount( 'revision', '1',
- array( 'rev_page' => $this->source->getArticleID(), $this->timeWhere ),
+ [ 'rev_page' => $this->source->getArticleID(), $this->timeWhere ],
__METHOD__,
- array( 'LIMIT' => self::REVISION_LIMIT + 1 )
+ [ 'LIMIT' => self::REVISION_LIMIT + 1 ]
);
return $count;
// Convert into a Status object
if ( $errors ) {
foreach ( $errors as $error ) {
- call_user_func_array( array( $status, 'fatal' ), $error );
+ call_user_func_array( [ $status, 'fatal' ], $error );
}
}
$this->dbw->update(
'revision',
- array( 'rev_page' => $this->dest->getArticleID() ),
- array( 'rev_page' => $this->source->getArticleID(), $this->timeWhere ),
+ [ 'rev_page' => $this->dest->getArticleID() ],
+ [ 'rev_page' => $this->source->getArticleID(), $this->timeWhere ],
__METHOD__
);
$haveRevisions = $this->dbw->selectField(
'revision',
'rev_timestamp',
- array( 'rev_page' => $this->source->getArticleID() ),
+ [ 'rev_page' => $this->source->getArticleID() ],
__METHOD__,
- array( 'FOR UPDATE' )
+ [ 'FOR UPDATE' ]
);
if ( !$haveRevisions ) {
if ( $reason ) {
if ( $redirectContent ) {
$redirectPage = WikiPage::factory( $this->source );
- $redirectRevision = new Revision( array(
+ $redirectRevision = new Revision( [
'title' => $this->source,
'page' => $this->source->getArticleID(),
'comment' => $reason,
- 'content' => $redirectContent ) );
+ 'content' => $redirectContent ] );
$redirectRevision->insertOn( $this->dbw );
$redirectPage->updateRevisionOn( $this->dbw, $redirectRevision );
// It should have no other outgoing links...
$this->dbw->delete(
'pagelinks',
- array( 'pl_from' => $this->dest->getArticleID() ),
+ [ 'pl_from' => $this->dest->getArticleID() ],
__METHOD__
);
$this->dbw->insert( 'pagelinks',
- array(
+ [
'pl_from' => $this->dest->getArticleID(),
'pl_from_namespace' => $this->dest->getNamespace(),
'pl_namespace' => $this->dest->getNamespace(),
- 'pl_title' => $this->dest->getDBkey() ),
+ 'pl_title' => $this->dest->getDBkey() ],
__METHOD__
);
} else {
$logEntry->setPerformer( $user );
$logEntry->setComment( $reason );
$logEntry->setTarget( $this->source );
- $logEntry->setParameters( array(
+ $logEntry->setParameters( [
'4::dest' => $this->dest->getPrefixedText(),
'5::mergepoint' => $this->timestampLimit->getTimestamp( TS_MW )
- ) );
+ ] );
$logId = $logEntry->insert();
$logEntry->publish( $logId );
- Hooks::run( 'ArticleMergeComplete', array( $this->source, $this->dest ) );
+ Hooks::run( 'ArticleMergeComplete', [ $this->source, $this->dest ] );
return $status;
}