前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Dokuwiki替换编辑器editor.md

Dokuwiki替换编辑器editor.md

作者头像
孤鸿
发布2022-10-04 14:58:02
8320
发布2022-10-04 14:58:02
举报
文章被收录于专栏:孤鸿孤鸿

一、安装

  1. 到官网下载合适的版本https://www.dokuwiki.org/
  2. 在网站一栏输入:http://你的ip地址/Dokuwiki/install.php 在右上角选好语言,简体中文zh
  3. 然后会弹出这样的安装示意图,启用ACL(推荐)
image-20200630182713350
image-20200630182713350
  1. 根据上示意图,填写信息。分别填写超级用户,全名,E-mail,密码等信息。
  2. 安装结束后,为了安全,要删除install.php文件,然后再用刚才设置的用户名密码登陆。
  3. 关于安全: http://你的ip地址/data/pages/wiki/dokuwiki.txt
  4. 访问 http://你的ip地址/dokuwiki/doku.php

二、配置

  1. 点击admin处的管理 按钮,然后出现页面
  2. 可分别根据用户管理、访问控制列表等来进行设置管理。

三、中文文件名的乱码问题

  1. 在服务器机子上 D:\phpStudy\WWW\dokuwiki\conf\local.php 在最后一行加上:
代码语言:javascript
复制
$conf['fnencode']='gb2312'; #注意分号不能少。 1
  1. 在服务器机子上 D:\phpStudy\WWW\dokuwiki\Inc\pageutils.php 修改两个函数:utf8_encodeFN函数
代码语言:javascript
复制
function utf8_encodeFN($file,$safe=true){
    global $conf;
    if($conf['fnencode'] == 'utf-8') return $file;

    if($safe && preg_match('#^[a-zA-Z0-9/_\-\.%]+$#',$file)){
        return $file;
    }

    if($conf['fnencode'] == 'safe'){
        return SafeFN::encode($file);
    }
    // 中文支持
    if ($conf['fnencode']=='gb2312'){
        return iconv('UTF-8','GB2312',$file);
    }

    $file = urlencode($file);
    $file = str_replace('%2F','/',$file);
    return $file;
}1234567891011121314151617181920

和utf8_decodeFN函数:

代码语言:javascript
复制
function utf8_decodeFN($file){
    global $conf;
    if($conf['fnencode'] == 'utf-8') return $file;

    if($conf['fnencode'] == 'safe'){
        return SafeFN::decode($file);
    }
    // 中文支持
    if ($conf['fnencode']=='gb2312'){
        return iconv('GB2312','UTF-8',$file);
    }
    return urldecode($file);
}12345678910111213

四、安装插件

  1. 新增页面 Add New Page插件
  2. Markdown插件 PHP Markdown Extra plugin
  3. 侧边栏 1)安装simplenavi插件
    1. 新建data\pages\sidebar.txt,内容如下:
代码语言:javascript
复制
===== 导航目录 =====
{{simplenavi>}}
===== 添加新页面 =====
{{NEWPAGE}}1234

五、支持editer.md

1.下载editor.md https://github.com/pandao/editor.md/archive/v1.5.0.tar.gz

2.解压到dokuwiki\lib\editor.md\

3.替换/inc/form.php里的函数form_wikitext($attrs),修改return结果

代码语言:javascript
复制
function form_wikitext($attrs) {
    // mandatory attributes
    unset($attrs['name']);
    unset($attrs['id']);
    $text = str_replace("<markdown>\n",'',$attrs['_text']);
    $text = str_replace("\n</markdown>",'',$text);
    /*
    return '<textarea name="wikitext" id="wiki__text" dir="auto" '
                 .buildAttributes($attrs,true).'>'.DOKU_LF
                 .formText($attrs['_text'])
                 .'</textarea>';
    */
    return '<div id="editormd" contenteditable="true"><textarea name="wikitext">'.DOKU_LF.formText($text)
    .'</textarea></div>';
}123456789101112131415

4.在/inc/parser/xhtml.php里更改cdata函数

