Dokuwiki 语法插件开发

Dokuwiki 语法插件开发

对语法标签的匹配采用PHP preg函数进行。

插件类需要实现以下方法:

  • getType() 返回此插件定义的模式类型。比如标签内部是纯文本等。
  • getSort() 返回此插件的优先级。数字越小,优先级越高。比如:需要替换系统的<code>标签。
  • connectTo($mode) 用来向词法分析器Lexer注册模式匹配的正则表达式。
  • postConnect() 当在connectTo()中注册的是起始正则表达式,则需要实现此函数,注册中止正则表达式。
  • handle($match, $state, $pos, Doku_Handler &$handler) 处理匹配出的内容,返回在渲染器中使用的内容。
  • render($mode, Doku_Renderer &$renderer, $data) 渲染内容。

当需要的时候,可以重载以下方法:

  • getPType() 返回生成内容的段落的形式。
  • getAllowedTypes() 返回允许内联的模式。(默认array())
  • accepts($mode) 返回是否允许内联自己的模式。

参考:devel:syntax_plugins devel:parser

Dokuwiki 常见问题

Dokuwiki 常见问题

– 设置时区

要正确设置时区,编辑“conf/local.protected.php”(如果你修改“conf/local.php”,你的修改将在通过GUI配置的时候丢失)。 并添加下面一行(这里的例子是东八区,即中国大陆时间):时区名字参考 http://us.php.net/timezones

// php4版本
putenv("Asia/Chongqing");   // php5 版本
date_default_timezone_set("Asia/Chongqing");

– 刷新页面缓存

在url后加&purge=true

– 导出文件

在url后加&do=export_xhtml

可以是rawxhtmlxhtmlbody

– data目录结构

  • data/pages 页面
  • data/meta 页面创建时间等元数据
  • data/attic 编辑历史版本数据。若不想保留旧版,可清空。
  • data/media 图片等媒体
  • data/media-meta 媒体元数据
  • data/media-attic 媒体历史版本数据。若不想保留旧版,可清空。
  • data/cache 缓存。可清空。

Dokuwiki 侧边栏配置

Dokuwiki 侧边栏配置

默认的模版 dokuwiki,支持侧边栏。

  • (1)配置里有个 sidebar 侧边栏的页面名称,这里填写 页面路径
  • (2)创建这个页面。

此时,侧边栏就出来了。

当同级命名空间下有相应的侧边栏页面,则使用此页面。

相关插件

simplenavi

根据访问者权限列出所有命名空间,默认自动展开当前页面所属空间,不能折叠此空间。

命名空间页面链接自动指向:start页。

{{simplenavi>}}

可以指定起始空间:{{simplenavi>some:namespace}}
simpleindex

根据访问者权限列出所有命名空间,默认自动关闭所有命名空间。

<simpleindex>

可以指定排除的空间:<simpleindex ns1,ns2>
indexmenu

基于dtree,

navi

利用一个页面中的链接生成导航。自动根据当前页面展开命名空间。

Sidebar Template

自动加载本命名空间的sidebar页面。展示形式跟Dokuwiki的站点地图一样。

NsToC

列出指定命名空间的标题,可以指定标题的层级。场景:比如图书的目录等。

其他

pageindex,catlist, dir, nspages, pagequery

Dokuwiki 插件整理

内置插件

非内置插件

  • Add New Page plugin:addnewpage 在页面中显示添加新页面表单
  • Ace Editor plugin:aceeditor 支持键盘功能键的编辑器。注意:该插件已不再维护。请使用CodeMirror插件。
  • markdownextra plugin:markdownextra 支持markdown语法
  • mathpublish plugin:mathpublish 数学公式渲染
  • move plugin:move 移动页面的同时移动对应的媒体,修改链接到它的页面链接。
  • Meta plugin:meta 指定页面元数据,比如页面标题、作者、创建时间等。以用作其他用途。不会覆盖data/meta中数据
  • OpenOffice.org Export plugin:odt 导出odt格式文档(相当于word)

更多参考

Dokuwiki 自動切換 Mobile 呈現頁面方式

因為最近開始使用 hTC Incredible S , 有這樣的需求, 很快找了一些現成的資料, 立即實現這樣的功能.

