|
今天给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" );
|
|