https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114159
Revision: 114159
Author: daniel
Date: 2012-03-19 17:49:00 +0000 (Mon, 19 Mar 2012)
Log Message:
-----------
messing with wfMerge
Modified Paths:
--------------
branches/Wikidata/phase3/includes/ContentHandler.php
branches/Wikidata/phase3/includes/EditPage.php
Modified: branches/Wikidata/phase3/includes/ContentHandler.php
===================================================================
--- branches/Wikidata/phase3/includes/ContentHandler.php 2012-03-19
17:27:46 UTC (rev 114158)
+++ branches/Wikidata/phase3/includes/ContentHandler.php 2012-03-19
17:49:00 UTC (rev 114159)
@@ -201,8 +201,23 @@
return $de;
}
- #XXX: is the native model for wikitext a string or the parser output?
parse early or parse late?
+ /**
+ * attempts to merge differences between three versions.
+ * Returns a new Content object for a clean merge and false for failure or
a conflict.
+ *
+ * This default implementation always returns false.
+ *
+ * @param $oldContent String
+ * @param $myContent String
+ * @param $yourContent String
+ * @return Content|Bool
+ */
+ public function merge3( Content $oldContent, Content $myContent, Content
$yourContent ) {
+ return false;
+ }
+ #TODO: cover patch/undo just like merge3.
+
#TODO: how to handle extra message for JS/CSS previews??
#TODO: Article::showCssOrJsPage ---> specialized classes!
@@ -221,6 +236,34 @@
return $content->getRawData();
}
+ /**
+ * attempts to merge differences between three versions.
+ * Returns a new Content object for a clean merge and false for failure or
a conflict.
+ *
+ * This text-based implementation uses wfMerge().
+ *
+ * @param $oldContent String
+ * @param $myContent String
+ * @param $yourContent String
+ * @return Content|Bool
+ */
+ public function merge3( Content $oldContent, Content $myContent, Content
$yourContent ) {
+ $format = $this->getDefaultFormat();
+
+ $old = $this->serialize( $oldContent, $format );
+ $mine = $this->serialize( $myContent, $format );
+ $yours = $this->serialize( $yourContent, $format );
+
+ $ok = wfMerge( $old, $mine, $yours, $result );
+
+ if ( !$ok ) return false;
+ if ( !$result ) return $this->emptyContent();
+
+ $mergedContent = $this->unserialize( $result, $format );
+ return $mergedContent;
+ }
+
+
}
class WikitextContentHandler extends TextContentHandler {
Modified: branches/Wikidata/phase3/includes/EditPage.php
===================================================================
--- branches/Wikidata/phase3/includes/EditPage.php 2012-03-19 17:27:46 UTC
(rev 114158)
+++ branches/Wikidata/phase3/includes/EditPage.php 2012-03-19 17:49:00 UTC
(rev 114159)
@@ -1312,7 +1312,7 @@
$text = $this->textbox1; // do not try to merge
here!
} elseif ( $this->isConflict ) {
# Attempt merge
- if ( $this->mergeChangesInto( $text ) ) {
#FIXME: use ContentHandler
+ if ( $this->mergeChangesInto( $text ) ) {
#FIXME: passe/receive Content object
// Successful merge! Maybe we should
tell the user the good news?
$this->isConflict = false;
wfDebug( __METHOD__ . ": Suppressing
edit conflict, successful merge.\n" );
@@ -1515,7 +1515,7 @@
wfProfileOut( __METHOD__ );
return false;
}
- $baseText = $baseRevision->getText();
+ $baseContent = $baseRevision->getContent();
// The current state, we want to merge updates into it
$currentRevision = Revision::loadFromTitle( $db, $this->mTitle
);
@@ -1523,11 +1523,14 @@
wfProfileOut( __METHOD__ );
return false;
}
- $currentText = $currentRevision->getText();
+ $currentContent = $currentRevision->getContent();
- $result = '';
- if ( wfMerge( $baseText, $editText, $currentText, $result ) ) {
- $editText = $result;
+ $handler = ContentHandler::getForModelName(
$baseContent->getModelName() );
+ $editContent = $handler->unserialize( $editText ); #FIXME: supply
serialization fomrat from edit form!
+
+ $result = $handler->merge3( $baseContent, $editContent,
$currentContent );
+ if ( $result ) {
+ $editText = ContentHandler::getContentText($result);
#FIXME: supply serialization fomrat from edit form!
wfProfileOut( __METHOD__ );
return true;
} else {
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs