VisualEditor

整体思路
visualeditor 依赖 parsoid
parsoid依赖:nodejs,npm

一、关于visualeditor

关于visualeditor,
如果是最新稳定版的mediawiki,那需要另外下载低版本的visualeditor
下载链接:https://www.mediawiki.org/wiki/Special:ExtensionDistributor/VisualEditor

Alt text

官方文档说明:
如果是最新的开发版,使用下面的visualeditor
For the General User: If you’re using the latest stable version of MediaWiki you will need to download the VisualEditor-MediaWiki extension from the ExtensionDistributor page.
For the Advanced User:
The following download instructions are for use with the latest nightly build of MediaWiki only.

cd extensions
git clone https://gerrit.wikimedia.org/r/p/mediawiki/extensions/VisualEditor.git
cd VisualEditor
git submodule update --init

1.2.9版本对应的visualeditor:https://extdist.wmflabs.org/dist/extensions/VisualEditor-REL1_29-ef45039.tar.gz

执行如下操作:
解压并复制到mediawiki的扩展目录

tar -xzf VisualEditor-REL1_29-ef45039.tar.gz -C /var/www/html/mediawiki/extensions

二、安装基础包

yum install -y nodejs npm git policycoreutils-python
错误:软件包:1:v8-3.14.5.10-25.el6.x86_64 (epel)
需要:libicui18n.so.42()(64bit)
错误:软件包:1:v8-3.14.5.10-25.el6.x86_64 (epel)
需要:libicuuc.so.42()(64bit)
错误:软件包:1:v8-3.14.5.10-25.el6.x86_64 (epel)
需要:libicudata.so.42()(64bit)
错误:软件包:gyp-0.1-0.6.1010svn.el6.noarch (epel)
需要:python(abi) = 2.6
已安装: python-2.7.5-48.el7.x86_64 (@anaconda)
python(abi) = 2.7
python(abi) = 2.7
可用: python-2.7.5-58.el7.x86_64 (base)
python(abi) = 2.7
python(abi) = 2.7
可用: python34-3.4.5-2.el6.i686 (epel)
python(abi) = 3.4
[root@localhost lib]# ll libicu*
lrwxrwxrwx 1 root root 20 10月 18 03:00 libicudata.so -> libicudata.so.50.1.2
lrwxrwxrwx 1 root root 20 10月 18 03:22 libicudata.so.42 -> libicudata.so.50.1.2
lrwxrwxrwx 1 root root 20 10月 18 03:00 libicudata.so.50 -> libicudata.so.50.1.2
-rwxr-xr-x 1 root root 20789236 11月 20 2015 libicudata.so.50.1.2
lrwxrwxrwx 1 root root 20 10月 18 03:00 libicui18n.so -> libicui18n.so.50.1.2
lrwxrwxrwx 1 root root 20 10月 18 03:20 libicui18n.so.42 -> libicui18n.so.50.1.2
lrwxrwxrwx 1 root root 20 10月 18 03:00 libicui18n.so.50 -> libicui18n.so.50.1.2
-rwxr-xr-x 1 root root 2117552 11月 20 2015 libicui18n.so.50.1.2
lrwxrwxrwx 1 root root 18 10月 18 03:00 libicuio.so -> libicuio.so.50.1.2
lrwxrwxrwx 1 root root 18 10月 18 03:00 libicuio.so.50 -> libicuio.so.50.1.2
-rwxr-xr-x 1 root root 52284 11月 20 2015 libicuio.so.50.1.2
lrwxrwxrwx 1 root root 18 10月 18 03:00 libicule.so -> libicule.so.50.1.2
lrwxrwxrwx 1 root root 18 10月 18 03:00 libicule.so.50 -> libicule.so.50.1.2
-rwxr-xr-x 1 root root 354284 11月 20 2015 libicule.so.50.1.2
lrwxrwxrwx 1 root root 18 10月 18 03:00 libiculx.so -> libiculx.so.50.1.2
lrwxrwxrwx 1 root root 18 10月 18 03:00 libiculx.so.50 -> libiculx.so.50.1.2
-rwxr-xr-x 1 root root 43276 11月 20 2015 libiculx.so.50.1.2
lrwxrwxrwx 1 root root 20 10月 18 03:00 libicutest.so -> libicutest.so.50.1.2
lrwxrwxrwx 1 root root 20 10月 18 03:00 libicutest.so.50 -> libicutest.so.50.1.2
-rwxr-xr-x 1 root root 61116 11月 20 2015 libicutest.so.50.1.2
lrwxrwxrwx 1 root root 18 10月 18 03:00 libicutu.so -> libicutu.so.50.1.2
lrwxrwxrwx 1 root root 18 10月 18 03:00 libicutu.so.50 -> libicutu.so.50.1.2
-rwxr-xr-x 1 root root 165352 11月 20 2015 libicutu.so.50.1.2
lrwxrwxrwx 1 root root 18 10月 18 03:00 libicuuc.so -> libicuuc.so.50.1.2
lrwxrwxrwx 1 root root 18 10月 18 03:22 libicuuc.so.42 -> libicuuc.so.50.1.2
lrwxrwxrwx 1 root root 18 10月 18 03:00 libicuuc.so.50 -> libicuuc.so.50.1.2
-rwxr-xr-x 1 root root 1501856 11月 20 2015 libicuuc.so.50.1.2

