Dokuwiki主题/模板制作

Dokuwiki主题/模板制作

之前也有写过,不过已经删掉了,因为提到的方法什么的都过时了,很多内容也没说清楚。看评论时发现这方面的东西还是有人需要的,于是决定重新写一遍。对于主题/模板的制作,除了官方文档之外,也可以在符合 Dokuwiki 标准的 starter 模板基础上进行修改,不少不错的模板都是基于它的。和官方文档类似,这里以 Starter 模板为例。

先安装 Starter 模板,并将 lib/tpl/starter 重命名为 lib/tpl/[你的模板名称] (名称应仅包含 a-z 和 0-9),然后在配置管理器里选择这个新模板。

目录结构

Starter 模板的目录下有不少文件,其中必要的有:

  • main.php: 主要的页面布局文件,决定我们一般所看到的页面的布局
  • detail.php: 图片的详细信息页布局
  • mediamanager.php: 媒体管理器/选择器窗口的布局
  • style.ini: 样式控制文件,决定每个样式表应用的情形(屏幕、打印等),并定义一些全站通用的颜色
  • template.info.txt: 模板的信息文件,包括名字、作者的信息等。

页面布局 (HTML+PHP)

页面布局的三个文件中,通常只需要修改 main.php,因为它影响一般所看到的页面的布局。没有特别需求的话,detail.phpmediamanager.php 不必修改,也可以直接复制默认模板的。布局文件是HTML+PHP,可以调用 Dokuwiki 提供的模板函数来显示标题、维基内容等等,也可以调用全局变量。Starter 模板的 main.php 比较复杂,可以先看一个简单的例子

<html>
  <head><title><?php echo $conf['title']?></title></head>
  <body>
    <div class="dokuwiki">
      <?php tpl_content()?>
      <?php tpl_indexerWebBug()?>
    </div>
  </body>
</html>

这会在标题栏显示网站名称,在页面上显示维基的内容。其中 $conf 是一个全局变量,包含 Dokuwiki 的配置信息。而 tpl_content() 是一个模板函数,可以显示带目录的文章内容。另外一个tpl_indexerWebBug()是每个模板都必须有的函数,否则搜索的索引可能无法建立。

模板函数中的 tpl_includeFile() 可以引用模板目录下的其它文件,从而方便用户添加自定义的内容。比如在 main.php 中写

<head>
    <?php tpl_includeFile('meta.html') ?>
</head>

可以将当前目录下的 meta.html 的内容放入。另外,在被引用的文件中也可以使用 PHP 代码。默认模板和 Starter 模板都预先定义了一些钩子,参见 Include Hooks

页面样式 (CSS)

对于模板的样式,Dokuwiki 会先读取 style.ini 文件 (参考 devel:style.ini)。这个文件决定需要哪些 CSS/LESS 文件以及每个文件应该用于何种情形(屏幕,打印等),同时对全站通用的颜色占位符进行定义。比如

[stylesheets]
css/basic.css  = screen
css/design.less = screen
css/print.css  = print   [replacements]
__text__ = "#333" ; @ini_text

这表示 css/basic.csscss/design.less 将应用于屏幕显示,而 css/print.css 用于打印,同时定义了__text__占位符代表的颜色。之后只需编辑相应的 CSS/LESS 文件就可以了。在 CSS 中使用颜色占位符的示例如下

body {
    color: __text__;   
}

如果是 LESS 则是

body {
    color: @ini_text;
}

Dokuwiki主题:Vector

用作Wiki和笔记的话,强烈推荐使用。不仅仅是因为它模仿了Mediawiki,更主要的是它的自定义能力,不但强大而且简单。而且很多自定义的内容作者已经提供好了,你只需Copy and Paste就行了。

官方说明请走:http://www.dokuwiki.org/template:vector

基本设置

“管理”——“配置设置”——“Vector模板设置”里有基本的设置选项。多数情况下,你只需要在这里进行修改。

定制

你可以添加自己的LOGO、CSS样式、侧栏、标签页等。所有修改都应在lib/tpl/vector/user目录下进行。

  • 自定义LOGO:将图片命名为logo,扩展名可以是png、gif、jpg。然后放入user目录下。
  • 自定义favicon:将图片命名为favicon.ico,放入user目录。
  • 自定义CSS:要改变页面的显示样式,编辑user目录下的screen.css文件。要改变打印样式,编辑print.css
  • 自定义JavaScript:编辑user目录下的user.js文件。需要在配置设置里激活——载入“vector/user /user.js“?
  • 自定义标签页:标签页就是上面那一排“文章”、“讨论”之类的,可以添加自己的。在user目录的tabs.php里编辑,里面有例子可以参考。
  • 自定义底部按钮:在user目录下的buttons.php中,有例子。
  • 自定义侧栏内容:可以添加自己的区块,在user目录下的boxes.php中,有例子。