代码语言:javascript
复制
    function cdata($text) {
        //$this->doc .= $this->_xmlEntities($text);
        return $this->doc.=$text;
    }1234

替换原因是:因为以前是纯字符编辑器,会将一些特殊符号进行过滤,比如:<>等等.而替换之后的xheditor本身已经做了一次过滤了,再次过滤就会导致字符<变成&lt,因此去掉这段之后,就只过滤一次

5.inc/actions.php的act_save函数

代码语言:javascript
复制
saveWikiText($ID,con($PRE,$TEXT,$SUF,true),$SUM,$INPUT-&gt;bool(&apos;minor&apos;)); //use pretty mode for con
&#x66FF;&#x6362;&#x6210;
saveWikiText($ID,con($PRE,&quot;&lt;markdown&gt;\n&quot;.$TEXT.&quot;\n&lt;/markdown&gt;&quot;,$SUF,true),$SUM,$INPUT-&gt;bool(&apos;minor&apos;)); //use pretty mode for con123

6.在/lib/tpl/dokuwiki/main.php添加editor.md包 head节中添加

代码语言:javascript
复制
&lt;link rel=&quot;stylesheet&quot; href=&quot;&lt;?php echo DOKU_BASE;?&gt;lib/editor.md/css/editormd.min.css&quot; /&gt;1

body节中添加

