r114159 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114158‎ | r114159 | r114160 >
Date:17:49, 19 March 2012
Author:daniel
Status:deferred
Tags:
Comment:
messing with wfMerge
Modified paths:
  • /branches/Wikidata/phase3/includes/ContentHandler.php (modified) (history)
  • /branches/Wikidata/phase3/includes/EditPage.php (modified) (history)

Diff [purge]

Index: branches/Wikidata/phase3/includes/EditPage.php
@@ -1312,7 +1312,7 @@
13131313 $text = $this->textbox1; // do not try to merge here!
13141314 } elseif ( $this->isConflict ) {
13151315 # Attempt merge
1316 - if ( $this->mergeChangesInto( $text ) ) { #FIXME: use ContentHandler
 1316+ if ( $this->mergeChangesInto( $text ) ) { #FIXME: passe/receive Content object
13171317 // Successful merge! Maybe we should tell the user the good news?
13181318 $this->isConflict = false;
13191319 wfDebug( __METHOD__ . ": Suppressing edit conflict, successful merge.\n" );
@@ -1515,7 +1515,7 @@
15161516 wfProfileOut( __METHOD__ );
15171517 return false;
15181518 }
1519 - $baseText = $baseRevision->getText();
 1519+ $baseContent = $baseRevision->getContent();
15201520
15211521 // The current state, we want to merge updates into it
15221522 $currentRevision = Revision::loadFromTitle( $db, $this->mTitle );
@@ -1523,11 +1523,14 @@
15241524 wfProfileOut( __METHOD__ );
15251525 return false;
15261526 }
1527 - $currentText = $currentRevision->getText();
 1527+ $currentContent = $currentRevision->getContent();
15281528
1529 - $result = '';
1530 - if ( wfMerge( $baseText, $editText, $currentText, $result ) ) {
1531 - $editText = $result;
 1529+ $handler = ContentHandler::getForModelName( $baseContent->getModelName() );
 1530+ $editContent = $handler->unserialize( $editText ); #FIXME: supply serialization fomrat from edit form!
 1531+
 1532+ $result = $handler->merge3( $baseContent, $editContent, $currentContent );
 1533+ if ( $result ) {
 1534+ $editText = ContentHandler::getContentText($result); #FIXME: supply serialization fomrat from edit form!
15321535 wfProfileOut( __METHOD__ );
15331536 return true;
15341537 } else {
Index: branches/Wikidata/phase3/includes/ContentHandler.php
@@ -201,8 +201,23 @@
202202 return $de;
203203 }
204204
205 - #XXX: is the native model for wikitext a string or the parser output? parse early or parse late?
 205+ /**
 206+ * attempts to merge differences between three versions.
 207+ * Returns a new Content object for a clean merge and false for failure or a conflict.
 208+ *
 209+ * This default implementation always returns false.
 210+ *
 211+ * @param $oldContent String
 212+ * @param $myContent String
 213+ * @param $yourContent String
 214+ * @return Content|Bool
 215+ */
 216+ public function merge3( Content $oldContent, Content $myContent, Content $yourContent ) {
 217+ return false;
 218+ }
206219
 220+ #TODO: cover patch/undo just like merge3.
 221+
207222 #TODO: how to handle extra message for JS/CSS previews??
208223 #TODO: Article::showCssOrJsPage ---> specialized classes!
209224
@@ -221,6 +236,34 @@
222237 return $content->getRawData();
223238 }
224239
 240+ /**
 241+ * attempts to merge differences between three versions.
 242+ * Returns a new Content object for a clean merge and false for failure or a conflict.
 243+ *
 244+ * This text-based implementation uses wfMerge().
 245+ *
 246+ * @param $oldContent String
 247+ * @param $myContent String
 248+ * @param $yourContent String
 249+ * @return Content|Bool
 250+ */
 251+ public function merge3( Content $oldContent, Content $myContent, Content $yourContent ) {
 252+ $format = $this->getDefaultFormat();
 253+
 254+ $old = $this->serialize( $oldContent, $format );
 255+ $mine = $this->serialize( $myContent, $format );
 256+ $yours = $this->serialize( $yourContent, $format );
 257+
 258+ $ok = wfMerge( $old, $mine, $yours, $result );
 259+
 260+ if ( !$ok ) return false;
 261+ if ( !$result ) return $this->emptyContent();
 262+
 263+ $mergedContent = $this->unserialize( $result, $format );
 264+ return $mergedContent;
 265+ }
 266+
 267+
225268 }
226269 class WikitextContentHandler extends TextContentHandler {
227270

Status & tagging log