一些示例

增大侧栏宽度,并居中LOGO。比如增大到16em宽:

  div#footer {
      margin-left:16em;
  }
  #head-base{
      margin-left:16em;
  }
  #left-navigation{
      left:16em;   }
  div#content  {
      margin-left:16em;
  }
  div#panel {   width:16em;
  }
  #p-logo{
      width:16em;
  } 
  #p-logo a{
      width:16em;
  }

为侧栏的无序列表添加缩进:

  div#panel div.portal ul {
      margin-top: 0.5em !important;
      margin-left: 0.8em !important;
  }
  div#panel div.portal ul ul{
      margin-left: 2em !important;
  }

为侧栏的导航列表添加列表样式。默认为无,这里添加square样式,类似的也可以为其他的添加:

  div#panel ul li {
     overflow: visible !important;
  }
  div#panel #p-navigation ul {
      list-style-type: square !important;
      margin-left:2.0em !important;
  }

<code>标签默认是白色背景,有时和其他元素结合使用时很难看,可以改为透明:

  code{
      background-color:transparent !important;
  }
  • 你好。 我也是装这个模板。
    可是,一选这个模板的时候。整个网站的样式都没了。
    但选择默认的又全好的。在网上查好久了,也没解决掉。

DokuWiki简介及插件推荐

DokuWiki简介及插件推荐

字数476 阅读5348 评论4 喜欢3

DokuWiki简介

一个简洁的Wiki系统,使用PHP+文本数据库,安装配置都比较简单,基本符合「够用就好」原则。唯一感觉不爽的就是媒体管理器,很不顺手。

在以往的工作实践中,常用它来进行公司内部的交流与协作,有效保障了信息的沟通。

官网地址是 http://www.dokuwiki.org,有中文界面,可以在左侧选择。

安装

下载、解压,浏览器访问后提示 「Setup Error」,选择 「 run the installer」继续。

一般来说,如果权限没问题的话,就会进入到 安装工具 页面,右上角可以更改语言为简体中文。

填写名称、超级用户帐号、内容发布许可协议等信息后保存继续即可。

配置

简单说一下管理页:

  • 用户管理器:添加和管理用户
  • ACL管理器:修改用户/组对于页面和命名空间的权限
  • 插件管理器:可以在这里更改插件,支持远程下载安装
  • 配置设置:关于Dokuwiki的设置,如模版、显示等设置项,一些插件安装后的设置项也在这里

模版

也就是常说的 主题,下载后解压到 lib/tpl 目录,然后在 管理 - 配置设置 中进行选择即可。

更多的主题可以在 官网的 Extensions页 找到

插件

插件可以通过 管理 - 插件管理器 进行安装,这里介绍几个个人比较喜欢的:

  • imgpaste:在编辑器直接粘贴就可以插入剪贴板中的图片,可以用来快速上传截图。
  • Note:可以在页面中插入醒目的提示文字,有几种默认图标和样式。

Dokuwiki插件与主题推荐

Dokuwiki插件与主题推荐

只是一个列表和简要的功能介绍,具体使用看相关文档

主题

Vector是模仿Wikipedia/Mediawiki最新样式的主题,自定义比较能力强。另外其实Dokuwiki现在的默认主题非常不错,也很适合写博客。

如果希望自己写,可以参考这里的文档以及Dokuwiki提供的一个初始模板

插件

外观

  • wrap:几乎涵盖大多数外观、排版上的要求。

交互

  • discussion:添加评论功能,需要pagelist插件的支持。
  • disqus: 添加评论功能,使用 DISQUS 的服务。
  • avatar:使用gravatar头像,多用于评论里的头像显示
  • captcha:验证码

标签

  • tag:用标签来组织内容
  • tagentry:在编辑栏下提供所有标签的列表,方便选择
  • cloud:标签云

导航

  • indexmenu:功能强大。但我不喜欢它默认的样式,又懒得去改。
  • indexmenu2:功能也不错,相对indexmenu略微逊色点
  • pagequery:前面两个主要用于生成树状结构的导航,这个完全不一样,非常值得一看。
  • simpleindex: 生成类似内置索引的简单导航,仅适用于顶层命名空间。
  • simplenavi: 生成一个简单的导航。

