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; }
static function prepareTextForFCK($text) { global $wgTitle; $options = new FCKeditorParserOptions(); $options->setTidy(true); $parser = new FCKeditorParser(); $parser->setOutputType(OT_HTML); $text = $parser->parse($text, $wgTitle, $options)->getText(); return $text; }
/** * Add FCK script * * @param $form EditPage object * @return true */ public function onEditPageShowEditFormInitial($form) { global $wgOut, $wgTitle, $wgScriptPath, $wgContLang, $wgUser; global $wgStylePath, $wgStyleVersion, $wgExtensionFunctions, $wgHooks, $wgDefaultUserOptions; global $wgFCKWikiTextBeforeParse, $wgFCKEditorIsCompatible; global $wgFCKEditorDir; if (!isset($this->showFCKEditor)) { $this->showFCKEditor = 0; if (!$wgUser->getOption('riched_start_disabled', $wgDefaultUserOptions['riched_start_disabled'])) { $this->showFCKEditor += RTE_VISIBLE; } if ($wgUser->getOption('riched_use_popup', $wgDefaultUserOptions['riched_use_popup'])) { $this->showFCKEditor += RTE_POPUP; } if ($wgUser->getOption('riched_use_toggle', $wgDefaultUserOptions['riched_use_toggle'])) { $this->showFCKEditor += RTE_TOGGLE_LINK; } } if (!empty($_SESSION['showMyFCKeditor']) && $wgUser->getOption('riched_toggle_remember_state', $wgDefaultUserOptions['riched_toggle_remember_state'])) { // Clear RTE_VISIBLE flag $this->showFCKEditor &= ~RTE_VISIBLE; // Get flag from session $this->showFCKEditor |= $_SESSION['showMyFCKeditor']; } # Don't initialize if we have disabled the toolbar or FCkeditor or have a non-compatible browser if (!$wgUser->getOption('showtoolbar') || $wgUser->getOption('riched_disable', !empty($wgDefaultUserOptions['riched_disable']) ? $wgDefaultUserOptions['riched_disable'] : false) || !$wgFCKEditorIsCompatible) { return true; } # Don't do anything if we're in an excluded namespace if (in_array($wgTitle->getNamespace(), $this->getExcludedNamespaces())) { return true; } # Make sure that there's no __NORICHEDITOR__ in the text either if (false !== strpos($form->textbox1, '__NORICHEDITOR__')) { return true; } $wgFCKWikiTextBeforeParse = $form->textbox1; if ($this->showFCKEditor & RTE_VISIBLE) { $options = new FCKeditorParserOptions(); $options->setTidy(true); $parser = new FCKeditorParser(); $parser->setOutputType(OT_HTML); $form->textbox1 = str_replace('<!-- Tidy found serious XHTML errors -->', '', $parser->parse($form->textbox1, $wgTitle, $options)->getText()); } $printsheet = htmlspecialchars("{$wgStylePath}/common/wikiprintable.css?{$wgStyleVersion}"); $script = <<<HEREDOC <script type="text/javascript" src="{$wgScriptPath}/{$wgFCKEditorDir}/fckeditor.js"></script> <script type="text/javascript"> var sEditorAreaCSS = '{$printsheet},/mediawiki/skins/monobook/main.css?{$wgStyleVersion}'; </script> <!--[if lt IE 5.5000]><script type="text/javascript">sEditorAreaCSS += ',/mediawiki/skins/monobook/IE50Fixes.css?{$wgStyleVersion}'; </script><![endif]--> <!--[if IE 5.5000]><script type="text/javascript">sEditorAreaCSS += ',/mediawiki/skins/monobook/IE55Fixes.css?{$wgStyleVersion}'; </script><![endif]--> <!--[if IE 6]><script type="text/javascript">sEditorAreaCSS += ',/mediawiki/skins/monobook/IE60Fixes.css?{$wgStyleVersion}'; </script><![endif]--> <!--[if IE 7]><script type="text/javascript">sEditorAreaCSS += ',/mediawiki/skins/monobook/IE70Fixes.css?{$wgStyleVersion}'; </script><![endif]--> <!--[if lt IE 7]><script type="text/javascript">sEditorAreaCSS += ',/mediawiki/skins/monobook/IEFixes.css?{$wgStyleVersion}'; </script><![endif]--> HEREDOC; # Show references only if Cite extension has been installed $showRef = false; if (isset($wgHooks['ParserFirstCallInit']) && in_array('wfCite', $wgHooks['ParserFirstCallInit']) || isset($wgExtensionFunctions) && in_array('wfCite', $wgExtensionFunctions)) { $showRef = true; } $showSource = false; if (isset($wgHooks['ParserFirstCallInit']) && in_array('efSyntaxHighlight_GeSHiSetup', $wgHooks['ParserFirstCallInit']) || isset($wgExtensionFunctions) && in_array('efSyntaxHighlight_GeSHiSetup', $wgExtensionFunctions)) { $showSource = true; } $script .= ' <script type="text/javascript"> var showFCKEditor = ' . $this->showFCKEditor . '; var popup = false; // pointer to popup document var firstLoad = true; var editorMsgOn = "' . Xml::escapeJsString(wfMsgHtml('textrichditor')) . '"; var editorMsgOff = "' . Xml::escapeJsString(wfMsgHtml('tog-riched_disable')) . '"; var editorLink = "' . ($this->showFCKEditor & RTE_VISIBLE ? Xml::escapeJsString(wfMsgHtml('tog-riched_disable')) : Xml::escapeJsString(wfMsgHtml('textrichditor'))) . '"; var saveSetting = ' . ($wgUser->getOption('riched_toggle_remember_state', $wgDefaultUserOptions['riched_toggle_remember_state']) ? 1 : 0) . '; var RTE_VISIBLE = ' . RTE_VISIBLE . '; var RTE_TOGGLE_LINK = ' . RTE_TOGGLE_LINK . '; var RTE_POPUP = ' . RTE_POPUP . '; var oFCKeditor = new FCKeditor( "wpTextbox1" ); // Set config oFCKeditor.BasePath = wgScriptPath + "/" + wgFCKEditorDir; oFCKeditor.Config["CustomConfigurationsPath"] = wgScriptPath + "/" + wgFCKEditorExtDir + "/fckeditor_config.js";'; // Load fckeditor-rtl.css for right-to-left languages, but only fckeditor.css for other languages if ($wgContLang->isRTL()) { $script .= 'oFCKeditor.Config["EditorAreaCSS"] = wgScriptPath + "/" + wgFCKEditorExtDir + "/css/fckeditor.css," + wgScriptPath + "/" + wgFCKEditorExtDir + "/css/fckeditor-rtl.css";'; } else { $script .= 'oFCKeditor.Config["EditorAreaCSS"] = wgScriptPath + "/" + wgFCKEditorExtDir + "/css/fckeditor.css";'; } $script .= ' oFCKeditor.ToolbarSet = wgFCKEditorToolbarSet; oFCKeditor.ready = true; oFCKeditor.Config["showreferences"] = ' . ($showRef ? 'true' : 'false') . '; oFCKeditor.Config["showsource"] = ' . ($showSource ? 'true' : 'false') . '; '; $script .= '</script>'; $newWinMsg = Xml::escapeJsString(wfMsgHtml('rich_editor_new_window')); $script .= <<<HEREDOC <script type="text/javascript"> //IE hack to call func from popup function FCK_sajax(func_name, args, target) { \tsajax_request_type = 'POST'; \tsajax_do_call(func_name, args, function (x) { \t\t// I know this is function, not object \t\ttarget(x); \t\t} \t); } function onLoadFCKeditor(){ \tif( !( showFCKEditor & RTE_VISIBLE ) ) \t\tshowFCKEditor += RTE_VISIBLE; \tfirstLoad = false; \trealTextarea = document.getElementById( 'wpTextbox1' ); \tif ( realTextarea ){ \t\tvar height = wgFCKEditorHeight; \t\trealTextarea.style.display = 'none'; \t\tif ( height == 0 ){ \t\t\t// Get the window (inner) size. \t\t\tvar height = window.innerHeight || ( document.documentElement && document.documentElement.clientHeight ) || 550; \t\t\t// Reduce the height to the offset of the toolbar. \t\t\tvar offset = document.getElementById( 'wikiPreview' ) || document.getElementById( 'toolbar' ); \t\t\twhile ( offset ){ \t\t\t\theight -= offset.offsetTop; \t\t\t\toffset = offset.offsetParent; \t\t\t} \t\t\t// Add a small space to be left in the bottom. \t\t\theight -= 20; \t\t} \t\t// Enforce a minimum height. \t\theight = ( !height || height < 300 ) ? 300 : height; \t\t// Create the editor instance and replace the textarea. \t\toFCKeditor.Height = height; \t\toFCKeditor.ReplaceTextarea(); \t\t// Hide the default toolbar. \t\tdocument.getElementById( 'toolbar' ).style.display = 'none'; \t\t// do things with CharInsert for example \t\tvar edittools_markup = document.getElementById( 'editpage-specialchars' ); \t\tif( edittools_markup ) { \t\t\tedittools_markup.style.display = 'none'; \t\t} \t\tFCKeditorInsertTags = function( tagOpen, tagClose, sampleText, oDoc ){ \t\t\tvar txtarea; \t\t\tif ( !( typeof(oDoc.FCK) == "undefined" ) && !( typeof(oDoc.FCK.EditingArea) == "undefined" ) ){ \t\t\t\ttxtarea = oDoc.FCK.EditingArea.Textarea; \t\t\t} else if( oDoc.editform ){ \t\t\t\t// if we have FCK enabled, behave differently... \t\t\t\tif ( showFCKEditor & RTE_VISIBLE ){ \t\t\t\t\tSRCiframe = oDoc.getElementById( 'wpTextbox1___Frame' ); \t\t\t\t\tif ( SRCiframe ){ \t\t\t\t\t\tif( window.frames[SRCiframe] ) \t\t\t\t\t\t\tSRCdoc = window.frames[SRCiframe].oDoc; \t\t\t\t\t\telse \t\t\t\t\t\t\tSRCdoc = SRCiframe.contentDocument; \t\t\t\t\t\tvar SRCarea = SRCdoc.getElementById( 'xEditingArea' ).firstChild; \t\t\t\t\t\tif( SRCarea ) \t\t\t\t\t\t\ttxtarea = SRCarea; \t\t\t\t\t\telse \t\t\t\t\t\t\treturn false; \t\t\t\t\t} else { \t\t\t\t\t\treturn false; \t\t\t\t\t} \t\t\t\t} else { \t\t\t\t\ttxtarea = oDoc.editform.wpTextbox1; \t\t\t\t} \t\t\t} else { \t\t\t\t// some alternate form? take the first one we can find \t\t\t\tvar areas = oDoc.getElementsByTagName( 'textarea' ); \t\t\t\ttxtarea = areas[0]; \t\t\t} \t\t\tvar selText, isSample = false; \t\t\tif ( oDoc.selection && oDoc.selection.createRange ){ // IE/Opera \t\t\t\t// save window scroll position \t\t\t\tif ( oDoc.documentElement && oDoc.documentElement.scrollTop ) \t\t\t\t\tvar winScroll = oDoc.documentElement.scrollTop; \t\t\t\telse if ( oDoc.body ) \t\t\t\t\tvar winScroll = oDoc.body.scrollTop; \t\t\t\t// get current selection \t\t\t\ttxtarea.focus(); \t\t\t\tvar range = oDoc.selection.createRange(); \t\t\t\tselText = range.text; \t\t\t\t// insert tags \t\t\t\tcheckSelected(); \t\t\t\trange.text = tagOpen + selText + tagClose; \t\t\t\t// mark sample text as selected \t\t\t\tif ( isSample && range.moveStart ){ \t\t\t\t\tif( window.opera ) \t\t\t\t\t\ttagClose = tagClose.replace(/\\n/g,''); // check it out one more time \t\t\t\t\trange.moveStart( 'character', - tagClose.length - selText.length ); \t\t\t\t\trange.moveEnd( 'character', - tagClose.length ); \t\t\t\t} \t\t\t\trange.select(); \t\t\t\t// restore window scroll position \t\t\t\tif ( oDoc.documentElement && oDoc.documentElement.scrollTop ) \t\t\t\t\toDoc.documentElement.scrollTop = winScroll; \t\t\t\telse if ( oDoc.body ) \t\t\t\t\toDoc.body.scrollTop = winScroll; \t\t\t} else if ( txtarea.selectionStart || txtarea.selectionStart == '0' ){ // Mozilla \t\t\t\t// save textarea scroll position \t\t\t\tvar textScroll = txtarea.scrollTop; \t\t\t\t// get current selection \t\t\t\ttxtarea.focus(); \t\t\t\tvar startPos = txtarea.selectionStart; \t\t\t\tvar endPos = txtarea.selectionEnd; \t\t\t\tselText = txtarea.value.substring( startPos, endPos ); \t\t\t\t// insert tags \t\t\t\tif( !selText ){ \t\t\t\t\tselText = sampleText; \t\t\t\t\tisSample = true; \t\t\t\t} else if( selText.charAt(selText.length - 1) == ' ' ){ //exclude ending space char \t\t\t\t\tselText = selText.substring(0, selText.length - 1); \t\t\t\t\ttagClose += ' '; \t\t\t\t} \t\t\t\ttxtarea.value = txtarea.value.substring(0, startPos) + tagOpen + selText + tagClose + \t\t\t\t\t\t\t\ttxtarea.value.substring(endPos, txtarea.value.length); \t\t\t\t// set new selection \t\t\t\tif( isSample ){ \t\t\t\t\ttxtarea.selectionStart = startPos + tagOpen.length; \t\t\t\t\ttxtarea.selectionEnd = startPos + tagOpen.length + selText.length; \t\t\t\t} else { \t\t\t\t\ttxtarea.selectionStart = startPos + tagOpen.length + selText.length + tagClose.length; \t\t\t\t\ttxtarea.selectionEnd = txtarea.selectionStart; \t\t\t\t} \t\t\t\t// restore textarea scroll position \t\t\t\ttxtarea.scrollTop = textScroll; \t\t\t} \t\t} \t} } function checkSelected(){ \tif( !selText ) { \t\tselText = sampleText; \t\tisSample = true; \t} else if( selText.charAt(selText.length - 1) == ' ' ) { //exclude ending space char \t\tselText = selText.substring(0, selText.length - 1); \t\ttagClose += ' ' \t} } function initEditor(){ \tvar toolbar = document.getElementById( 'toolbar' ); \t// show popup or toogle link \tif( showFCKEditor & ( RTE_POPUP|RTE_TOGGLE_LINK ) ){ \t\t// add new toolbar before wiki toolbar \t\tvar fckTools = document.createElement( 'div' ); \t\tfckTools.setAttribute('id', 'fckTools'); \t\ttoolbar.parentNode.insertBefore( fckTools, toolbar ); \t\tvar SRCtextarea = document.getElementById( 'wpTextbox1' ); \t\tif( showFCKEditor & RTE_VISIBLE ) SRCtextarea.style.display = 'none'; \t} \tif( showFCKEditor & RTE_TOGGLE_LINK ){ \t\tfckTools.innerHTML='[<a class="fckToogle" id="toggle_wpTextbox1" href="javascript:void(0)" onclick="ToggleFCKEditor(\\'toggle\\',\\'wpTextbox1\\')">'+ editorLink +'</a>] '; \t} \tif( showFCKEditor & RTE_POPUP ){ \t\tvar style = (showFCKEditor & RTE_VISIBLE) ? 'style="display:none"' : ""; \t\tfckTools.innerHTML+='<span ' + style + ' id="popup_wpTextbox1">[<a class="fckPopup" href="javascript:void(0)" onclick="ToggleFCKEditor(\\'popup\\',\\'wpTextbox1\\')">{$newWinMsg}</a>]</span>'; \t} \tif( showFCKEditor & RTE_VISIBLE ){ \t\tif ( toolbar ){\t// insert wiki buttons \t\t\t// Remove the mwSetupToolbar onload hook to avoid a JavaScript error with FF. \t\t\tif ( window.removeEventListener ) \t\t\t\twindow.removeEventListener( 'load', mwSetupToolbar, false ); \t\t\telse if ( window.detachEvent ) \t\t\t\twindow.detachEvent( 'onload', mwSetupToolbar ); \t\t\tmwSetupToolbar = function(){ return false ; }; \t\t\tfor( var i = 0; i < mwEditButtons.length; i++ ) { \t\t\t\tmwInsertEditButton(toolbar, mwEditButtons[i]); \t\t\t} \t\t\tfor( var i = 0; i < mwCustomEditButtons.length; i++ ) { \t\t\t\tmwInsertEditButton(toolbar, mwCustomEditButtons[i]); \t\t\t} \t\t} \t\tonLoadFCKeditor(); \t} \treturn true; } addOnloadHook( initEditor ); HEREDOC; if ($this->showFCKEditor & (RTE_TOGGLE_LINK | RTE_POPUP)) { // add toggle link and handler $script .= <<<HEREDOC function ToggleFCKEditor( mode, objId ){ \tvar SRCtextarea = document.getElementById( objId ); \tif( mode == 'popup' ){ \t\tif ( ( showFCKEditor & RTE_VISIBLE ) && ( FCKeditorAPI ) ) { // if FCKeditor is up-to-date \t\t\tvar oEditorIns = FCKeditorAPI.GetInstance( objId ); \t\t\tvar text = oEditorIns.GetData( oEditorIns.Config.FormatSource ); \t\t\tSRCtextarea.value = text; // copy text to textarea \t\t} \t\tFCKeditor_OpenPopup('oFCKeditor', objId); \t\treturn true; \t} \tvar oToggleLink = document.getElementById( 'toggle_' + objId ); \tvar oPopupLink = document.getElementById( 'popup_' + objId ); \tif ( firstLoad ){ \t\t// firstLoad = true => FCKeditor start invisible \t\tif( oToggleLink ) oToggleLink.innerHTML = 'Loading...'; \t\tsajax_request_type = 'POST'; \t\toFCKeditor.ready = false; \t\tsajax_do_call('wfSajaxWikiToHTML', [SRCtextarea.value], function( result ){ \t\t\tif ( firstLoad ){ //still \t\t\t\tSRCtextarea.value = result.responseText; // insert parsed text \t\t\t\tonLoadFCKeditor(); \t\t\t\tif( oToggleLink ) oToggleLink.innerHTML = editorMsgOff; \t\t\t\toFCKeditor.ready = true; \t\t\t} \t\t}); \t\treturn true; \t} \tif( !oFCKeditor.ready ) return false; // sajax_do_call in action \tif( !FCKeditorAPI ) return false; // not loaded yet \tvar oEditorIns = FCKeditorAPI.GetInstance( objId ); \tvar oEditorIframe = document.getElementById( objId + '___Frame' ); \tvar FCKtoolbar = document.getElementById( 'toolbar' ); \tvar bIsWysiwyg = ( oEditorIns.EditMode == FCK_EDITMODE_WYSIWYG ); \t//FCKeditor visible -> hidden \tif ( showFCKEditor & RTE_VISIBLE ){ \t\tvar text = oEditorIns.GetData( oEditorIns.Config.FormatSource ); \t\tSRCtextarea.value = text; \t\tif ( bIsWysiwyg ) oEditorIns.SwitchEditMode(); // switch to plain \t\tvar text = oEditorIns.GetData( oEditorIns.Config.FormatSource ); \t\t// copy from FCKeditor to textarea \t\tSRCtextarea.value = text; \t\tif( saveSetting ){ \t\t\tsajax_request_type = 'GET'; \t\t\tsajax_do_call( 'wfSajaxToggleFCKeditor', ['hide'], function(){} ); //remember closing in session \t\t} \t\tif( oToggleLink ) oToggleLink.innerHTML = editorMsgOn; \t\tif( oPopupLink ) oPopupLink.style.display = ''; \t\tshowFCKEditor -= RTE_VISIBLE; \t\toEditorIframe.style.display = 'none'; \t\tFCKtoolbar.style.display = ''; \t\tSRCtextarea.style.display = ''; \t} else { \t\t// FCKeditor hidden -> visible \t\tif ( bIsWysiwyg ) oEditorIns.SwitchEditMode(); // switch to plain \t\tSRCtextarea.style.display = 'none'; \t\t// copy from textarea to FCKeditor \t\toEditorIns.EditingArea.Textarea.value = SRCtextarea.value; \t\tFCKtoolbar.style.display = 'none'; \t\toEditorIframe.style.display = ''; \t\tif ( !bIsWysiwyg ) oEditorIns.SwitchEditMode();\t// switch to WYSIWYG \t\tshowFCKEditor += RTE_VISIBLE; // showFCKEditor+=RTE_VISIBLE \t\tif( oToggleLink ) oToggleLink.innerHTML = editorMsgOff; \t\tif( oPopupLink ) oPopupLink.style.display = 'none'; \t} \treturn true; } HEREDOC; } if ($this->showFCKEditor & RTE_POPUP) { $script .= <<<HEREDOC function FCKeditor_OpenPopup(jsID, textareaID){ \tpopupUrl = wgFCKEditorExtDir + '/FCKeditor.popup.html'; \tpopupUrl = popupUrl + '?var='+ jsID + '&el=' + textareaID; \twindow.open(popupUrl, null, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=1,dependent=yes'); \treturn 0; } HEREDOC; } $script .= '</script>'; $wgOut->addScript($script); return true; }
function wfSajaxWikiToHTML($wiki) { global $wgTitle; $options = new FCKeditorParserOptions(); $options->setTidy(true); $parser = new FCKeditorParser(); $parser->setOutputType(OT_HTML); wfSajaxToggleFCKeditor('show'); // FCKeditor was switched to visible return str_replace('<!-- Tidy found serious XHTML errors -->', '', $parser->parse($wiki, $wgTitle, $options)->getText()); }