软链接到对应的高版本函数库,依然无效

三、安装淘宝镜像:

[root@localhost opt]# npm install -g cnpm --registry=https://registry.npm.taobao.org
npm: relocation error: npm: symbol SSL_set_cert_cb, version libssl.so.10 not defined in file libssl.so.10 with link time reference

尝试关闭证书验证:

npm config set strict-ssl false

问题依旧存在
看到error说明中使用了ssl
尝试安装openssl

yum install openssl

再次运行

Alt text

关于淘宝镜像更多内容,参考官网:https://npm.taobao.org/

四、安装parsoid

1、从Git仓库下载Parsoid最新版本

git clone https://gerrit.wikimedia.org/r/p/mediawiki/services/parsoid

Alt text

2、安装Parsoid使用的Node.js包

cnpm install

3、修改config.yaml配置

复制一份示例配置文档

[root@localhost parsoid]# cp config.example.yaml config.yaml
[root@localhost parsoid]# vim config.yaml

做如下修改

mwApis:
- # This is the only required parameter,
# the URL of you MediaWiki API endpoint.
uri: 'http://192.168.6.195/mediawiki/api.php'
# The "domain" is used for communication with Visual Editor
# and RESTBase. It defaults to the hostname portion of
# the `uri` property above, but you can manually set it
# to an arbitrary string. It must match the "domain" set
# in $wgVirtualRestConfig.
domain: 'localhost' # optional

其中192.168.6.195/mediawiki为本机的mediawiki访问路径

4、启动服务

在parsoi目录下执行如下命令
node bin/server.js
访问测试

Alt text

5、创建服务启动文件以及开机自启动

1、创建环境配置文件

vim /opt/parsoid/parsoid.env

写入如下内容:

PORT=8000
NODE_PATH=/opt/parsoid/node_modules

2、创建parsoid.service服务

vim /usr/lib/systemd/system/parsoid.service

写入如下内容