其他

还有很多看起来非常不错的,例如画图、化学、图片/视频浏览等,不过自己没用过。

以 UTF8 编码命名文件名

建议选择 safe 方式命名文件名。

经测试,以下修改源码以适应 utf-8 命名方式兼容性也不好。

// 修改\inc\pageutils.php中utf8_encodeFN、utf8_decodeFN两个函数   function utf8_encodeFN($file,$safe=true){
    global $conf;
    //if($conf['fnencode'] == 'utf-8') return $file;
  if($conf['fnencode'] == 'utf-8'){
		if(eregi('win', PHP_OS)){
			$file=mb_convert_encoding($file,"CP936","UTF-8");
		}
		return $file;
	}   if($safe && preg_match('#^[a-zA-Z0-9/_\-\.%]+$#',$file)){
        return $file;
    }   if($conf['fnencode'] == 'safe'){
        return SafeFN::encode($file);
    }   $file = urlencode($file);
    $file = str_replace('%2F','/',$file);
    return $file;
}   function utf8_decodeFN($file){
    global $conf;
    //if($conf['fnencode'] == 'utf-8') return $file;
	if($conf['fnencode'] == 'utf-8'){
		if(eregi('win', PHP_OS)){
			$file=mb_convert_encoding($file,"UTF-8","CP936");
		}
		return $file;
	}   if($conf['fnencode'] == 'safe'){
        return SafeFN::decode($file);
    }   return urldecode($file);
}

第一次使用dokuwiki

恭喜你,你的维基现在启动和运行。这里有一些更多的提示,让你开始。

与DokuWiki的享受你的工作,
– 开发商

创建您的第页

您的wiki需要有一个起始页。只要它不存在,这个环节将是红色的主页。

来吧,跟随该链接,创建页面。如果你需要用你总是可以参考的语法页面的语法帮助。

您可能还需要使用一个侧边栏。要创建它,只需编辑边栏页。在该页面一切都将在一个侧面的利润率列中显示。请阅读我们的侧边栏上的常见问题,以了解更多信息。

请注意,并非所有的模板支持侧边栏。

自定义您的Wiki

一旦你舒服的创建和编辑你可能想看看配置设置页面(请务必先登录为超级用户)。

您可能还希望看到什么插件和模板可在DokuWiki.org延长您的DokuWiki安装的功能和外观。

加入社区

DokuWiki的是,通过用户贡献的蓬勃发展一个开源项目。一个好办法留在这是怎么回事知情和使用DokuWiki的是订阅电子报以获得有用的提示。

DokuWiki的用户论坛是与其他用户DokuWiki的接触得到一个很好的方式,是刚刚的许多方法来获得支持的。

当然,我们会很乐意让你加入与DokuWiki的。

tagentry – 编辑框下显示tag列表

tagentry – 编辑框下显示tag列表

tagentry用于在编辑框下面列出所有的tag,并带有复选框。

bug修补:

  • tag列表无法显示。
./action.php.old  2009-09-18 13:32:00.000000000 +0400
+++ ./action.php	2013-05-30 12:29:47.000000000 +0400
@@ -55,7 +55,7 @@
       $pos = $event->data->findElementByAttribute('type','submit');
       if(!$pos) return; // no button -> source view mode
       #echo "DEBUG: <pre>".print_r($event->data,true).'</pre>';
-      if (   !empty($event->data->_hidden['prefix'])
+      if (   empty($event->data->_hidden['prefix'])
           || !empty($event->data->_hidden['suffix'])) return;
       if ($event->data->findElementByType('wikitext')===false) return;
     }elseif(!$event->data['writable']){
@@ -72,7 +72,7 @@
     }
 
     if ($this->getConf('tagsrc') == 'All tags' && $thlp) {
-      $alltags=$this->_gettags($thlp);
+      $alltags=array_map('trim', idx_getIndex('subject', '_w'));
     } else {
       $alltags=$this->_getpages($tagns);
     }
  • 不兼容ACE编辑器。

尚无方案。

Gallery – 列出图片目录插件

Gallery – 列出图片目录插件

语法

{{gallery>namespace}}

{{gallery>namespace:someimage.jpg}}

{{gallery> namespace}} (right aligned)
{{gallery>namespace }} (left aligned)
{{gallery> namespace }} (centered)

