美国主机Lunarpages

Mediawiki中文技术论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 14068|回复: 0

MediaWiki在线可视编辑器(FCKeditor)插件安装指南

[复制链接]
发表于 2011-12-3 11:00:18 | 显示全部楼层 |阅读模式
Godaddy主机最新优惠码
今天给MediaWiki添加可视编辑器 (FCKeditor),方法如下:
--
版本说明
MediaWiki 版本 1.12
FCKeditor 版本 2.62

按照步骤
1. 下载FCKeditor http://www.fckeditor.net
2. 解压到MediaWiki根安装目录,文件夹命名为/FCKeditor
3.在/FCKeditor/fckconfig.js中添加

FCKConfig.ToolbarSets["Wiki"] = [
['Source','-','Save','NewPage','-'],
['Cut','Copy','Paste','PasteText','PasteWord','-','Print'],
['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
['Bold','Italic','Underline','StrikeThrough','-','Subscript','Superscript'],
['OrderedList','UnorderedList','-','Outdent','Indent'],
['JustifyLeft','JustifyCenter','JustifyRight','JustifyFull'],
['Link','Unlink','Anchor'],
['Image','Table','Rule','Smiley','SpecialChar','PageBreak'],
['Style','FontFormat','FontName','FontSize'],
['TextColor','BGColor'],
['About']
] ;

4.在mediawiki的LocalSettings.php 文件中添加

/* Installing this extension may lead to security and technical problems
* as well as data corruption.
*/
require_once("extensions/FCKeditor.php");

$wgFCKUseEditor          = false;      // When set to 'true' the FCKeditor is the default editor.
$wgFCKEditorDir          = "FCKeditor";
$wgFCKEditorToken        = "__USE_EDITOR__";  
$wgFCKEditorToolbarSet   = "Wiki";
$wgFCKEditorHeight       = "600";
$wgFCKEditorAllow_a_tags      = false; // <a> </a>
$wgFCKEditorAllow_img_tags    = false; // <img />
$wgFCKexcludedNamespaces = array();    // eg. "8" for disabling the editor within the MediaWiki namespace.

5.在mediawiki的extensions目录中添加FCKeditor.php文件。
文件内容如下:

<?php

/*
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
*/


if( !defined( 'MEDIAWIKI' ) ) {
  die();
}

$wgExtensionCredits['other'][] = array(

        "name" => "fckeditor extension",
        "author" => "Mafs",
        "version" => "fck/mw-extension May 2006",
        "url" => "http://meta.wikimedia.org/wiki/FCKeditor",
        "description" => "integrating the fckeditor"

);


# REGISTER HOOKS
//$wgHooks['ParserBeforeStrip'][]                 = 'wfFCKeditorBypassParserCut';
//$wgHooks['ParserAfterTidy'][]                   = 'wfFCKeditorBypassParserPaste';
$wgHooks['ArticleAfterFetchContent'][]          = 'wfFCKeditorCheck';
$wgHooks['EditPage::showEditForm:initial'][]    = 'wfFCKeditorAddFCKScript';


function wfFCKeditorAddFCKScript ($q) {
        global $wgOut, $wgTitle, $wgScriptPath;
        global $wgFCKexcludedNamespaces, $wgFCKUseEditor, $wgFCKEditorToolbarSet;
        global $wgFCKEditorDir, $wgFCKEditorHeight;

        $ns_allowed = true;
        $ns = $wgTitle->getNamespace();
        if (in_array($ns, $wgFCKexcludedNamespaces)) $ns_allowed = false;
        
        if ($ns_allowed and $wgFCKUseEditor) {
                $wgOut->addScript( "<script type=\"text/javascript\" src=\"$wgScriptPath/$wgFCKEditorDir/fckeditor.js\"></script>\n" );
               
                $wgOut->addScript("<script type=\"text/javascript\"> function onLoadFCK () { var oFCKeditor = new FCKeditor('wpTextbox1') ; oFCKeditor.BasePath = \"$wgScriptPath/$wgFCKEditorDir/\" ; if (document.getElementById(\"wpTextbox1\")) {oFCKeditor.Height = \"$wgFCKEditorHeight\" ; oFCKeditor.ToolbarSet = \"$wgFCKEditorToolbarSet\" ; oFCKeditor.ReplaceTextarea() ; var oDiv=document.getElementById(\"toolbar\"); oDiv.style.cssText = 'display: none;'; }} addOnloadHook(onLoadFCK); </script>\n");
        }
    return true;   
}

function wfFCKeditorCheck ($q, $text) {
  
        global $wgFCKUseEditor, $wgFCKEditorToken;
        if (preg_match("/$wgFCKEditorToken/i", $text, $a)) {
                $wgFCKUseEditor = true;
        }
return true;
}


function wfFCKeditorBypassParserCut ($q, $text) {
        global $wgFCKexcludedNamespaces, $wgFCKUseEditor, $wgTitle;
        global $wgFCKBypassText, $wgFCKEditorToken;

        $ns_allowed = true;
        $ns = $wgTitle->getNamespace();
        
        if (in_array($ns, $wgFCKexcludedNamespaces)) $ns_allowed = false;
        
        if ($ns_allowed and $wgFCKUseEditor) {
               
                $wgFCKBypassText = $text;
                $text = "";
        }
return true;
}


function wfFCKeditorBypassParserPaste ($q, $text) {

        global $wgOut, $wgTitle, $wgParser;
        global $wgFCKexcludedNamespaces, $wgFCKEditorHeight, $wgFCKEditorToolbarSet, $wgFCKUseEditor;
        global $wgFCKBypassText, $wgFCKEditorToken, $wgFCKEditorAllow_a_tags, $wgFCKEditorAllow_img_tags;
        
        $List   = array();
        $ns_allowed = true;
        $ns = $wgTitle->getNamespace();
        if (in_array($ns, $wgFCKexcludedNamespaces)) $ns_allowed = false;
        
        if ($ns_allowed and $wgFCKUseEditor) {
        
                $fcktext = $wgFCKBypassText;
        
                $fcktext = $q->replaceVariables($fcktext);
               
                if ($wgFCKEditorAllow_a_tags) {
                        $i = 0;
                        $ta = md5("aopen");
                        while (preg_match("|(<a.*?>)|i", $fcktext, $a)) {
                                $j = $ta."_".md5($i);
                                $List[$j]["content"] = $a[0];
                                $List[$j]["index"] = $j;
                                $fcktext = str_replace($a[0], $j, $fcktext);
                                $i++;
                        }
                        $i = 0;
                        $ta = md5("aclose");
                        while (preg_match("|(</a>)|i", $fcktext, $a)) {
                                $j = $ta."_".md5($i);
                                $List[$j]["content"] = $a[0];
                                $List[$j]["index"] = $j;
                                $fcktext = str_replace($a[0], $j, $fcktext);
                                $i++;
                        }
                }
                if ($wgFCKEditorAllow_img_tags) {
                        $i = 0;
                        $timg = md5("img");
                        while (preg_match("|(<img[^>]*?/>)|i", $fcktext, $a)) {
                                $j = $timg."_".md5($i);
                                $List[$j]["content"] = $a[0];
                                $List[$j]["index"] = $j;
                                $fcktext = str_replace($a[0], $j, $fcktext);
                                $i++;
                        }
                }
        
                $tagList = array("pre", "math", "gallery", "nowiki", "html");
                foreach($tagList as $tag) {
                        $fcktext = preg_replace("|<$tag>|i", "<$tag>", $fcktext);
                        $fcktext = preg_replace("|</$tag>|i", "</$tag>", $fcktext);
                }
                foreach($q->mTagHooks as $tag) {
                        $fcktext = preg_replace("|<($tag.*?)>|i", "<\\1>", $fcktext);
                        $fcktext = preg_replace("|</$tag>|i", "</$tag>", $fcktext);
                }
        
                $x =& $state;
                $fcktext = $q->strip($fcktext, $x);
               
                $fcktext = preg_replace("/<\/?tbody>/i","", $fcktext);
                $fcktext = preg_replace("/$wgFCKEditorToken/i","", $fcktext);      
        
                $fcktext = Sanitizer::removeHTMLtags( $fcktext, array( &$q, 'attributeStripCallback' ) );
               
                $fcktext = $wgParser->replaceInternalLinks( $fcktext );
                $fcktext = $wgParser->replaceExternalLinks( $fcktext );
        
                # replaceInternalLinks may sometimes leave behind
                # absolute URLs, which have to be masked to hide them from replaceExternalLinks
                $fcktext = str_replace($wgParser->mUniqPrefix."NOPARSE", "", $fcktext);
               
                $fcktext = $wgParser->doMagicLinks( $fcktext );
                $fcktext = $wgParser->formatHeadings( $fcktext );
        
                $wgParser->replaceLinkHolders( $fcktext );

              //  $fcktext = $q->unstripNoWiki( $fcktext, $state );
               // $fcktext = $q->unstrip($fcktext, $state);
        
                foreach($List as $item) {
                        $fcktext = str_replace($item["index"], $item["content"], $fcktext);
                        $i++;
                }
        
                $text = $fcktext;
        }
        return true;
}

?>
----------------------------------------------------------------
----------------------------------------------------------------
这种方法不支持wiki code,我看到fckeditor有phpbb扩展,想来也该有wiki code的插件,不过功夫不负有心人,到现在终于找到了。
参见:http://mediawiki.fckeditor.net/i ... r_integration_guide
1.Download the extension
svn checkout http://svn.fckeditor.net/MediaWiki/trunk
2.Download the editor
http://mediawiki.fckeditor.net/n ... fckeditor_ext_N.zip
3.Modify configuration file
require_once( "extensions/FCKeditor/FCKeditor.php" );
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

BlueHost美国主机优惠码

Archiver|手机版|小黑屋|Mediawiki中文技术论坛

GMT+8, 2024-4-24 23:21 , Processed in 0.039139 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2024, Tencent Cloud.

快速回复 返回顶部 返回列表