代码语言:javascript
复制
    &lt;script src=&quot;&lt;?php echo DOKU_BASE;?&gt;lib/editor.md/examples/js/jquery.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;&lt;?php echo DOKU_BASE;?&gt;lib/editor.md/editormd.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot;&gt;
        var testEditor;
        $(function(md) {
            testEditor = editormd(&quot;editormd&quot;, {
                width: &quot;100%&quot;,
                height: 740,

                path: &apos;&lt;?php echo DOKU_BASE;?&gt;lib/editor.md/lib/&apos;,
                theme: &quot;dark&quot;,
                /*
                previewTheme : &quot;dark&quot;,
                editorTheme : &quot;pastel-on-dark&quot;,
                markdown : md,
                */
                codeFold: true,
                syncScrolling: &quot;single&quot;,

                saveHTMLToTextarea: true, // &#x4FDD;&#x5B58; HTML &#x5230; Textarea
                searchReplace: true,
                //watch : false,                                // &#x5173;&#x95ED;&#x5B9E;&#x65F6;&#x9884;&#x89C8;
                htmlDecode: &quot;style,script,iframe|on*&quot;, // &#x5F00;&#x542F; HTML &#x6807;&#x7B7E;&#x89E3;&#x6790;&#xFF0C;&#x4E3A;&#x4E86;&#x5B89;&#x5168;&#x6027;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E0D;&#x5F00;&#x542F;
                //toolbar    : false,                         //&#x5173;&#x95ED;&#x5DE5;&#x5177;&#x680F;
                //previewCodeHighlight : false, // &#x5173;&#x95ED;&#x9884;&#x89C8; HTML &#x7684;&#x4EE3;&#x7801;&#x5757;&#x9AD8;&#x4EAE;&#xFF0C;&#x9ED8;&#x8BA4;&#x5F00;&#x542F;
                emoji: true,
                taskList: true,
                tocm: true, // Using [TOCM]
                tex: true, // &#x5F00;&#x542F;&#x79D1;&#x5B66;&#x516C;&#x5F0F;TeX&#x8BED;&#x8A00;&#x652F;&#x6301;&#xFF0C;&#x9ED8;&#x8BA4;&#x5173;&#x95ED;
                flowChart: true, // &#x5F00;&#x542F;&#x6D41;&#x7A0B;&#x56FE;&#x652F;&#x6301;&#xFF0C;&#x9ED8;&#x8BA4;&#x5173;&#x95ED;
                sequenceDiagram: true, // &#x5F00;&#x542F;&#x65F6;&#x5E8F;/&#x5E8F;&#x5217;&#x56FE;&#x652F;&#x6301;&#xFF0C;&#x9ED8;&#x8BA4;&#x5173;&#x95ED;,
                //dialogLockScreen : false,     // &#x8BBE;&#x7F6E;&#x5F39;&#x51FA;&#x5C42;&#x5BF9;&#x8BDD;&#x6846;&#x4E0D;&#x9501;&#x5C4F;&#xFF0C;&#x5168;&#x5C40;&#x901A;&#x7528;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;true
                //dialogShowMask : false,         // &#x8BBE;&#x7F6E;&#x5F39;&#x51FA;&#x5C42;&#x5BF9;&#x8BDD;&#x6846;&#x663E;&#x793A;&#x900F;&#x660E;&#x906E;&#x7F69;&#x5C42;&#xFF0C;&#x5168;&#x5C40;&#x901A;&#x7528;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;true
                //dialogDraggable : false,        // &#x8BBE;&#x7F6E;&#x5F39;&#x51FA;&#x5C42;&#x5BF9;&#x8BDD;&#x6846;&#x4E0D;&#x53EF;&#x62D6;&#x52A8;&#xFF0C;&#x5168;&#x5C40;&#x901A;&#x7528;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;true
                //dialogMaskOpacity : 0.4,        // &#x8BBE;&#x7F6E;&#x900F;&#x660E;&#x906E;&#x7F69;&#x5C42;&#x7684;&#x900F;&#x660E;&#x5EA6;&#xFF0C;&#x5168;&#x5C40;&#x901A;&#x7528;&#xFF0C;&#x9ED8;&#x8BA4;&#x503C;&#x4E3A;0.1
                //dialogMaskBgColor : &quot;#000&quot;, // &#x8BBE;&#x7F6E;&#x900F;&#x660E;&#x906E;&#x7F69;&#x5C42;&#x7684;&#x80CC;&#x666F;&#x989C;&#x8272;&#xFF0C;&#x5168;&#x5C40;&#x901A;&#x7528;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;#fff
                imageUpload: true,
                imageFormats: [&quot;jpg&quot;, &quot;jpeg&quot;, &quot;gif&quot;, &quot;png&quot;, &quot;bmp&quot;, &quot;webp&quot;],
                imageUploadURL: &quot;&lt;?php echo DOKU_BASE;?&gt;uploadimg.php&quot;,
                onload: function() {}
            });
        });

        window.onload = function() {
            //document.getElementById(&quot;editormd&quot;).addEventListener(&apos;paste&apos;, function (event) {
            $(&quot;#editormd&quot;).on(&apos;paste&apos;, function(event) {
                //console.log(event);
                var items = (event.clipboardData || event.originalEvent.clipboardData).items;
                for (var index in items) {
                    var item = items[index];
                    //console.log(item);
                    if (item.kind === &apos;file&apos;) {
                        var blob = item.getAsFile();                
                        var reader = new FileReader();
                        reader.onload = function(event) {                    
                            var base64 = event.target.result;
                            console.log(base64);
                            //ajax&#x4E0A;&#x4F20;&#x56FE;&#x7247;
                            $.post(&quot;&lt;?php echo DOKU_BASE;?&gt;uploadimg.php&quot;, {
                                screenshots: base64
                            }, function(rets) {
                                ret = JSON.parse(rets);
                                //layer.msg(ret.msg);
                                console.log(ret);
                                if (ret.success === 1) {
                                    //&#x65B0;&#x4E00;&#x884C;&#x7684;&#x56FE;&#x7247;&#x663E;&#x793A;
                                    testEditor.insertValue(&quot;\n![](&quot; + ret.url + &quot;)&quot;);
                                } else {
                                    alert(&quot;&#x622A;&#x56FE;&#x4E0A;&#x4F20;&#x5931;&#x8D25;&#xFF1A;&quot; + ret.message);
                                }
                            });
                        };
                        reader.readAsDataURL(blob);
                    }
                }
            });
        }
    &lt;/script&gt;

7.粘贴图片自动上传支持 修改文件data/.htaccess中的 Deny from all改为 allow from all 上传图片保存代码:

代码语言:javascript
复制
&lt;?php
if(!defined(&apos;DOKU_INC&apos;)) define(&apos;DOKU_INC&apos;, dirname(__FILE__).&apos;/&apos;);
require_once(DOKU_INC.&apos;inc/init.php&apos;);

