return;
}
- $errors = array();
+ $errors = [];
if ( !$this->mTargetObj instanceof Title ) {
$errors[] = $this->msg( 'mergehistory-invalid-source' )->parseAsBlock();
} elseif ( !$this->mTargetObj->exists() ) {
$out->addWikiMsg( 'mergehistory-header' );
$out->addHTML(
- Xml::openElement( 'form', array(
+ Xml::openElement( 'form', [
'method' => 'get',
- 'action' => wfScript() ) ) .
+ 'action' => wfScript() ] ) .
'<fieldset>' .
- Xml::element( 'legend', array(),
+ Xml::element( 'legend', [],
$this->msg( 'mergehistory-box' )->text() ) .
Html::hidden( 'title', $this->getPageTitle()->getPrefixedDBkey() ) .
Html::hidden( 'submitted', '1' ) .
Xml::openElement( 'table' ) .
'<tr>
<td>' . Xml::label( $this->msg( 'mergehistory-from' )->text(), 'target' ) . '</td>
- <td>' . Xml::input( 'target', 30, $this->mTarget, array( 'id' => 'target' ) ) . '</td>
+ <td>' . Xml::input( 'target', 30, $this->mTarget, [ 'id' => 'target' ] ) . '</td>
</tr><tr>
<td>' . Xml::label( $this->msg( 'mergehistory-into' )->text(), 'dest' ) . '</td>
- <td>' . Xml::input( 'dest', 30, $this->mDest, array( 'id' => 'dest' ) ) . '</td>
+ <td>' . Xml::input( 'dest', 30, $this->mDest, [ 'id' => 'dest' ] ) . '</td>
</tr><tr><td>' .
Xml::submitButton( $this->msg( 'mergehistory-go' )->text() ) .
'</td></tr>' .
# List all stored revisions
$revisions = new MergeHistoryPager(
- $this, array(), $this->mTargetObj, $this->mDestObj
+ $this, [], $this->mTargetObj, $this->mDestObj
);
$haveRevisions = $revisions && $revisions->getNumRows() > 0;
$out = $this->getOutput();
$titleObj = $this->getPageTitle();
- $action = $titleObj->getLocalURL( array( 'action' => 'submit' ) );
+ $action = $titleObj->getLocalURL( [ 'action' => 'submit' ] );
# Start the form here
$top = Xml::openElement(
'form',
- array(
+ [
'method' => 'post',
'action' => $action,
'id' => 'merge'
- )
+ ]
);
$out->addHTML( $top );
Xml::openElement( 'fieldset' ) .
$this->msg( 'mergehistory-merge', $this->mTargetObj->getPrefixedText(),
$this->mDestObj->getPrefixedText() )->parse() .
- Xml::openElement( 'table', array( 'id' => 'mw-mergehistory-table' ) ) .
+ Xml::openElement( 'table', [ 'id' => 'mw-mergehistory-table' ] ) .
'<tr>
<td class="mw-label">' .
Xml::label( $this->msg( 'mergehistory-reason' )->text(), 'wpComment' ) .
'</td>
<td class="mw-input">' .
- Xml::input( 'wpComment', 50, $this->mComment, array( 'id' => 'wpComment' ) ) .
+ Xml::input( 'wpComment', 50, $this->mComment, [ 'id' => 'wpComment' ] ) .
'</td>
</tr>
<tr>
<td class="mw-submit">' .
Xml::submitButton(
$this->msg( 'mergehistory-submit' )->text(),
- array( 'name' => 'merge', 'id' => 'mw-merge-submit' )
+ [ 'name' => 'merge', 'id' => 'mw-merge-submit' ]
) .
'</td>
</tr>' .
$pageLink = Linker::linkKnown(
$rev->getTitle(),
htmlspecialchars( $this->getLanguage()->userTimeAndDate( $ts, $user ) ),
- array(),
- array( 'oldid' => $rev->getId() )
+ [],
+ [ 'oldid' => $rev->getId() ]
);
if ( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
$pageLink = '<span class="history-deleted">' . $pageLink . '</span>';
$last = Linker::linkKnown(
$rev->getTitle(),
$this->msg( 'last' )->escaped(),
- array(),
- array(
+ [],
+ [
'diff' => $row->rev_id,
'oldid' => $this->prevId[$row->rev_id]
- )
+ ]
);
}
}
$comment = Linker::revComment( $rev );
- return Html::rawElement( 'li', array(),
+ return Html::rawElement( 'li', [],
$this->msg( 'mergehistory-revisionrow' )
->rawParams( $checkBox, $last, $pageLink, $userLink, $stxt, $comment )->escaped() );
}
if ( $targetTitle->getArticleID() == $destTitle->getArticleID() ) {
return false;
}
- # Verify that this timestamp is valid
- # Must be older than the destination page
- $dbw = wfGetDB( DB_MASTER );
- # Get timestamp into DB format
- $this->mTimestamp = $this->mTimestamp ? $dbw->timestamp( $this->mTimestamp ) : '';
- # Max timestamp should be min of destination page
- $maxtimestamp = $dbw->selectField(
- 'revision',
- 'MIN(rev_timestamp)',
- array( 'rev_page' => $this->mDestID ),
- __METHOD__
- );
- # Destination page must exist with revisions
- if ( !$maxtimestamp ) {
- $this->getOutput()->addWikiMsg( 'mergehistory-fail' );
-
- return false;
- }
- # Get the latest timestamp of the source
- $lasttimestamp = $dbw->selectField(
- array( 'page', 'revision' ),
- 'rev_timestamp',
- array( 'page_id' => $this->mTargetID, 'page_latest = rev_id' ),
- __METHOD__
- );
- # $this->mTimestamp must be older than $maxtimestamp
- if ( $this->mTimestamp >= $maxtimestamp ) {
- $this->getOutput()->addWikiMsg( 'mergehistory-fail' );
-
- return false;
- }
- # Get the timestamp pivot condition
- if ( $this->mTimestamp ) {
- $timewhere = "rev_timestamp <= {$this->mTimestamp}";
- $timestampLimit = wfTimestamp( TS_MW, $this->mTimestamp );
- } else {
- $timewhere = "rev_timestamp <= {$maxtimestamp}";
- $timestampLimit = wfTimestamp( TS_MW, $lasttimestamp );
- }
- # Check that there are not too many revisions to move
- $limit = 5000; // avoid too much slave lag
- $count = $dbw->selectRowCount( 'revision', '1',
- array( 'rev_page' => $this->mTargetID, $timewhere ),
- __METHOD__,
- array( 'LIMIT' => $limit + 1 )
- );
- if ( $count > $limit ) {
- $this->getOutput()->addWikiMsg( 'mergehistory-fail-toobig' );
- return false;
- }
- # Do the moving...
- $dbw->update(
- 'revision',
- array( 'rev_page' => $this->mDestID ),
- array( 'rev_page' => $this->mTargetID, $timewhere ),
- __METHOD__
- );
-
- $count = $dbw->affectedRows();
- # Make the source page a redirect if no revisions are left
- $haveRevisions = $dbw->selectField(
- 'revision',
- 'rev_timestamp',
- array( 'rev_page' => $this->mTargetID ),
- __METHOD__,
- array( 'FOR UPDATE' )
- );
- if ( !$haveRevisions ) {
- if ( $this->mComment ) {
- $comment = $this->msg(
- 'mergehistory-comment',
- $targetTitle->getPrefixedText(),
- $destTitle->getPrefixedText(),
- $this->mComment
- )->inContentLanguage()->text();
- } else {
- $comment = $this->msg(
- 'mergehistory-autocomment',
- $targetTitle->getPrefixedText(),
- $destTitle->getPrefixedText()
- )->inContentLanguage()->text();
- }
-
- $contentHandler = ContentHandler::getForTitle( $targetTitle );
- $redirectContent = $contentHandler->makeRedirectContent( $destTitle );
-
- if ( $redirectContent ) {
- $redirectPage = WikiPage::factory( $targetTitle );
- $redirectRevision = new Revision( array(
- 'title' => $targetTitle,
- 'page' => $this->mTargetID,
- 'comment' => $comment,
- 'content' => $redirectContent ) );
- $redirectRevision->insertOn( $dbw );
- $redirectPage->updateRevisionOn( $dbw, $redirectRevision );
-
- # Now, we record the link from the redirect to the new title.
- # It should have no other outgoing links...
- $dbw->delete( 'pagelinks', array( 'pl_from' => $this->mDestID ), __METHOD__ );
- $dbw->insert( 'pagelinks',
- array(
- 'pl_from' => $this->mDestID,
- 'pl_from_namespace' => $destTitle->getNamespace(),
- 'pl_namespace' => $destTitle->getNamespace(),
- 'pl_title' => $destTitle->getDBkey() ),
- __METHOD__
- );
- } else {
- // would be nice to show a warning if we couldn't create a redirect
- }
- } else {
- $targetTitle->invalidateCache(); // update histories
- }
- $destTitle->invalidateCache(); // update histories
- # Check if this did anything
- if ( !$count ) {
- $this->getOutput()->addWikiMsg( 'mergehistory-fail' );
+ // MergeHistory object
+ $mh = new MergeHistory( $targetTitle, $destTitle, $this->mTimestamp );
+ // Merge!
+ $mergeStatus = $mh->merge( $this->getUser(), $this->mComment );
+ if ( !$mergeStatus->isOK() ) {
+ // Failed merge
+ $this->getOutput()->addWikiMsg( $mergeStatus->getMessage() );
return false;
}
- # Update our logs
- $logEntry = new ManualLogEntry( 'merge', 'merge' );
- $logEntry->setPerformer( $this->getUser() );
- $logEntry->setComment( $this->mComment );
- $logEntry->setTarget( $targetTitle );
- $logEntry->setParameters( array(
- '4::dest' => $destTitle->getPrefixedText(),
- '5::mergepoint' => $timestampLimit
- ) );
- $logId = $logEntry->insert();
- $logEntry->publish( $logId );
$targetLink = Linker::link(
$targetTitle,
null,
- array(),
- array( 'redirect' => 'no' )
+ [],
+ [ 'redirect' => 'no' ]
);
$this->getOutput()->addWikiMsg( $this->msg( 'mergehistory-done' )
->rawParams( $targetLink )
->params( $destTitle->getPrefixedText() )
- ->numParams( $count )
+ ->numParams( $mh->getMergedRevisionCount() )
);
- Hooks::run( 'ArticleMergeComplete', array( $targetTitle, $destTitle ) );
-
return true;
}
$maxtimestamp = $dbr->selectField(
'revision',
'MIN(rev_timestamp)',
- array( 'rev_page' => $dest->getArticleID() ),
+ [ 'rev_page' => $dest->getArticleID() ],
__METHOD__
);
$this->maxTimestamp = $maxtimestamp;
$this->mResult->seek( 0 );
$batch = new LinkBatch();
# Give some pointers to make (last) links
- $this->mForm->prevId = array();
+ $this->mForm->prevId = [];
foreach ( $this->mResult as $row ) {
$batch->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
$batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->user_name ) );
$conds['rev_page'] = $this->articleID;
$conds[] = "rev_timestamp < " . $this->mDb->addQuotes( $this->maxTimestamp );
- return array(
- 'tables' => array( 'revision', 'page', 'user' ),
+ return [
+ 'tables' => [ 'revision', 'page', 'user' ],
'fields' => array_merge( Revision::selectFields(), Revision::selectUserFields() ),
'conds' => $conds,
- 'join_conds' => array(
+ 'join_conds' => [
'page' => Revision::pageJoinCond(),
- 'user' => Revision::userJoinCond() )
- );
+ 'user' => Revision::userJoinCond() ]
+ ];
}
function getIndexField() {