最近在 VPS 上安装了 MediaWiki 作为自己的笔记整理工具,但是编辑器感觉很不友好,而 MarkDown 插件也不能所见即得。试了一下好像 VisualEditor 还不错,于是就开始了我曲折的安装之路。
如果安装之前 VPS 上安装有 SELinux ,最好先关闭掉。因为好像有比较大的兼容问题(我没搞定)。
首先下载 VisualEditor 插件到 extensions 目录下:
1 2 3 4 |
cd extensions git clone https://gerrit.wikimedia.org/r/p/mediawiki/extensions/VisualEditor.git cd VisualEditor git submodule update --init |
然而这远远不够,还要安装插件 parsoid:
ssh 登陆 VPS ,首先检查依赖关系 yum -y install nodejs npm vim-enhanced git ;
接着创建一个新的/opt/parsoid 目录,并使用git命令克隆最新的 Parsoid:
1 2 |
mkdir -p /opt/parsoid git clone https://gerrit.wikimedia.org/r/p/mediawiki/services/parsoid /opt/parsoid |
进入“/opt/parsoid”目录,使用下面的 npm 命令安装 Parsoid 服务:
1 2 |
cd /opt/parsoid npm install |
接下来,通过编辑相应的配置文件来配置Parsoid服务。
将示例配置“localsettings.example.js”复制到“localsettings.js”,然后使用vim编辑该文件。
1 2 |
cp localsettings.example.js localsettings.js vim localsettings.js |
取消三行注释,并且修改其中的网址为 mediawiki 的 api.php 所在网址。输入“ESC”然后“:wq”退出编辑。
将’config.example.yaml’配置复制到’config.yaml’并用vim编辑器进行编辑:
1 2 |
cp config.example.yaml config.yaml vim config.yaml |
更改 uri 和 domain 的值,还有“serverPort”和“serverInterface”。推荐将“serverInterface”的值修改为’0.0.0.0’,这样在任意电脑都可以查看 Parsoid 的当前状态。
接着打开 iptables 防火墙的相关端口:
1 2 |
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 端口 -j ACCEPT service iptables save #保存iptables规则 |
接下来,我们将Parsoid配置为一项服务。 为此,转至“/etc/systemd/system”目录并创建一个名为“parsoid.service”的新服务文件:
1 2 |
cd /etc/systemd/system/ vim parsoid.service |
粘贴下面一段内容并保存:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
[Unit] Description=Mediawiki Parsoid web service on node.js Documentation=http://www.mediawiki.org/wiki/Parsoid Wants=local-fs.target network.target After=local-fs.target network.target [Install] WantedBy=multi-user.target [Service] Type=simple User=root Group=root WorkingDirectory=/opt/parsoid ExecStart=/usr/bin/node /opt/parsoid/bin/server.js KillMode=process Restart=on-success PrivateTmp=true StandardOutput=syslog |
执行以下命令 reload 并 启动服务:
1 2 |
systemctl daemon-reload systemctl start parsoid |
通过 netstat 命令进行检查服务是否启用 netstat -plntu 。
访问 ip:端口,查看是否服务已经启动。

安装为服务,使得 Parsoid 随系统启动:
1 |
systemctl enable parsoid |
这时候编辑 LocalSettings.php 文件,在末尾添加以下内容(其中有三处需要替换):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
wfLoadExtension( 'VisualEditor' ); // Enable by default for everybody $wgDefaultUserOptions['visualeditor-enable'] = 1; // Optional: Set VisualEditor as the default for anonymous users // otherwise they will have to switch to VE // $wgDefaultUserOptions['visualeditor-editor'] = "visualeditor"; // Don't allow users to disable it $wgHiddenPrefs[] = 'visualeditor-enable'; // OPTIONAL: Enable VisualEditor's experimental code features #$wgDefaultUserOptions['visualeditor-enable-experimental'] = 1; $wgVirtualRestConfig['modules']['parsoid'] = array( // URL to the Parsoid instance // Use port 8142 if you use the Debian package 'url' => 'http://uri:8000', // Parsoid "domain", see below (optional) 'domain' => 'domain', // Parsoid "prefix", see below (optional) 'prefix' => 'ip' ); |
此时访问 mediawiki 就可以发现新的编辑器已经可以使用了。
参考: