DokuWiki 2026-07-14c 常用 CLI 命令与工具详解

DokuWiki 2026-07-14c 命令行手册:bin/ 下 indexer、dwpage、plugin、render、wantedpages、striplangs、gittool 逐条实测回显,taskrunner 定时任务与备份恢复运维组合。

DokuWikiDokuWiki2026/10/22

DokuWiki 2026-07-14c 常用 CLI 命令与工具详解

目标:逐条实测 DokuWiki 2026-07-14c 的 bin/ 命令行脚本(indexer、dwpage、plugin、render、wantedpages、striplangs、gittool)与 lib/exe/taskrunner.php 定时任务入口,覆盖子命令、参数与真实回显,并给出备份恢复等运维命令组合,作为 Nginx/PHP 服务器上 DokuWiki 日常运维的命令手册。

一、环境信息

二、工具概览

DokuWiki 的 CLI 工具由两部分组成:发行包自带的 bin/ 脚本与核心入口 lib/exe/。实测 bin/ 目录清单:

ls /var/www/dokuwiki/bin/

实测回显:

dwpage.php     gittool.php  indexer.php  plugin.php
render.php     striplangs.php  wantedpages.php

工具分工速查表:

工具用途典型场景
bin/indexer.php全量/增量重建全文搜索索引定时任务、搜索缺结果时
bin/dwpage.php页面检出/提交/锁定/元数据读取脚本化批量改页、外部编辑器集成
bin/plugin.php运行插件提供的 CLI(extension/usermanager)命令行装插件、管用户
bin/render.php命令行把 wiki 语法渲染成 XHTML语法调试、静态导出流水线
bin/wantedpages.php列出站内被链接但不存在(待写)的页面内容盘点、补链
bin/striplangs.php删除多余语言包精简发行包、缩减部署体积
bin/gittool.php批量管理 DokuWiki 及插件的 git 仓库从 git 维护插件/模板
lib/exe/taskrunner.php定时任务统一入口(索引/订阅/清理)cron 定时触发

💡 技术拓展:Web 应用的定时任务触发方式不止一种——DokuWiki 默认用「页面请求触发」模式(每次有人访问页面时异步跑 taskrunner,适合无 cron 的虚拟主机);独立服务器推荐「cron 直接触发」模式,可控且不受流量影响。本文采用后者,两种方式见 4.8 节。

三、前置条件

  1. 已完成 DokuWiki 安装(见《Ubuntu 22.04 安装 DokuWiki 2026-07-14c 指南》);
  2. PHP CLI 可用且版本满足 8.2+(php -v 确认);
  3. 在 DokuWiki 根目录执行或用绝对路径调用 php /var/www/dokuwiki/bin/<脚本>;
  4. 脚本以哪个系统用户运行很重要:以 root 运行时产生的数据文件属主是 root,Web 层(www-data)可能写不进去——建议 CLI 操作后统一 chown -R www-data:www-data /var/www/dokuwiki/data,或直接以 www-data 身份执行(sudo -u www-data php bin/...)。

所有 CLI 脚本共享一组通用选项(各脚本 -h 均列出):--no-colors(禁用彩色输出,适合管道/日志)、--loglevel <level>(最小日志级别,默认 info,可选 debug/info/notice/success/warning/error/critical/alert/emergency)。

四、各工具详解

4.1 bin/indexer.php:搜索索引维护

DokuWiki 的全文搜索依赖倒排索引(存于 data/index/),页面变更后索引默认由页面访问异步更新;批量导入或怀疑索引损坏时用本工具手动维护。查看帮助:

php /var/www/dokuwiki/bin/indexer.php -h

实测回显:

USAGE:
   indexer.php <OPTIONS>

   Updates the searchindex by indexing all new or changed pages. When the
   -c option is given the index is cleared first.


OPTIONS:
   -c, --clear           clear the index before updating

   -q, --quiet           DEPRECATED

   -h, --help            Display this help screen and exit immediately.

   --no-colors           Do not use any colors in output. Useful when
                         piping output to other tools or files.

   --loglevel <level>    Minimum level of messages to display. Default is
                         info. Valid levels are: debug, info, notice,
                         success, warning, error, critical, alert,
                         emergency.