{{gallery>http://www.23hq.com/rss/schabloni}}

参数

参数以?开头,用&分割,所有参数的否定在前面加no,比如:cache,nocache

{{gallery>images:vacation?image_*.jpg&80x80&crop&lightbox}}
// 所有
{{gallery>?crop&lightbox}}

<markdown> <table class=“inline”>

<tbody><tr class="row0">
	<th class="col0 leftalign"> Parameter                      </th><th class="col1 leftalign"> Default         </th><th class="col2 leftalign"> Description    </th>
</tr>
<tr class="row1">
	<td class="col0 leftalign"> <code><em>&lt;number&gt;</em>x<em>&lt;number&gt;</em></code>  </td><td class="col1"> <code>120x120</code> </td><td class="col2"> 设置缩略图大小, 除非设定了crop选项,会保持缩略图长宽比.</td>
</tr>
<tr class="row2">
	<td class="col0 leftalign"> <code><em>&lt;number&gt;</em>X<em>&lt;number&gt;</em></code>  </td><td class="col1"> <code>800X600</code> </td><td class="col2"> 设置<code>direct</code>模式下链接到的图片大小,会保持长宽比. 注意是大写 <code>X</code>.</td>
</tr>
<tr class="row3">
	<td class="col0 leftalign"> <code><em>&lt;number&gt;</em></code>               </td><td class="col1 leftalign"> <code>5</code>           </td><td class="col2"> 每行gallery表里可显示的图片数目. 如果指定为0不使用表格,所有缩略图顺序排列 </td>
</tr>
<tr class="row4">
	<td class="col0 leftalign"> <code>=<em>&lt;number&gt;</em></code>              </td><td class="col1 leftalign"> <code>=0</code>          </td><td class="col2"> 限制显示给定数目的图片. <code>0</code>代表所有. </td>
</tr>
<tr class="row5">
	<td class="col0 leftalign"> <code>+<em>&lt;number&gt;</em></code>              </td><td class="col1 leftalign"> <code>+0</code>          </td><td class="col2"> 跳过显示前面的number张图片. 和上面的选项一起很有用.</td>
</tr>
<tr class="row6">
	<td class="col0 leftalign"> <code>~<em>&lt;number&gt;</em></code>              </td><td class="col1 leftalign"> <code>~0</code>          </td><td class="col2"> Add a pagination for the thumbnails displaying the number of given thumbnails per page. <code>0</code> disables pagination. Pagination is added through JavaScript - when no JavaScript is available all thumbnails are displayed </td>
</tr>
<tr class="row7">
	<td class="col0 leftalign"> <code>cache</code>                      </td><td class="col1 leftalign"> enabled         </td><td class="col2"> Usually the output of the created gallery is cached. When the images in your selected namespace change, you have to manually force an update of the gallery page's <a href="http://www.unixtech.org/caching" class="wikilink2" title="caching" rel="nofollow">cache</a>. To disable the cache for the page showing the gallery, set <code>nocache</code> as option. </td>
</tr>
<tr class="row8">
	<td class="col0 leftalign"> <code>crop</code>                       </td><td class="col1 leftalign"> disabled        </td><td class="col2"> 使用给定的缩略图大小,不保持长宽比,裁剪多出部分 </td>
</tr>
<tr class="row9">
	<td class="col0 leftalign"> <code>direct</code>                     </td><td class="col1 leftalign"> disabled        </td><td class="col2"> 缩略图链接到给定大小的图片而不是图片描述页 </td>
</tr>
<tr class="row10">
	<td class="col0 leftalign"> <code>lightbox</code>                   </td><td class="col1 leftalign"> disabled        </td><td class="col2"> Show images in a fancy JavaScript modal browsing window, see below for details. Setting this option automatically implies the <code>direct</code> mode </td>
</tr>
<tr class="row11">
	<td class="col0 leftalign"> <code>reverse</code>                    </td><td class="col1 leftalign"> disabled        </td><td class="col2"> Reverse the order of the displayed images </td>
</tr>
<tr class="row12">
	<td class="col0 leftalign"> <code>recursive</code>                  </td><td class="col1 leftalign"> enabled         </td><td class="col2"> Find images in the given namespace and all sub namespaces </td>
</tr>
<tr class="row13">
	<td class="col0 leftalign"> <code>random</code>                     </td><td class="col1 leftalign"> disabled        </td><td class="col2"> Sort images randomly. You might want to use <code>nocache</code> as well </td>
</tr>
<tr class="row14">
	<td class="col0 leftalign"> <code>modsort</code>                    </td><td class="col1 leftalign"> disabled        </td><td class="col2"> Sort images by file modification date </td>
</tr>
<tr class="row15">
	<td class="col0 leftalign"> <code>datesort</code>                   </td><td class="col1 leftalign"> disabled        </td><td class="col2"> Sort images by EXIF date </td>
</tr>
<tr class="row16">
	<td class="col0 leftalign"> <code>titlesort</code>                  </td><td class="col1 leftalign"> disabled        </td><td class="col2"> Sort images by EXIF title </td>
</tr>
<tr class="row17">
	<td class="col0 leftalign"> <code>showname</code>                   </td><td class="col1 leftalign"> disabled        </td><td class="col2"> Show filename below thumbnails </td>
</tr>
<tr class="row18">
	<td class="col0 leftalign"> <code>showtitle</code>                  </td><td class="col1 leftalign"> disabled        </td><td class="col2"> Show the EXIF tag <code>Headline</code> as title below thumbnails </td>
</tr>
<tr class="row19">
	<td class="col0 leftalign"> anything containing a <code>*</code>    </td><td class="col1"> jpg,gif,png images </td><td class="col2"> This can be used to filter the list of files found in the given namespace. <code>*</code> work as simple wildcard symbol. </td>
</tr>

</tbody></table> </markdown>

关于lightbox

基于https://github.com/splitbrain/prettyphoto/tree/merged,源自PrettyPhoto

dw2pdf – 导出 pdf 插件

dw2pdf插件用于导出一个wiki页面为一个pdf文件。官网https://www.dokuwiki.org/plugin:dw2pdf

安装

  1. 下载并安装插件
  2. 下载mPdf库最新版,替换掉插件自带的
  3. 修改mpdf/config.php,大致44行,将useAdobeCJK改为true: 此时导出中文正常
  4. 修改Dokuwiki主题模版,添加导出按钮
// Dokuwiki template
// Insert:   <form class="button" method="get" action="<?php wl($ID)?>">
    <div class="no">
    <button type="submit" class="button">
    <img src="<?php echo DOKU_BASE?>lib/images/fileicons/pdf.png" alt="PDF Export" />
    </button>
        <input type="hidden" name="do" value="export_pdf" />
        <input type="hidden" name="rev" value="<?php global $REV; echo $REV?>" />
        <input type="hidden" name="id" value="<?php echo $ID?>" />
    </div>
</form>   // in lib/tpl/dokuwiki/main.php
// after   <!-- PAGE ACTIONS -->
<div id="dokuwiki__pagetools">
    <h3 class="a11y"><?php echo $lang['page_tools']; ?></h3>
    <div class="tools">
        <ul>
            <?php
                tpl_action('edit',      1, 'li', 0, '<span>', '</span>');
                tpl_action('revert',    1, 'li', 0, '<span>', '</span>');
                tpl_action('revisions', 1, 'li', 0, '<span>', '</span>');
                tpl_action('backlink',  1, 'li', 0, '<span>', '</span>');
                tpl_action('subscribe', 1, 'li', 0, '<span>', '</span>');
                tpl_action('top',       1, 'li', 0, '<span>', '</span>');
            ?>   // DW2pdf-Icon will be on the floating menu.

模版语法

<TEXT> The following replacement patterns can be used within the header and footer files.

@PAGE@ – current page number in the PDF @PAGES@ – number of all pages in the PDF @TITLE@ – The article’s title @WIKI@ – The wiki’s title @WIKIURL@ – URL to the wiki @DATE@ – time when the PDF was created (might be in the past if cached) @BASE@ – the wiki base directory @TPLBASE@ – the PDF template base directory (use to reference images) Remark about Bookcreator: The page depended replacements are only for citation.html updated for every page. In the headers and footers the ID of the bookmanager page of the Bookcreator is applied.

@ID@ – The article’s pageID @PAGEURL@ – URL to the article @UPDATE@ – Time of the last update of the article @QRCODE@ – QR code image pointing to the original page url </TEXT>

注意事项

  1. include插件兼容性

<TEXT> To work with the include plugin you have to add dw2pdf to its action_plugin_include supportedModes member variable

var $supportedModes = array('xhtml', 'metadata','dw2pdf');

Otherwise you may have problems with caching. </TEXT>