Index: branches/Wikidata/phase3/includes/EditPage.php |
— | — | @@ -1312,7 +1312,7 @@ |
1313 | 1313 | $text = $this->textbox1; // do not try to merge here! |
1314 | 1314 | } elseif ( $this->isConflict ) { |
1315 | 1315 | # Attempt merge |
1316 | | - if ( $this->mergeChangesInto( $text ) ) { #FIXME: use ContentHandler |
| 1316 | + if ( $this->mergeChangesInto( $text ) ) { #FIXME: passe/receive Content object |
1317 | 1317 | // Successful merge! Maybe we should tell the user the good news? |
1318 | 1318 | $this->isConflict = false; |
1319 | 1319 | wfDebug( __METHOD__ . ": Suppressing edit conflict, successful merge.\n" ); |
— | — | @@ -1515,7 +1515,7 @@ |
1516 | 1516 | wfProfileOut( __METHOD__ ); |
1517 | 1517 | return false; |
1518 | 1518 | } |
1519 | | - $baseText = $baseRevision->getText(); |
| 1519 | + $baseContent = $baseRevision->getContent(); |
1520 | 1520 | |
1521 | 1521 | // The current state, we want to merge updates into it |
1522 | 1522 | $currentRevision = Revision::loadFromTitle( $db, $this->mTitle ); |
— | — | @@ -1523,11 +1523,14 @@ |
1524 | 1524 | wfProfileOut( __METHOD__ ); |
1525 | 1525 | return false; |
1526 | 1526 | } |
1527 | | - $currentText = $currentRevision->getText(); |
| 1527 | + $currentContent = $currentRevision->getContent(); |
1528 | 1528 | |
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! |
1532 | 1535 | wfProfileOut( __METHOD__ ); |
1533 | 1536 | return true; |
1534 | 1537 | } else { |
Index: branches/Wikidata/phase3/includes/ContentHandler.php |
— | — | @@ -201,8 +201,23 @@ |
202 | 202 | return $de; |
203 | 203 | } |
204 | 204 | |
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 | + } |
206 | 219 | |
| 220 | + #TODO: cover patch/undo just like merge3. |
| 221 | + |
207 | 222 | #TODO: how to handle extra message for JS/CSS previews?? |
208 | 223 | #TODO: Article::showCssOrJsPage ---> specialized classes! |
209 | 224 | |
— | — | @@ -221,6 +236,34 @@ |
222 | 237 | return $content->getRawData(); |
223 | 238 | } |
224 | 239 | |
| 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 | + |
225 | 268 | } |
226 | 269 | class WikitextContentHandler extends TextContentHandler { |
227 | 270 | |