增量索引(只索引新增/变更页,实测站点共 5 页):

php /var/www/dokuwiki/bin/indexer.php --no-colors

实测回显(逐页输出索引结果):

Searching pages...
5 pages found.
lab:install-test indexing...
lab:install-test indexed.
playground:playground indexing...
playground:playground indexed.

清空后全量重建(-c 先清索引):

php /var/www/dokuwiki/bin/indexer.php --no-colors -c

实测回显:

Clearing index...
Index cleared.
Searching pages...
5 pages found.

⚠️ 注意:-q(quiet)已被官方标记为 DEPRECATED,静默需求用 --loglevel error 代替。

4.2 bin/dwpage.php:页面检出与提交

面向「外部编辑器 + 脚本」的页面工作流:checkout 检出(自动加编辑锁)→ 本地改文件 → commit 提交(旧版本自动进 attic 归档)。查看帮助:

php /var/www/dokuwiki/bin/dwpage.php -h

实测回显(节选,完整列出四个命令):

USAGE:
   dwpage.php <OPTIONS> <COMMAND> ...

   Utility to help command line Dokuwiki page editing, allow pages to be
   checked out for editing then committed after changes


OPTIONS:
   -f, --force           force obtaining a lock for the page (generally
                         bad idea)

   -u <username>, --user work as this user. defaults to current CLI user
   <username>

   -h, --help            Display this help screen and exit immediately.
   ...

COMMANDS:
   checkout <wikipage> [<workingfile>]
   commit <OPTIONS> <workingfile> <wikipage>
   lock <wikipage>
   unlock <wikipage>
   getmeta <wikipage> [<key>]

实测完整工作流(页面 lab:install-test):

第一步,检出页面到本地文件:

php /var/www/dokuwiki/bin/dwpage.php --no-colors checkout lab:install-test /tmp/test-page.txt
head -3 /tmp/test-page.txt

实测回显:

lab:install-test > /tmp/test-page.txt
====== 安装验证页 ======

本页面由安装实测流程创建。

第二步,本地修改后提交(-m 变更摘要必填,-t 表示次要变更可选):

printf "====== 安装验证页 ======\n\nCLI commit 修改于 2026-10-22T06:41:50Z\n" > /tmp/test-page.txt
php /var/www/dokuwiki/bin/dwpage.php --no-colors commit -m "CLI 编辑测试" /tmp/test-page.txt lab:install-test

实测回显:

/tmp/test-page.txt > lab:install-test

提交后旧版本自动压缩归档到 data/attic/(实测列出,时间戳为修订号):

install-test.1792621862.txt.gz
install-test.1792622510.txt.gz

第三步,用 getmeta 确认修改时间已更新:

php /var/www/dokuwiki/bin/dwpage.php --no-colors getmeta lab:install-test "date modified"

实测回显:

1792622510

不带 key 时输出全部元数据 JSON(实测节选):

