Index: /MediaWiki/trunk/FCKeditor.body.php
===================================================================
--- /MediaWiki/trunk/FCKeditor.body.php	(revision 1928)
+++ /MediaWiki/trunk/FCKeditor.body.php	(revision 1929)
@@ -75,4 +75,53 @@
 		return true;
 	}
+	
+	public function onEditPageShowEditFormFields($pageEditor, $wgOut)
+	{
+		global $wgUser, $wgFCKEditorIsCompatible, $wgTitle, $wgVersion;
+
+		/*
+		If FCKeditor extension is enabled, BUT it shouldn't appear (because it's disabled by user, we have incompatible browser etc.)
+		We must do this trick to show the original text as WikiText instead of HTML when conflict occurs
+		*/
+		if ( (!$wgUser->getOption( 'showtoolbar' ) || $wgUser->getOption( 'riched_disable' ) || !$wgFCKEditorIsCompatible) ||
+				in_array($wgTitle->getNamespace(), $this->getExcludedNamespaces()) ||
+				false !== strpos($pageEditor->textbox1, "__NORICHEDITOR__")
+			) {
+			if ($pageEditor->isConflict) {
+				$pageEditor->textbox1 = $pageEditor->getWikiContent();
+			}
+		}
+		/*
+		If FCKeditor extension is enabled, and it should appear
+		We must do this trick to show HTML instead of the original text when conflict occurs
+		This hack is only needed for MW 1.11 and below
+		*/
+		else if (version_compare("1.12", $wgVersion, ">")) {
+			if ($pageEditor->isConflict) {
+			$options = new FCKeditorParserOptions();
+			$options->setTidy(true);
+			$parser = new FCKeditorParser();
+			$parser->setOutputType(OT_HTML);
+			$pa = $parser->parse($pageEditor->textbox1, $pageEditor->mTitle, $options);
+			$pageEditor->textbox1 = $pa->mText;
+			}
+		}
+		
+		return true;
+	}
+
+	public function onEditPageBeforeConflictDiff($pageEditor, $wgOut)
+	{
+		global $fckPageEditor, $wgRequest;
+
+		/*
+		Show WikiText instead of HTML when there is a conflict
+		http://dev.fckeditor.net/ticket/1385
+		*/
+		$pageEditor->textbox2 = $wgRequest->getVal( 'wpTextbox1' );
+		$pageEditor->textbox1 = $pageEditor->getWikiContent();
+				
+		return true;
+	}
 
 	public function registerHooks() {
@@ -83,4 +132,5 @@
 		$wgHooks['ParserAfterTidy'][]                   = array($this, 'onParserAfterTidy');
 		$wgHooks['EditPage::showEditForm:initial'][]    = array($this, 'onEditPageShowEditFormInitial');
+		$wgHooks['EditPage::showEditForm:fields'][]		= array($this, 'onEditPageShowEditFormFields');
 		$wgHooks['EditPageBeforePreviewText'][]         = array($this, 'onEditPageBeforePreviewText');
 		$wgHooks['EditPagePreviewTextEnd'][]            = array($this, 'onEditPagePreviewTextEnd');
@@ -88,6 +138,11 @@
 		$wgHooks['LanguageGetMagic'][]                  = array($this, "onLanguageGetMagic");
 		$wgHooks['ParserBeforeInternalParse'][]         = array($this, "onParserBeforeInternalParse");
+		$wgHooks['EditPageBeforeConflictDiff'][]		= array($this, 'onEditPageBeforeConflictDiff');
 
 		if ($this->debug) {
+			/*
+			This is just an array of all available hooks, useful for debugging and learning
+			Add here all new hooks
+			*/
 			$opcje =  array('ArticleSave',
 			'ArticleInsertComplete', 'ArticleSaveComplete', 'TitleMoveComplete', 'ArticleProtect', 'ArticleProtectComplete', 'ArticleDelete', 'ArticleDeleteComplete', 'AlternateEdit', 'ArticleFromTitle', 'ArticleAfterFetchContent',
@@ -209,4 +264,5 @@
 		global $wgFCKEditorExtDir, $wgFCKEditorDir, $wgFCKEditorHeight, $wgUser;
 		global $wgStylePath, $wgStyleVersion, $wgDefaultSkin, $wgExtensionFunctions;
+		global $wgFCKWikiTextBeforeParse;
 
 		if (!$wgUser->getOption( 'showtoolbar' ) || $wgUser->getOption( 'riched_disable' ) || !$wgFCKEditorIsCompatible) {
@@ -226,4 +282,5 @@
 		$parser = new FCKeditorParser();
 		$parser->setOutputType(OT_HTML);
+		$wgFCKWikiTextBeforeParse = $form->textbox1;
 		$form->textbox1 = $parser->parse($form->textbox1, $wgTitle, $options)->getText();
 
@@ -315,6 +372,10 @@
 }
 addOnloadHook( onLoadFCKeditor ) ;
+</script>
+HEREDOC;
 
 /*
+$script .= <<<HEREDOC
+<script type="text/javascript">
 function showSource() {
 	var wp = document.getElementById("wpDiff");
@@ -346,7 +407,7 @@
 
 addOnloadHook(showSource);
-*/
 </script>
 HEREDOC;
+*/
 
 		$wgOut->addScript($script);
Index: /MediaWiki/trunk/FCKeditorEditPage.body.php
===================================================================
--- /MediaWiki/trunk/FCKeditorEditPage.body.php	(revision 1928)
+++ /MediaWiki/trunk/FCKeditorEditPage.body.php	(revision 1929)
@@ -29,5 +29,5 @@
 		}
 	}
-	
+
 	function getPreviewText() {
 		if (!$this->isCssJsSubpage) {
@@ -41,3 +41,38 @@
 		return $result;
 	}
+
+	function getContent( $def_text = '' ) {
+		$t = parent::getContent( $def_text );
+		if(!$this->isConflict) {
+			return $t;
+		}
+		$options = new FCKeditorParserOptions();
+		$options->setTidy(true);
+		$parser = new FCKeditorParser();
+		$parser->setOutputType(OT_HTML);
+		$pa = $parser->parse($t, $this->mTitle, $options);
+		return $pa->mText;
+
+	}
+
+	function getWikiContent(){
+		return $this->mArticle->getContent();
+	}
+
+	/**
+	 * This is a hack to fix
+	 * http://dev.fckeditor.net/ticket/1174
+	 * If RTE is enabled, diff must be performed on WikiText, not on HTML
+	 */
+	function showDiff() {
+		global $wgFCKWikiTextBeforeParse;
+		if (isset($wgFCKWikiTextBeforeParse)) {
+			$_textbox1 = $this->textbox1;
+			$this->textbox1 = $wgFCKWikiTextBeforeParse;
+		}
+			$result = parent::showDiff();
+		if (isset($wgFCKWikiTextBeforeParse)) {
+			$this->textbox1 = $_textbox1;
+		}
+	}
 }