$hostpath=getBaseURL(false);
$attachDir=&apos;/data/media/editor/&apos;;//&#x4E0A;&#x4F20;&#x6587;&#x4EF6;&#x4FDD;&#x5B58;&#x8DEF;&#x5F84;&#xFF0C;&#x7ED3;&#x5C3E;&#x4E0D;&#x8981;&#x5E26;/
$maxAttachSize = 2*1024*1024;  //&#x6700;&#x5927;&#x4E0A;&#x4F20;&#x5927;&#x5C0F;&#xFF0C;&#x9ED8;&#x8BA4;&#x662F;2M

function upEditorImg(){
    global $hostpath, $attachDir, $maxAttachSize;
    //&#x83B7;&#x53D6;&#x6587;&#x4EF6;&#x7684;&#x5927;&#x5C0F;
    $file_size=$_FILES[&apos;editormd-image-file&apos;][&apos;size&apos;];
    //echo &quot;$file_size $maxAttachSize&quot;;
    if($file_size &gt; $maxAttachSize) {
        echo &apos;{&quot;success&quot;:0,&quot;message&quot;:&quot;&#x4E0D;&#x80FD;&#x4E0A;&#x4F20;&#x5927;&#x4E8E;2M&#x7684;&#x6587;&#x4EF6;&quot;}&apos;;
        return false;
    }

    //&#x83B7;&#x53D6;&#x6587;&#x4EF6;&#x7C7B;&#x578B;
    $file_type=$_FILES[&apos;editormd-image-file&apos;][&apos;type&apos;];
    if($file_type!=&quot;image/jpeg&quot; &amp;&amp; $file_type!=&apos;image/pjpeg&apos; &amp;&amp; $file_type!=&quot;image/png&quot;) {
        echo &apos;{&quot;success&quot;:0,&quot;message&quot;:&quot;&#x56FE;&#x7247;&#x683C;&#x5F0F;&#x5F02;&#x5E38;&quot;}&apos;;
        return false;
    }

    //&#x5224;&#x65AD;&#x662F;&#x5426;&#x4E0A;&#x4F20;&#x6210;&#x529F;&#xFF08;&#x662F;&#x5426;&#x4F7F;&#x7528;post&#x65B9;&#x5F0F;&#x4E0A;&#x4F20;&#xFF09;
    if(is_uploaded_file($_FILES[&apos;editormd-image-file&apos;][&apos;tmp_name&apos;])) {
        //&#x628A;&#x6587;&#x4EF6;&#x8F6C;&#x5B58;&#x5230;&#x4F60;&#x5E0C;&#x671B;&#x7684;&#x76EE;&#x5F55;&#xFF08;&#x4E0D;&#x8981;&#x4F7F;&#x7528;copy&#x51FD;&#x6570;&#xFF09;
        $uploaded_file=$_FILES[&apos;editormd-image-file&apos;][&apos;tmp_name&apos;];

        //&#x6211;&#x4EEC;&#x7ED9;&#x6BCF;&#x4E2A;&#x7528;&#x6237;&#x52A8;&#x6001;&#x7684;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x6587;&#x4EF6;&#x5939;
        $save_path=$_SERVER[&apos;DOCUMENT_ROOT&apos;].$hostpath.$attachDir;
        //&#x5224;&#x65AD;&#x8BE5;&#x7528;&#x6237;&#x6587;&#x4EF6;&#x5939;&#x662F;&#x5426;&#x5DF2;&#x7ECF;&#x6709;&#x8FD9;&#x4E2A;&#x6587;&#x4EF6;&#x5939;
        if(!file_exists($save_path)) {
            mkdir($save_path);
        }

        //$move_to_file=$save_path.&quot;/&quot;.$_FILES[&apos;editormd-image-file&apos;][&apos;name&apos;];
        $file_true_name=$_FILES[&apos;editormd-image-file&apos;][&apos;name&apos;];
        $move_file_name=time().rand(1,1000).substr($file_true_name,strrpos($file_true_name,&quot;.&quot;));
        $move_to_file=$save_path.$move_file_name;
        //echo &quot;$uploaded_file   $move_to_file&quot;;
        if(move_uploaded_file($uploaded_file,iconv(&quot;utf-8&quot;,&quot;gb2312&quot;,$move_to_file))) {
            //echo $_FILES[&apos;editormd-image-file&apos;][&apos;name&apos;].&quot;&#x4E0A;&#x4F20;&#x6210;&#x529F;&quot;;
            //echo &apos;{&quot;success&quot;:1,&quot;message&quot;:&quot;&#x4E0A;&#x4F20;&#x6210;&#x529F;&quot;, &quot;url&quot;:&quot;&apos;.$hostpath.$attachDir.$move_file_name.&apos;&quot;}&apos;;
            $result=array(
              &apos;success&apos;=&gt; 1,
              &apos;message&apos;=&gt;&apos;&#x4E0A;&#x4F20;&#x6210;&#x529F;&apos;,
              &apos;url&apos;=&gt;$hostpath.$attachDir.$move_file_name
            );
            echo json_encode($result);
        } else {
            //echo &quot;&#x4E0A;&#x4F20;&#x5931;&#x8D25;&quot;;
            echo &apos;{&quot;success&quot;:0,&quot;message&quot;:&quot;&#x670D;&#x52A1;&#x5668;&#x4FDD;&#x5B58;&#x6587;&#x4EF6;&#x5931;&#x8D25;&quot;}&apos;;
        }
    } else {
        //echo &quot;&#x4E0A;&#x4F20;&#x5931;&#x8D25;&quot;;
        echo &apos;{&quot;success&quot;:0,&quot;message&quot;:&quot;&#x4E0A;&#x4F20;&#x5931;&#x8D25;&quot;}&apos;;
        return false;
    }
}

//$_POST= [screenshots] =&gt; data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAI0AAACcCAYAAABC1CibAAAL6UlEQVR4Ae2dbUiU6RrH...
function upEditorScreenshots(){
    global $hostpath, $attachDir, $maxAttachSize;

    $content = $_POST[&apos;screenshots&apos;];

    if (preg_match(&apos;/^data:image\/(\w+);base64,(\S+)/&apos;, $content, $result)) {
        $file_type = $result[1];
        $base64data = $result[2];

        //echo &quot;$file_type $base64data&quot;;
        $save_path = $_SERVER[&apos;DOCUMENT_ROOT&apos;].$hostpath.$attachDir;
        if (!is_dir($save_path)) {
            mkdir($save_path, 0777);
        }

        $filedata = base64_decode($base64data);
        $filename = time().rand(1,1000).&quot;.&quot;.$file_type;
        if (!file_put_contents($save_path . $filename, $filedata)) {
            echo &apos;{&quot;success&quot;:0,&quot;message&quot;:&quot;&#x670D;&#x52A1;&#x5668;&#x4FDD;&#x5B58;&#x6587;&#x4EF6;&#x5931;&#x8D25;&quot;}&apos;;
            return false;
        }
        unset($filedata);

        echo &apos;{&quot;success&quot;:1,&quot;message&quot;:&quot;&#x4E0A;&#x4F20;&#x6210;&#x529F;&quot;, &quot;url&quot;:&quot;&apos;.$hostpath.$attachDir.$filename.&apos;&quot;}&apos;;
        return true;
    } else {
        echo &apos;{&quot;success&quot;:0,&quot;message&quot;:&quot;&#x56FE;&#x7247;&#x683C;&#x5F0F;&#x5F02;&#x5E38;&quot;}&apos;;
        return false;
    }
}

//print_r($_POST);
//print_r($_FILES);

if(isset($_FILES[&apos;editormd-image-file&apos;])){
    upEditorImg();
    exit();
}

if(isset($_POST[&apos;screenshots&apos;])){
    upEditorScreenshots();
    exit();
}
?

也可以直接下载已经修改好的源码: https://github.com/mergerly/dokuwiki/tree/stable

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、安装
  • 二、配置
  • 三、中文文件名的乱码问题
  • 四、安装插件
  • 五、支持editer.md
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档