{
    "date": {
        "created": 1792621862,
        "modified": 1792621862
    },
    "creator": "Wiki Administrator",
    "user": "admin",
    "last_change": {
        "date": 1792621862,
        "ip": "10.89.78.1",
        "type": "C",
        "id": "lab:install-test",
        "user": "admin",
        "sum": "",
        "extra": "",

编辑锁管理:checkout 自动加锁,异常中断后用 unlock 释放:

php /var/www/dokuwiki/bin/dwpage.php --no-colors lock lab:install-test

实测回显:

lab:install-test locked

锁文件落盘于 data/locks/(实测:lab:install-test.lock 类型的哈希文件名)。释放:

php /var/www/dokuwiki/bin/dwpage.php --no-colors unlock lab:install-test

实测回显:

lab:install-test unlocked

4.3 bin/plugin.php:插件命令行入口

插件可以自带 CLI,本脚本是统一入口。无参数运行列出可用插件 CLI(实测本站有 extension 与 usermanager 两个捆绑插件提供 CLI):

php /var/www/dokuwiki/bin/plugin.php

实测回显(节选):

USAGE:
   plugin.php <OPTIONS> [<plugin>]

   Excecutes Plugin command line tools

ARGUMENTS:
   <plugin>              The plugin CLI you want to run. Leave off to see
                         list


AVAILABLE PLUGINS:
   extension             Allows managing and installing plugins and
                         templates
   usermanager           Manage DokuWiki user accounts

4.3.1 extension:命令行管理插件

查看 extension CLI 帮助:

php /var/www/dokuwiki/bin/plugin.php extension

实测回显(节选):

USAGE:
   extension <OPTIONS> <COMMAND> ...
   Manage plugins and templates for this DokuWiki instance

   Status codes:
      i - installed                    S - security issue
      b - bundled with DokuWiki        E - extension error
      g - installed via git            W - extension warning
      d - disabled                     I - extension info
      u - update available

COMMANDS:
   search <OPTIONS> <query>
   ...

列出已安装扩展(状态码:b=捆绑,d=已禁用,I=信息):

php /var/www/dokuwiki/bin/plugin.php extension list

实测回显(节选):

acl                  b     <bundled>    ACL Manager by Andreas Gohr
authad               bd    <bundled>    Active Directory Auth Plugin by
                                        Andreas Gohr
authldap             bd    <bundled>    LDAP Auth Plugin by Andreas Gohr
authpdo              bI    <bundled>    authpdo plugin by Andreas Gohr
authplain            b     <bundled>    Plain Auth Plugin by Andreas Gohr
config               b     <bundled>    Configuration Manager by
                                        Christopher Smith
extension            b     <bundled>    Extension Manager by Andreas Gohr

从官方扩展库搜索插件(需服务器可连通 www.dokuwiki.org,代理配置见[《DokuWiki 2026-07-14c 配置参数详解》](https://www.quzuo.net/document/okkosskIw0i9)5.10 节):

php /var/www/dokuwiki/bin/plugin.php extension search table

实测回显(节选):

listusergroup              2020-12-21   Listusergroup Plugin by
                                        richig_vienna
exttab3                    2021-03-24   Extended Table Syntax 3 Plugin by
                                        Satoshi Satoshi Sahara
tablelayout                2026-09-24   tablelayout Plugin by Michael
                                        Große

⚠️ 注意:未配置出网连通性时报错(实测原文):无法连接到扩展库。请确定您的服务器可以连接 www.dokuwiki.org 并检查您的代理设置。

4.3.2 usermanager:命令行管理用户

实测添加用户(参数序为 <login> <mail> [<name>] [<groups>] [<password>]):

php /var/www/dokuwiki/bin/plugin.php usermanager add editor editor@example.com "Wiki Editor" user q1w2e3r4

实测回显:

用户添加成功

回读账本确认(bcrypt 哈希自动生成):

tail -1 /var/www/dokuwiki/conf/users.auth.php

实测回显:

editor:$2y$10$v9Buxuzog7QP4BA54TR6q.EPovagIB3XFGN4.sb9mTNM83h8hckei:Wiki Editor:editor@example.com:user

删除用户(成功时静默无输出):

php /var/www/dokuwiki/bin/plugin.php usermanager delete editor

⚠️ 排障实录:实测中误把邮箱当登录名(usermanager add editor@example.com ...)后,执行 delete editor 报 0 个用户删除成功, 1 个用户删除失败。——delete 的参数是登录名而非邮箱,登录名写错了就要用实际登录名(editor@example.com)来删。另一个实测现象:用户较多时 usermanager list 会输出表格宽度警告 Wanted column widths exceed available space,属显示层警告不影响数据。

4.4 bin/render.php:命令行渲染

把 DokuWiki 语法渲染为 XHTML(默认 renderer),用于语法调试或构建静态导出流水线。帮助:

php /var/www/dokuwiki/bin/render.php -h

实测回显(节选):

USAGE:
   render.php <OPTIONS>

   A simple commandline tool to render some DokuWiki syntax with a given
   renderer.

OPTIONS:
   -r <mode>, --renderer The renderer mode to use. Defaults to xhtml
   <mode>

语法内容从 stdin 读入(实测标题、粗体、内链与表格):

printf "====== Hello ======\n\n**bold** and [[start|link]]\n" | php /var/www/dokuwiki/bin/render.php --no-colors

实测回显:


<h1 class="sectionedit1" id="hello">Hello</h1>
<div class="level1">

<p>
<strong>bold</strong> and <a href="/bin/doku.php?id=start" class="wikilink2" title="start" rel="nofollow" data-wiki-id="start">link</a>
</p>

</div>

表格语法实测:

printf "| a | b |\n" | php /var/www/dokuwiki/bin/render.php --no-colors

实测回显:

<div class="table sectionedit1"><table class="inline">
        <tr class="row0">
                <td class="col0"> a </td><td class="col1"> b </td>
        </tr>
</table></div>
<!-- EDIT{&quot;target&quot;:&quot;table&quot;,&quot;name&quot;:&quot;&quot;,&quot;hid&quot;:&quot;table&quot;,&quot;secid&quot;:1,&quot;range&quot;:&quot;1-10&quot;} -->

💡 说明:class="wikilink2" 表示目标页尚不存在(缺失链接),存在则为 wikilink1——可用此特性在 CI 里检测死链。

4.5 bin/wantedpages.php:待写页面盘点

扫描全站,列出「被链接但不存在的页面」:

php /var/www/dokuwiki/bin/wantedpages.php

实测回显(左列=缺失页,右列=引用它的页面):

searching /var/www/dokuwiki/data/pages
sidebar                                  wiki:welcome
some:namespaces                          wiki:syntax
start                                    wiki:welcome
wiki:nonexisting                         wiki:syntax
wiki:pagename                            wiki:syntax

4.6 bin/striplangs.php:语言包瘦身

删除指定语言之外的全部语言包(英文永不删除),用于精简部署体积。帮助:

php /var/www/dokuwiki/bin/striplangs.php -h

实测回显:

USAGE:
   striplangs.php <OPTIONS>

   Remove all languages from the installation, besides the ones specified.
   English language is never removed!


OPTIONS:
   -k <langcodes>,       Comma separated list of languages to keep in
   --keep <langcodes>    addition to English.

   -e, --english-only    Remove all languages except English

   -h, --help            Display this help screen and exit immediately.
   ...

实测(为不破坏运行站点,先复制一份到临时目录执行;生产操作同理应先备份):复制前语言包共 78 个语言目录,执行 --english-only 后仅剩 en:

cp -r /var/www/dokuwiki /tmp/dw-test
ls /tmp/dw-test/inc/lang | wc -l
php /tmp/dw-test/bin/striplangs.php --english-only
ls /tmp/dw-test/inc/lang

实测回显:

78
en

⚠️ 注意:本操作不可逆删除语言文件(含插件的语言包),且站点界面语言会被强制英文;中文站点应使用 -k zh(保留简体中文)而非 --english-only,执行前务必备份或在副本上演练。

4.7 bin/gittool.php:git 仓库辅助

当 DokuWiki 或其插件/模板以 git 方式维护时,批量执行 git 操作。帮助:

php /var/www/dokuwiki/bin/gittool.php -h

实测回显(节选):

USAGE:
   gittool.php <OPTIONS> <COMMAND> ... <command>

   Manage git repositories for DokuWiki and its plugins and templates.

   $> ./bin/gittool.php clone gallery template:ach
   $> ./bin/gittool.php repos
   $> ./bin/gittool.php origin -v

帮助里的示例即用法:clone <插件名> 从官方库克隆安装,repos 列出全部 git 管理的仓库。tarball 部署的站点没有 git 元数据,此工具通常只在 git 方式维护扩展时使用。

4.8 lib/exe/taskrunner.php:定时任务入口

DokuWiki 的后台任务(搜索索引更新、订阅邮件、缓存清理等)统一由 lib/exe/taskrunner.php 驱动。直接以 CLI 执行它默认输出一个 1×1 透明 GIF(实测输出以 GIF89a 开头——这是为浏览器内嵌 <img> 触发设计的返回体):

php /var/www/dokuwiki/lib/exe/taskrunner.php | head -c 8

实测回显:

GIF89a

独立服务器推荐用 cron 定时触发(每 5 分钟一次,HTTP 请求方式复用 Web 层的 PHP 环境与权限):

*/5 * * * * curl -s -o /dev/null http://localhost/lib/exe/taskrunner.php

⚠️ 注意:若已在页面请求异步触发模式下运行良好(默认行为),加 cron 属可选优化;两者并存无冲突,taskrunner 自带互斥。

五、运维命令组合

5.1 全量备份与恢复

DokuWiki 无数据库,备份即打包 conf/ 与 data/(页面/媒体/索引/日志/缓存全在其中):

tar czf /root/dw-backup-conf-data.tgz -C /var/www/dokuwiki conf data

实测回显(备份产物):

-rw-r--r-- 1 root root 118034 Oct 21 22:32 /root/dw-backup-conf-data.tgz

恢复:解包覆盖后修正属主即可(无需重启任何服务):

tar xzf /root/dw-backup-conf-data.tgz -C /var/www/dokuwiki/
chown -R www-data:www-data /var/www/dokuwiki/conf /var/www/dokuwiki/data

5.2 数据目录巡检

日常巡检关注三处:页面总数、attic 归档增长、缓存体积:

find /var/www/dokuwiki/data/pages -name "*.txt" | wc -l
du -sh /var/www/dokuwiki/data/attic /var/www/dokuwiki/data/cache

实测回示(当前测试站点):

5
236K	/var/www/dokuwiki/data/attic
8.0M	/var/www/dokuwiki/data/cache

5.3 索引异常修复组合

搜索结果缺失或明显陈旧时的标准组合拳:

php /var/www/dokuwiki/bin/indexer.php --no-colors -c
php /var/www/dokuwiki/bin/indexer.php --no-colors

实测回显(清空后全量重建,5 页索引完成):

Clearing index...
Index cleared.
Searching pages...
5 pages found.

5.4 缓存清理

页面样式异常或改了模板/CSS 不生效时清空渲染缓存(cache 目录自动重建):

rm -rf /var/www/dokuwiki/data/cache/*

命令本身无回显;验证方式为刷新页面观察样式恢复正常。

六、注意事项

  1. 属主一致性:CLI 以 root 运行产生的 data/ 文件属主是 root,会让 Web 端写不了页面。批量操作后执行 chown -R www-data:www-data /var/www/dokuwiki/data,或统一 sudo -u www-data php bin/...;
  2. --no-colors 优先:输出进管道/日志/CI 时始终带上,避免 ANSI 色码污染日志(indexer/dwpage/plugin 等全部支持);
  3. dwpage commit 的 -m 必填:省略会报错退出,摘要会显示在页面的修订历史里;
  4. striplangs 不可逆:语言文件直接删除,先在副本演练(4.6 节实测方式);
  5. CLI 与 Web 版本一致:升级 DokuWiki 后 bin/ 脚本同步被替换,跨大版本升级后先跑一次 bin/indexer.php -c 重建索引(升级流程见《Ubuntu 22.04 安装 DokuWiki 2026-07-14c 指南》第八章)。

七、常见问题(FAQ)

Q1:php bin/indexer.php 报 PHP 版本或扩展错误? CLI 用的 PHP 与 FPM 不同源时会出现(如 CLI 是 8.1、FPM 是 8.3)。php -v 与 php -m 核对版本与扩展(需要 mbstring/xml/gd),统一到同一 PHP 8.2+ 版本。

Q2:bin/plugin.php usermanager list 输出 Wanted column widths exceed available space? 终端宽度装不下用户表的实际列宽,属显示警告,数据不受影响;需要干净输出时用 usermanager export 类命令或读取 conf/users.auth.php(注意勿改哈希列)。

Q3:dwpage checkout 后页面被锁死,别人编辑不了? checkout 自动加编辑锁,正常流程是 commit 或 unlock 释放;异常中断后执行 bin/dwpage.php unlock <页面> 释放(4.2 节实测)。强制抢锁用 -f,官方注释明确标注 generally bad idea。

Q4:extension search 一直报「无法连接到扩展库」? 出网受限。给 $conf['proxy'] 配置出网代理(配置方法与实测回显见《DokuWiki 2026-07-14c 配置参数详解》5.10 节),或放行服务器到 www.dokuwiki.org:443。

Q5:render.php 直接把参数当内容输出原文本? render.php 只从 stdin 读语法(4.4 节实测),printf "..." | php bin/render.php 才是正确姿势。

Q6:cron 跑 taskrunner 需要认证吗? 不需要,taskrunner 是匿名可触发的任务入口;但请仅向 localhost 触发(示例中的 curl 写法),避免暴露公网。

八、参考链接