Show
Ignore:
Timestamp:
2008-04-16 09:25:55 (6 months ago)
Author:
wwalc
Message:

Fix for #1385 and #1174 - HTML/WikiText mess on conflict/preview

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • MediaWiki/trunk/FCKeditor.body.php

    r1871 r1929  
    7575                return true; 
    7676        } 
     77         
     78        public function onEditPageShowEditFormFields($pageEditor, $wgOut) 
     79        { 
     80                global $wgUser, $wgFCKEditorIsCompatible, $wgTitle, $wgVersion; 
     81 
     82                /* 
     83                If FCKeditor extension is enabled, BUT it shouldn't appear (because it's disabled by user, we have incompatible browser etc.) 
     84                We must do this trick to show the original text as WikiText instead of HTML when conflict occurs 
     85                */ 
     86                if ( (!$wgUser->getOption( 'showtoolbar' ) || $wgUser->getOption( 'riched_disable' ) || !$wgFCKEditorIsCompatible) || 
     87                                in_array($wgTitle->getNamespace(), $this->getExcludedNamespaces()) || 
     88                                false !== strpos($pageEditor->textbox1, "__NORICHEDITOR__") 
     89                        ) { 
     90                        if ($pageEditor->isConflict) { 
     91                                $pageEditor->textbox1 = $pageEditor->getWikiContent(); 
     92                        } 
     93                } 
     94                /* 
     95                If FCKeditor extension is enabled, and it should appear 
     96                We must do this trick to show HTML instead of the original text when conflict occurs 
     97                This hack is only needed for MW 1.11 and below 
     98                */ 
     99                else if (version_compare("1.12", $wgVersion, ">")) { 
     100                        if ($pageEditor->isConflict) { 
     101                        $options = new FCKeditorParserOptions(); 
     102                        $options->setTidy(true); 
     103                        $parser = new FCKeditorParser(); 
     104                        $parser->setOutputType(OT_HTML); 
     105                        $pa = $parser->parse($pageEditor->textbox1, $pageEditor->mTitle, $options); 
     106                        $pageEditor->textbox1 = $pa->mText; 
     107                        } 
     108                } 
     109                 
     110                return true; 
     111        } 
     112 
     113        public function onEditPageBeforeConflictDiff($pageEditor, $wgOut) 
     114        { 
     115                global $fckPageEditor, $wgRequest; 
     116 
     117                /* 
     118                Show WikiText instead of HTML when there is a conflict 
     119                http://dev.fckeditor.net/ticket/1385 
     120                */ 
     121                $pageEditor->textbox2 = $wgRequest->getVal( 'wpTextbox1' ); 
     122                $pageEditor->textbox1 = $pageEditor->getWikiContent(); 
     123                                 
     124                return true; 
     125        } 
    77126 
    78127        public function registerHooks() { 
     
    83132                $wgHooks['ParserAfterTidy'][]                   = array($this, 'onParserAfterTidy'); 
    84133                $wgHooks['EditPage::showEditForm:initial'][]    = array($this, 'onEditPageShowEditFormInitial'); 
     134                $wgHooks['EditPage::showEditForm:fields'][]             = array($this, 'onEditPageShowEditFormFields'); 
    85135                $wgHooks['EditPageBeforePreviewText'][]         = array($this, 'onEditPageBeforePreviewText'); 
    86136                $wgHooks['EditPagePreviewTextEnd'][]            = array($this, 'onEditPagePreviewTextEnd'); 
     
    88138                $wgHooks['LanguageGetMagic'][]                  = array($this, "onLanguageGetMagic"); 
    89139                $wgHooks['ParserBeforeInternalParse'][]         = array($this, "onParserBeforeInternalParse"); 
     140                $wgHooks['EditPageBeforeConflictDiff'][]                = array($this, 'onEditPageBeforeConflictDiff'); 
    90141 
    91142                if ($this->debug) { 
     143                        /* 
     144                        This is just an array of all available hooks, useful for debugging and learning 
     145                        Add here all new hooks 
     146                        */ 
    92147                        $opcje =  array('ArticleSave', 
    93148                        'ArticleInsertComplete', 'ArticleSaveComplete', 'TitleMoveComplete', 'ArticleProtect', 'ArticleProtectComplete', 'ArticleDelete', 'ArticleDeleteComplete', 'AlternateEdit', 'ArticleFromTitle', 'ArticleAfterFetchContent', 
     
    209264                global $wgFCKEditorExtDir, $wgFCKEditorDir, $wgFCKEditorHeight, $wgUser; 
    210265                global $wgStylePath, $wgStyleVersion, $wgDefaultSkin, $wgExtensionFunctions; 
     266                global $wgFCKWikiTextBeforeParse; 
    211267 
    212268                if (!$wgUser->getOption( 'showtoolbar' ) || $wgUser->getOption( 'riched_disable' ) || !$wgFCKEditorIsCompatible) { 
     
    226282                $parser = new FCKeditorParser(); 
    227283                $parser->setOutputType(OT_HTML); 
     284                $wgFCKWikiTextBeforeParse = $form->textbox1; 
    228285                $form->textbox1 = $parser->parse($form->textbox1, $wgTitle, $options)->getText(); 
    229286 
     
    315372} 
    316373addOnloadHook( onLoadFCKeditor ) ; 
     374</script> 
     375HEREDOC; 
    317376 
    318377/* 
     378$script .= <<<HEREDOC 
     379<script type="text/javascript"> 
    319380function showSource() { 
    320381        var wp = document.getElementById("wpDiff"); 
     
    346407 
    347408addOnloadHook(showSource); 
    348 */ 
    349409</script> 
    350410HEREDOC; 
     411*/ 
    351412 
    352413                $wgOut->addScript($script);