$this->isConflict = true;
$content = $textbox_content; // do not try to merge here!
} elseif ( $this->isConflict ) {
+ $contentObj = $content;
# Attempt merge
- if ( $this->mergeChangesIntoContent( $textbox_content ) ) {
+ if ( $this->mergeChangesInto( $content ) ) {
// Successful merge! Maybe we should tell the user the good news?
$this->isConflict = false;
- $content = $textbox_content;
+ $content = $this->toEditContent( $content );
wfDebug( __METHOD__ . ": Suppressing edit conflict, successful merge.\n" );
} else {
$this->section = '';
- #$this->textbox1 = $text; #redundant, nothing to do here?
+ $this->textbox1 = ContentHandler::getContentText( $contentObj );
wfDebug( __METHOD__ . ": Keeping edit conflict, failed merge.\n" );
}
}
if ( $doEditStatus->isOK() ) {
$result['redirect'] = $content->isRedirect();
- $this->commitWatch();
+ $this->updateWatchlist();
wfProfileOut( __METHOD__ );
return $status;
} else {
}
/**
- * Commit the change of watch status
+ * Register the change of watch status
*/
- protected function commitWatch() {
+ protected function updateWatchlist() {
global $wgUser;
+
if ( $wgUser->isLoggedIn() && $this->watchthis != $wgUser->isWatched( $this->mTitle ) ) {
+ $fname = __METHOD__;
+ $title = $this->mTitle;
+ $watch = $this->watchthis;
+
+ // Do this in its own transaction to reduce contention...
$dbw = wfGetDB( DB_MASTER );
- $dbw->begin( __METHOD__ );
- if ( $this->watchthis ) {
- WatchAction::doWatch( $this->mTitle, $wgUser );
- } else {
- WatchAction::doUnwatch( $this->mTitle, $wgUser );
- }
- $dbw->commit( __METHOD__ );
+ $dbw->onTransactionIdle( function() use ( $dbw, $title, $watch, $wgUser, $fname ) {
+ $dbw->begin( $fname );
+ if ( $watch ) {
+ WatchAction::doWatch( $title, $wgUser );
+ } else {
+ WatchAction::doUnwatch( $title, $wgUser );
+ }
+ $dbw->commit( $fname );
+ } );
}
}
function mergeChangesInto( &$editText ){
ContentHandler::deprecated( __METHOD__, "1.21" );
- $editContent = $this->toEditContent( $editText );
+ wfProfileIn( __METHOD__ );
+
+ $db = wfGetDB( DB_MASTER );
+
+ // This is the revision the editor started from
+ $baseRevision = $this->getBaseRevision();
+ if ( is_null( $baseRevision ) ) {
+ wfProfileOut( __METHOD__ );
+ return false;
+ }
+ $baseText = $baseRevision->getText();
+
+ // The current state, we want to merge updates into it
+ $currentRevision = Revision::loadFromTitle( $db, $this->mTitle );
+ if ( is_null( $currentRevision ) ) {
+ wfProfileOut( __METHOD__ );
+ return false;
+ }
+ $currentText = $currentRevision->getText();
- $ok = $this->mergeChangesIntoContent( $editContent );
+ $result = '';
+ $editText = $this->toEditText( $editText );
- if ( $ok ) {
- $editText = $this->toEditText( $editContent );
+ if ( wfMerge( $baseText, $editText, $currentText, $result ) ) {
+ $editText = $result;
+ wfProfileOut( __METHOD__ );
return true;
+ } else {
+ wfProfileOut( __METHOD__ );
+ return false;
}
- return false;
}
/**
# Messages: usercsspreview, userjspreview, sitecsspreview, sitejspreview
if( $level && $format ) {
$note = "<div id='mw-{$level}{$format}preview'>" . wfMessage( "{$level}{$format}preview" )->text() . "</div>";
- } else {
- $note = wfMessage( 'previewnote' )->text() ;
}
- } else {
- $note = wfMessage( 'previewnote' )->text() ;
}
$rt = $content->getRedirectChain();