$this->showArticle( $text, wfMsg( "newarticle" ) );
}
- function updateArticle( $text, $summary, $minor, $watchthis, $section = "", $forceBot = false )
- {
- global $wgOut, $wgUser, $wgLinkCache;
- global $wgDBtransactions, $wgMwRedir;
- global $wgUseSquid, $wgInternalServer;
- $fname = "Article::updateArticle";
+ /* Side effects: loads last edit */
+ function getTextOfLastEditWithSectionReplacedOrAdded($section, $text, $summary = ""){
$this->loadLastEdit();
-
- // insert updated section into old text if we have only edited part
- // of the article
- if ($section != "") {
- $oldtext=$this->getContent();
+ $oldtext = $this->getContent();
+ if ($section != "") {
if($section=="new") {
if($summary) $subject="== {$summary} ==\n\n";
$text=$oldtext."\n\n".$subject.$text;
$text=join("",$secs);
}
}
+ return $text;
+ }
+
+ function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false )
+ {
+ global $wgOut, $wgUser, $wgLinkCache;
+ global $wgDBtransactions, $wgMwRedir;
+ global $wgUseSquid, $wgInternalServer;
+ $fname = "Article::updateArticle";
+
if ( $this->mMinorEdit ) { $me1 = 1; } else { $me1 = 0; }
if ( $minor && $wgUser->getID() ) { $me2 = 1; } else { $me2 = 0; }
if ( preg_match( "/^((" . $wgMwRedir->getBaseRegex() . ")[^\\n]+)/i", $text, $m ) ) {
$wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
$wgOut->setRobotpolicy( "noindex,nofollow" );
$wgOut->addHTML( "<h2>" . $newcomment . "</h2>\n<hr>\n" );
- $this->updateArticle( Article::getRevisionText( $s ), $newcomment, 1, $this->mTitle->userIsWatching(), "", $bot );
-
+ $this->updateArticle( Article::getRevisionText( $s ), $newcomment, 1, $this->mTitle->userIsWatching(), $bot );
Article::onArticleEdit( $this->mTitle );
$wgOut->returnToMain( false );
}
$this->mArticle->insertNewArticle( $this->textbox1, $this->summary, $this->minoredit, $this->watchthis );
return;
}
+
# Article exists. Check for edit conflict.
- # Don't check for conflict when appending a comment - this should always work
$this->mArticle->clear(); # Force reload of dates, etc.
- if( ( $this->section != "new" ) &&
- ( $this->mArticle->getTimestamp() != $this->edittime ) ) {
+
+ if( ( $this->section != "new" ) &&
+ ($this->mArticle->getTimestamp() != $this->edittime ) ) {
$isConflict = true;
}
$userid = $wgUser->getID();
+ $text = $this->mArticle->getTextOfLastEditWithSectionReplacedOrAdded(
+ $this->section, $this->textbox1, $this->summary);
# Suppress edit conflict with self
if ( ( 0 != $userid ) && ( $this->mArticle->getUser() == $userid ) ) {
# FIXME: This is confusing. In theory we should attempt to merge, finding
# the equivalent section if it's unchanged and avoid the conflict.
if($isConflict) {
- if( $this->merge() ){
+ if( $this->mergeChangesInto( $text ) ){
// Successful merge! Maybe we should tell the user the good news?
$isConflict = false;
} else {
$this->section = "";
+ $this->textbox1 = $text;
}
}
}
if ( ! $isConflict ) {
# All's well: update the article here
- if($this->mArticle->updateArticle( $this->textbox1, $this->summary, $this->minoredit, $this->watchthis, $this->section ))
+ if($this->mArticle->updateArticle( $text, $this->summary, $this->minoredit, $this->watchthis ))
return;
else
$isConflict = true;
}
}
- /* private */ function merge(){
+ /* private */ function mergeChangesInto( &$text ){
$oldDate = $this->edittime;
$res = wfQuery("SELECT cur_text FROM cur WHERE cur_id=" .
$this->mTitle->getArticleID() . " FOR UPDATE", DB_WRITE);
$res = wfQuery("SELECT old_text FROM old WHERE old_namespace = $ns AND ".
"old_title = '{$title}' AND old_timestamp = '{$oldDate}'", DB_WRITE);
$obj = wfFetchObject($res);
- if(wfMerge($obj->old_text, $this->textbox1, $yourtext, $result)){
- $this->textbox1 = $result;
+ if(wfMerge($obj->old_text, $text, $yourtext, $result)){
+ $text = $result;
return true;
} else {
return false;