From: Mr. E23 Date: Sun, 14 Mar 2004 22:28:52 +0000 (+0000) Subject: Fixed problems with section editing and merging X-Git-Tag: 1.3.0beta1~790 X-Git-Url: https://git.cyclocoop.org/admin/?a=commitdiff_plain;h=46071b3a161f31e78605c4deaa378dced8733716;p=lhc%2Fweb%2Fwiklou.git Fixed problems with section editing and merging --- diff --git a/includes/Article.php b/includes/Article.php index 9d49d75b20..ffce076944 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -442,19 +442,12 @@ class Article { $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; @@ -466,6 +459,16 @@ class Article { $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 ) ) { @@ -1014,8 +1017,7 @@ class Article { $wgOut->setPagetitle( wfMsg( "actioncomplete" ) ); $wgOut->setRobotpolicy( "noindex,nofollow" ); $wgOut->addHTML( "

" . $newcomment . "

\n
\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 ); } diff --git a/includes/EditPage.php b/includes/EditPage.php index d22df2d5aa..46d101d631 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -151,16 +151,19 @@ class EditPage { $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 ) ) { @@ -170,17 +173,18 @@ class EditPage { # 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; @@ -452,7 +456,7 @@ htmlspecialchars( $wgLang->recodeForEdit( $this->textbox1 ) ) . } } - /* 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); @@ -464,8 +468,8 @@ htmlspecialchars( $wgLang->recodeForEdit( $this->textbox1 ) ) . $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;