[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=nobody
Group=nobody
WorkingDirectory=/opt/parsoid
EnvironmentFile=-/opt/parsoid/parsoid.env
ExecStart=/usr/bin/node /opt/parsoid/bin/server.js
KillMode=process
Restart=on-success
PrivateTmp=true
StandardOutput=syslog

3、启动parsoid.service服务

systemctl start parsoid.service

4、设置parsoid.service服务自启动

systemctl enable parsoid.service
[root@localhost parsoid]# vim /usr/lib/systemd/system/parsoid.service
[root@localhost parsoid]# systemctl start parsoid.service
[root@localhost parsoid]# systemctl enable parsoid.service
Created symlink from /etc/systemd/system/multi-user.target.wants/parsoid.service to /usr/lib/systemd/system/parsoid.service.
[root@localhost parsoid]# systemctl status parsoid.service
● parsoid.service - Mediawiki Parsoid web service on node.js
Loaded: loaded (/usr/lib/systemd/system/parsoid.service; enabled; vendor preset: disabled)
Active: active (running) since 三 2017-10-18 04:25:40 CST; 35s ago
Docs: http://www.mediawiki.org/wiki/Parsoid
Main PID: 69775 (node)
CGroup: /system.slice/parsoid.service
├─69775 /usr/bin/node /opt/parsoid/bin/server.js
├─69795 /usr/bin/node /opt/parsoid/node_modules/_service-runner@2.3.0@service-runner/service-runner.js
├─69801 /usr/bin/node /opt/parsoid/node_modules/_service-runner@2.3.0@service-runner/service-runner.js
├─69811 /usr/bin/node /opt/parsoid/node_modules/_service-runner@2.3.0@service-runner/service-runner.js
└─69821 /usr/bin/node /opt/parsoid/node_modules/_service-runner@2.3.0@service-runner/service-runner.js
10月 18 04:25:41 localhost.localdomain node[69775]: {"name":"parsoid","hostname":"localhost.localdomain","pid":69775,"level":30,"leve..."v":0}
10月 18 04:25:42 localhost.localdomain node[69775]: {"name":"lib/index.js","hostname":"localhost.localdomain","pid":69795,"level":30,..."v":0}
10月 18 04:25:42 localhost.localdomain node[69775]: {"name":"lib/index.js","hostname":"localhost.localdomain","pid":69795,"level":30,..."v":0}
10月 18 04:25:43 localhost.localdomain node[69775]: {"name":"lib/index.js","hostname":"localhost.localdomain","pid":69801,"level":30,..."v":0}
10月 18 04:25:43 localhost.localdomain node[69775]: {"name":"lib/index.js","hostname":"localhost.localdomain","pid":69801,"level":30,..."v":0}
10月 18 04:25:44 localhost.localdomain node[69775]: {"name":"lib/index.js","hostname":"localhost.localdomain","pid":69811,"level":30,..."v":0}
10月 18 04:25:44 localhost.localdomain node[69775]: {"name":"lib/index.js","hostname":"localhost.localdomain","pid":69811,"level":30,..."v":0}
10月 18 04:25:46 localhost.localdomain node[69775]: {"name":"lib/index.js","hostname":"localhost.localdomain","pid":69821,"level":30,..."v":0}
10月 18 04:25:46 localhost.localdomain node[69775]: {"name":"lib/index.js","hostname":"localhost.localdomain","pid":69821,"level":30,..."v":0}
10月 18 04:25:46 localhost.localdomain node[69775]: {"name":"parsoid","hostname":"localhost.localdomain","pid":69775,"level":40,"leve..."v":0}
Hint: Some lines were ellipsized, use -l to show in full.

五、安装Visualeditor

1、下载

[root@localhost ~]# cd /var/www/html/mediawiki/extensions/

2、修改LocalSettings.php配置

以下是官方文档说明:

Basic configuration for MediaWiki-VisualEditor[编辑]
By default, MediaWiki-VisualEditor does not enable itself for users. To make it available, add the following lines to your wiki’s LocalSettings.php after you have downloaded the extension:

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;

Note that you can do this before you have installed the Parsoid node.js service to experiment with VE; this will mean that you can try the editor out in ‘create’ mode on your own wiki, but you will not be able to save or edit existing pages.

Other extensions which load plugins for VE (e.g. Math) can be loaded before or after VE if you are using MediaWiki 1.25 or later; the plugins should work either way.

Enabling other Namespaces[编辑]
Per default, the VisualEditor only works with Namespace 0 (NS_MAIN), i.e. the main article namespace. To change this, adapt the following example that enables namespaces 0 (main), 2 (user) and 102 (some user specific one)

$wgVisualEditorAvailableNamespaces = [
NS_MAIN => true,
NS_USER => true,
102 => true,
“_merge_strategy” => “array_plus”
];
An easy way to figure out numbers of your namespaces is to look at the source code of the pulldown menu of Special:AllPages

Linking with Parsoid[编辑]
To get VisualEditor to talk to Parsoid, add the following code to your LocalSettings.php to specify your Parsoid instance:

$wgVirtualRestConfig[‘modules’][‘parsoid’] = array(
// URL to the Parsoid instance
// Use port 8142 if you use the Debian package
‘url’ => ‘http://localhost:8000‘,
// Parsoid “domain”, see below (optional)
‘domain’ => ‘localhost’,
// Parsoid “prefix”, see below (optional)
‘prefix’ => ‘localhost’
);
A single Parsoid server can handle multiple wikis. The Parsoid domain setting identifies your wiki configuration to Parsoid. Whether you set domain explicitly or optionally accept the default value, the value from wgCanonicalServer, but you can pick an arbitrary string. Older versions of Parsoid also used a unique “prefix” to identify the server; you may need to list that here as well.

Parsoid must have been configured to match, for example with the following in Parsoid’s config.yaml:

mwApis:
- # This is the only required parameter,
# the URL of you MediaWiki API endpoint.
uri: 'http://path/to/my/wiki/api.php'
domain: 'localhost'

If you are using Parsoid older than 0.6.0, you would use a line in Parsoid’s localsettings.js like:

parsoidConfig.setMwApi({ uri: ‘http://path/to/my/wiki/api.php‘, domain: ‘localhost’, prefix: ‘localhost’ });
Again, the “domain” property is optional in the Parsoid configuration; it defaults to the hostname used in the uri property if not specified. The “prefix” property can also be omitted unless you are running a very old version of Parsoid.

See Parsoid/Setup#Configuration for more details.

更多内容,参考:https://www.mediawiki.org/wiki/Extension:VisualEditor

如上所述,在LocalSettings.php中加入以下内容

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;

3、测试

Alt text

Alt text

至此,Visualeditor安装完毕