處理程序

  • 下載安裝 dokumobile Template

    cd /var/www/html/wiki/lib/tpl
    wget http://kjh.ca/dokumobile_2010_02_28.zip
    unzip dokumobile_2010_02_28.zip
  • 會出現 dokumobile 目錄, 然後修改 top_bar.php 第9-11行, 解決無法出現表頭圖樣的問題, 修改如下

         <td width="33%" style="border:0;" align="left"><img src="<?php echo DOKU_TPL?>images/icon_left.png" id="toggle_toc" /></td>
         <td width="33%" style="border:0;" align="center"><img src="<?php echo DOKU_TPL?>images/icon_middle.png" id="toggle_admin" /></td>
         <td width="33%" style="border:0;" align="right"><img src="<?php echo DOKU_TPL?>images/icon_right.png" id="toggle_nav" /></td>
  • 下載 Mobile_Detect.php 到 conf 目錄內

    cd /var/www/html/wiki/conf
    wget http://php-mobile-detect.googlecode.com/files/Mobile_Detect.php
  • 修改 inc/init.php 1)

    vi /var/www/html/wiki/inc/init.php
    • 在 72-77 行加入以下程式碼

      // for Mobile http://www.dokuwiki.org/template:dokumobile include(DOKU_CONF . "Mobile_Detect.php"); $mdetect = new Mobile_Detect(); if ($mdetect->isMobile()) {$conf['template']='dokumobile';}
    • 在原本 121-127 define Template baseURL, define real Template directory 要取消不執行

      #// define Template baseURL #if(!defined('DOKU_TPL')) define('DOKU_TPL', #        DOKU_BASE.'lib/tpl/'.$conf['template'].'/');  #// define real Template directory #if(!defined('DOKU_TPLINC')) define('DOKU_TPLINC', #        DOKU_INC.'lib/tpl/'.$conf['template'].'/');

Dokuwiki 相簿應用的 plugin

以下是整理最近安裝 Gallery Plugin後整理出來方便上傳與呈現的相簿相關 plugin

– 安裝相關 plugin

– 設定與建立頁面

  • 本範例是將 scucs83:gallery 當相簿清單頁面, 主要的 code 如下:
====== 電子相簿 ======
|新增相簿|{{NEWPAGE>scucs83:gallery}}|
<style box>
{{indexmenu>scucs83:gallery#1|js navbar nocookie msort#date:modified rsort}}
</style>
  • scucs83:gallery:20080630 當相簿內頁, 主要的 code 如下:
====== 東吳校園現況 ======
{{gallery>scucs83:gallery:20080630?lightbox}}

– 相簿內頁 template

  • 讓每次建立新的相簿內頁都會自動帶出這些預設資訊
cd data/pages/scucs83/galley
vi _template.txt
====== 相簿主題 ======
{{gallery>scucs83:gallery:@PAGE@?lightbox}}

– 新增相簿

  1. 在 PC 端建立一個 20080703 的相簿目錄
  2. 先將要上傳的照片檔都放入 20080703 相簿目錄內
  3. 使用 7-zip 將這個目錄押成 20080703.zip
  4. 透過相簿清單頁面的新增頁面功能輸入 20080703 → 新增頁面
  5. 將 template 所帶出來的 相簿主題 改成實際的主題
  6. 點下加入圖案或檔案 icon 選 20080703.zip 並勾選 Unpack archive after upload 上傳
  7. 關閉上傳視窗
  8. 儲存新增頁面

– 展示

Dokuwiki 升級方式

環境說明

  • 原本 dokuwiki 安裝的路徑為 /var/www/html/dokuwiki
  • 預計更新成 2009-02-14 的版本

確認目前版本

cd /var/www/html/dokuwiki
cat VERSION
2007-06-26b

產生新版本與原有版本差異檔

cd /tmp
mkdir WikiUpgrade
cd WikiUpgrade
wget http://www.splitbrain.org/_media/projects/dokuwiki/dokuwiki-2007-06-26b.tgz
wget http://www.splitbrain.org/_media/projects/dokuwiki/dokuwiki-2009-02-14.tgz
tar -xzf dokuwiki-2007-06-26b.tgz
tar -xzf dokuwiki-2009-02-14.tgz
diff -Naur dokuwiki-2007-06-26b dokuwiki-2009-02-14 > doku.diff

備份原本檔案與升級

備份原本檔案

cd /var/www/html
tar -cf dokuwiki.tar dokuwiki/
gzip dokuwiki.tar
  • 備份檔案就是 dokuwiki.tar.gz

測試升級

cd /var/www/html/dokuwiki
patch -p1 </tmp/WikiUpgrade/doku.diff --dry-run

正式升級

cd /var/www/html/dokuwiki
patch -p1 </tmp/WikiUpgrade/doku.diff

清除更版訊息

cd /var/www/html/dokuwiki/data/cache
echo "" > messages.txt

這樣要求升級的訊息就會消失

DokuWiki Plugin 精選

– 版面相關

– yalist

– box

<box 80% round orange|a title> the box contents</box>
<box 50% left blue>the box contents</box|a caption>
<box 60% round #f99 #fc9 #fcc #f60|title>the box contents></box|caption>
  • 呈現範例

a title

the box contents

the box contents

a caption

title

the box contents>

caption

– styler

– note

– include

– columns

– Translation

設定說明

– source

– code2

因為 code3 在中文字顯示會有太小不清楚的問題, 在短時間內我又無法調整好 style.css, 所以就直接改用這個 code2 的方案

如果對 code3 還是有興趣者, 可以點這裡參考以下是調整 code3 的處理方式(調整之後, 在 FireFox 還是會出現行距太高的問題.)

點這裡看基本語法

1|h 點這裡可看 code2 的 Sample|h

<?php # 13:09 2007/10/29 # Update by Jonathan Tsai #  require_once("twitter.conf.php");   # 設定傳入參數改以 p_ 開頭變數表示 import_request_variables('gp', 'p_');   $username = ($p_username!="")?$p_username:$username; $password = ($p_password!="")?$p_password:$password; : : ?>

– 操作功能

– rss

– addnewpage

– alphaindex

– indexmenu

– tag

– searchresults

{{search>"關鍵字" @namespace}}
{{backlinks>wiki}}

– Page Redirector

~~REDIRECT>namespace:page~~

– Folded

點這看使用說明(也用 block 方式展示)

– Select

<select 我的最愛> tech:menu|技術分享資訊 start:software:list|推薦免費軟體

http://blog.ichiayi.com|Jonathan’s Blog http://www.google.com|Google http://docs.google.com | Google Office </select>

  • 語法如下:
<select 我的最愛>
tech:menu|技術分享資訊
start:software:list|推薦免費軟體

http://blog.ichiayi.com|Jonathan's Blog
http://www.google.com|Google
http://docs.google.com | Google Office
</select>

– BookmarkMe

  • 使用說明:
    1. 安裝後預設是每頁底下都會出現這個加入書籤的工具列
    2. 透過管理選單的系統設定將 「Display social bookmarks」打勾拿掉
    3. 在需要顯示的頁面加入這語法

      ~~BOOKMARKME:on~~

  • 增加推推王黑米書籤網站說明
    1. – 編輯 lib/plugins/bookmarkme/bookmark.ini|

..

funp   http://funp.com/push/submit/add.php
hemidemi  http://www.hemidemi.com/user_bookmark/new?title=%title%&amp;url=%permalink%
  1. 將 funp 與 hemedemi 的代表小圖檔放入 lib/plugins/bookmarkme/img/ 內命名為 funp.gif 與 hemidemi.gif 2)
  2. 在 管理選單的系統設定 內「Enable bookmarking for」底下加上 funp,hemidemi 這個兩個定義名稱, 中間用“,”隔開

– Keyboard

– CAPTCHA

– 應用類型

– s5

~~SLIDESHOW~~

– Ditaa

<ditaa name=test>

+--------+     /--------\
|  Test  +---->| Test 2 |
+--------+     \--------/

</ditaa>

<ditaa name=test>

+——–+ /——–\

Test +—→ Test 2

+——–+ \——–/

</ditaa>

安裝後要修改實際 java 與 jar 路徑

– graphviz

FIXME

– contact

– poll

– AV Bar Chart

1000|A:500,B:50,C:250,D:1000

<barchart>1000|A:500,B:50,C:250,D:1000</barchart>

– doodle

<doodle [disable] [single] [login]| [id]>
^ [choice] ^ [choice] ^ ... ^
</doodle>
  • disable : 表示不可以投票(只能看結果)
  • single : 表示單選(不指定就是複選)
  • login : 使用 login name (沒有 login 只能看無法投票)

– freemind

參數說明與呈現範例

– abc

– googlemap

25.027459,121.475862,宜家男的髮藝造型

<googlemap width="300px" height="300px" lat="25.027459" lon="121.475862" type="map" zoom="16">
25.027459,121.475862,宜家男的髮藝造型
</googlemap>

– youtube

– flowplay

– mp3play

– AutoViewer

語法與範例:

– imstatus

– 系統管理

– googleanalytics

– Loglog

– Statistics

– superacl

– Bad Behaviour

– 待評估項目

Mantis 與 Dokuwiki 整合作法

– dokuwiki 部份

  1. 先安裝好 dokuwiki,可參考 DokuWiki安裝程序
  2. 安裝完成後的 dokuwiki 環境假設網址是 http://192.168.11.250/dokuwiki 實體路徑 /var/www/html/dokuwiki
  3. 更改 dokuwiki 系統設定檔 /var/www/html/dokuwiki/conf/local.protected.php (如果改 local.php 透過網頁介面更改就會不見)

    <?php /* for intergrating with Mantis */ define( 'MANTIS_ROOT', '/var/www/html/mantis/' ); define( 'MANTIS_URL', 'http://localhost/mantis/' ); ?>
  4. 建立 mantis 認證程式碼 /var/www/html/dokuwiki/inc/auth/mantis.class.php

    <?php /**
     * Mantis auth backend
     *
     * Uses external Trust mechanism to check against Mantis'
     * user cookie.
     *
     * @author    Victor Boctor (http://www.futureware.biz)
     */   require_once( MANTIS_ROOT . 'core.php' );   class auth_mantis extends auth_basic { /**
       * Constructor.
       *
       * Sets additional capabilities and config strings
       */ function auth_mantis(){ $this->cando['external'] = true; }   /**
       * Authenticates the user using Mantis APIs.
       */ function trustExternal($user,$pass,$sticky=false){ global $USERINFO; global $conf;   if ( auth_is_user_authenticated() ) { // okay we're logged in - set the globals $USERINFO['pass'] = current_user_get_field( 'password' ); $USERINFO['name'] = current_user_get_field( 'username' ); $USERINFO['mail'] = current_user_get_field( 'email' );   $t_project_name = getNS( getID() ); $t_project_id = project_get_id_by_name( $t_project_name ); $t_access_level = access_get_project_level( $t_project_id ); $t_access_level_string = strtoupper( get_enum_to_string( config_get( 'access_levels_enum_string' ), $t_access_level ) );   $USERINFO['grps'] = array( $t_access_level_string );   $_SERVER['REMOTE_USER'] = $USERINFO['name']; $_SESSION[$conf['title']]['auth']['user'] = $USERINFO['name']; $_SESSION[$conf['title']]['auth']['info'] = $USERINFO;   return true; }   // to be sure auth_logoff();   return false; }   /**
       * Logout from Mantis
       */ function logOff(){ auth_logout(); }   /**
       * Retrieves the user data of the user identified by                                                                                                                                                        
       * username $user. This is used, e.g., by dokuwiki's
       * email notification feature.
       */ function getUserData( $user ) { $userData = false; $mantis_uid = user_get_id_by_name( $user ); if ( $mantis_uid ) { $userData['username'] = user_get_field( $mantis_uid, 'username' ); $userData['mail'] = user_get_field( $mantis_uid, 'email' );   $t_project_name = getNS( getID() ); $t_project_id = project_get_id_by_name( $t_project_name ); $t_access_level = access_get_project_level( $t_project_id , $mantis_uid ); $t_access_level_string = strtoupper( get_enum_to_string( config_get( 'access_levels_enum_string' ), $t_access_level ) );   $userData['grps'] = array( $t_access_level_string ); }   return $userData; } } ?>
  5. 修改權限檔 /var/www/html/dokuwiki/conf/acl.auth.php

    : * @ALL 0 * @VIEWER 1 * @REPORTER 2 * @DEVELOPER 8 * @MANAGER 8 * @ADMINISTRATOR 8
  6. 增加 Mantis Syntax Plug-in /var/www/html/dokuwiki/lib/plugins/mantis/syntax.php

    mkdir /var/www/html/dokuwiki/lib/plugins/mantis
    cd /var/www/html/dokuwiki/lib/plugins/mantis
    vi syntax.php
    <?php /**
     * Mantis Plugin: Hyperlinks references to Mantis Issues
     * 
     * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
     * @author     Victor Boctor (http://www.futureware.biz)
     */  
      if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once(DOKU_PLUGIN.'syntax.php');   /**
     * A plug-in that hyper links references to Mantis issues.  References
     * to Mantis issues should use the following format: ~~Mantis:123~~.
     *
     * All DokuWiki plugins to extend the parser/rendering mechanism
     * need to inherit from this class
     */ class syntax_plugin_mantis extends DokuWiki_Syntax_Plugin {   /**
         * return some info
         */ function getInfo(){ return array( 'author' => 'Victor Boctor', 'email' => 'vboctor at users . sourceforge . net', 'date' => '2006-05-18', 'name' => 'Mantis Issues Plugin', 'desc' => 'Support References to Mantis Issues', 'url' => 'http://www.futureware.biz', ); }   /**
         * What kind of syntax are we?
         */ function getType(){ return 'substition'; # typo is intentional  }   /**
         * What about paragraphs?
         */ function getPType(){ return 'normal'; }   /**
         * Where to sort in?
         */ function getSort(){ return 156; }  
      /**
         * Connect pattern to lexer
         */ function connectTo($mode) { $this->Lexer->addSpecialPattern('~~Mantis:[0-9]+~~', $mode, 'plugin_mantis'); }  
      /**
         * Handle the match
         */ function handle($match, $state, $pos, &$handler){ $match = substr( $match, 9, -2 ); // strip "~~Mantis:" from start and "~~" from end return array( strtolower( $match ) ); }   /**
         * Create output
         */ function render($format, &$renderer, $data) { if ( $format == 'xhtml' ) { $renderer->externallink( MANTIS_URL . 'view.php?id=' . $data[0], $data[0] ); return true; } return false; } } ?>
  7. 透過 dokuwiki 原本設定介面來更動 /var/www/html/dokuwiki/conf/local.php
    1. Use access control lists → 打勾(應該已經打勾)
    2. Authentication backend → mantis(上面的步驟完成才會出現 mantis 選項)
    3. Default group → VIEWER
    4. Superuser → @ADMINISTRATOR
    5. 確認 /var/www/html/dokuwiki/conf/local.php 內應該要出現以下的設定值

      $conf['useacl'] = 1; $conf['authtype'] = 'mantis'; $conf['defaultgroup'] = 'VIEWER'; $conf['superuser'] = '@ADMINISTRATOR';
經過以上的設定,只要在 mantis 內登入, dokuwiki 也會依據 mantis 的身份權限出現在 dokuwiki 系統內

– mantis 部份

  1. Mantis 設定檔啟用 dokuwiki 整合定義 /var/www/html/mantis/config_inc.php

    : : #####################  # Wiki Integration  #####################  # Wiki Integration Enabled?  $g_wiki_enable = ON;   # Wiki Engine  $g_wiki_engine = 'dokuwiki';   # Wiki namespace to be used as root for all pages relating to this mantis installation.  $g_wiki_root_namespace = 'mantis';   # URL under which the wiki engine is hosted.  Must be on the same server.  $g_wiki_engine_url = $t_protocol . '://' . $t_host . '/%wiki_engine%/';
  2. 其餘相關檔案 /var/www/html/mantis/core/wiki_api.php、wiki_dokuwiki_api.php、html_api.php 以及 /var/www/html/mantis/wiki.php 在 1.1.1 版本已經包含在內,不需要自己額外再建立
經過這樣的設定,Mantis 的檢視 Bug 頁面就會出現 wiki 可以直接連結整合的項目