How to Install VisualEditor for MediaWiki on CentOS 7

VisualEditor is a rich-text editor for MediaWiki. It's available as an extension and relies on the Parsoid parser service to be up and running for editing MediaWiki pages.

Coming to Parsoid, it is a parser service based on Nodejs. It's being used by many MediaWiki extensions, including VisualEditor, Flow, Content Translation, and other applications.

In this tutorial, I will show you how to step-by-step install and configure VisualEditor for latest MediaWiki version 1.30. It's worth sharing that our MediaWiki is installed under CentOS 7 operating system, and we will add and install Nodejs, Parsoid service, and configure VisualEditor for MediaWiki Editor.

Prerequisites

What we will do

  1. Check the MediaWiki Installation
  2. Install dependencies
  3. Install and configure Parsoid service
  4. Install and configure VisualEditor for MediaWiki
  5. Test the setup

Step 1 - Check MediaWiki installation

In this step, we will check our MediaWiki installation. MediaWiki is installed under the domain name 'http://wiki.hakase-labs.me'. Open the web browser and visit the following MediaWiki URL address, mine is: http://wiki.hakase-labs.me/

You will be redirected to the HTTPS connection, following which you will get to the MediaWiki page with 'Vector' skin similar to the one shown below.

MediaWiki

Next, log in as admin user and try to edit the page. Click on the 'Edit' tab and you will get the default MediaWiki editor as below.

Edit page in MediaWiki

The MediaWiki is up and running without any error.

Step 2 - Install dependencies

To install the Parsoid service and configure VisualEditor, we need some CentOS packages to be installed on the system. Specifically, we will install Nodejs, npm, vim, and git.

Install all packages needed using yum command below.

yum -y install nodejs npm vim-enhanced git

All packages and dependencies have been installed.

Step 3 - Install and configure Parsoid

Parsoid can be installed on a separate MediaWiki server. But for this tutorial, and we will be using only 1 CentOS 7 server for both MediaWiki and Parsoid.

Now, since we're using the CentOS 7 server, we need to install the Parsoid service manually from source because official packages are only available for Ubuntu/Debian based operating systems.

So to start with, create a new '/opt/parsoid' directory and clone the latest parsoid using the git command, as shown below.

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

Install parsoid

Now go to the '/opt/parsoid' directory and install the Parsoid service using the following npm command.

cd /opt/parsoid
npm install

After the installation is complete, you will get the result as below.

parsoid installation result

Next, configure the Parsoid service by editing the corresponding configuration files.

Copy the example configuration 'localsettings.example.js' to 'localsettings.js', and then edit the file using vim.

cp localsettings.example.js localsettings.js
vim localsettings.js

Uncomment the 'parsoidConfig.setMwApi' line and change the 'uri' value with your MediaWiki API URL as below.

exports.setup = function(parsoidConfig) {
        // Do something dynamic with `parsoidConfig` like,
        parsoidConfig.setMwApi({
                uri: 'http://wiki.hakase-labs.me/api.php',
         });
};

Uncomment the 'parsoidConfig.setMwApi' line

That's it. Save and exit.

Now copy the 'config.example.yaml' configuration to 'config.yaml' and edit it with vim editor.

cp config.example.yaml config.yaml
vim config.yaml

On the 'mwApis' line (line number 34), change the 'uri' value with your MediaWiki API URL and the 'domain' value with your own domain name.

 mwApis:
        - # This is the only required parameter,
          # the URL of you MediaWiki API endpoint.
          uri: 'http://wiki.hakase-labs.me/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: 'wiki.hakase-labs.me'
          #optional

Save and exit.

Next, we will configure Parsoid as a service. For this, go to the '/etc/systemd/system' directory and create a new service file dubbed 'parsoid.service'.

cd /etc/systemd/system/
vim parsoid.service

Paste the Parsoid service configuration below.

[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

Save and exit. Then execute the following reload command.

systemctl daemon-reload

Now, start the Parsoid service, and enable it to execute everytime at system boot.

systemctl start parsoid
systemctl enable parsoid

Parsoid should now be running as a service on CentOS 7, using port 8000. You can check it with the netstat command in the following way.

netstat -plntu

And you should get a result similar to the following:

Result of netstat -plntu command

The parsoid installation and configuration has been completed.

Note:

If you have Firewalld running on your server, add the parsoid port 8000 to the firewalld configuration using the following commands.

firewall-cmd --add-port=8000/tcp --permanent
firewall-cmd --reload

Configure the firewall

Step 4 - Install and configure VisualEditor

In this step, we will install and configure VisualEditor extensions for MediaWiki.

Go to the MediaWiki installation directory '/var/www/mediawiki/extensions' and download the latest VisualEditor version using git.

cd /var/www/mediawiki/extensions
git clone https://gerrit.wikimedia.org/r/p/mediawiki/extensions/VisualEditor.git

Now go to the VisualEditor directory, and initialize and update all submodules inside it.

cd VisualEditor/
git submodule update --init

Install VisualEditor

Next, we need to edit the Mediawiki configuration file 'LocalSettings.php' to enable VisualEditor. For this, head to the mediawiki directory and edit the 'LocalSettings.php' file using vim.

cd /var/www/mediawiki
vim LocalSettings.php

Paste configuration below towards the end of the file.

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://wiki.hakase-labs.me:8000',
    // Parsoid "domain", see below (optional)
    'domain' => 'wiki.hakase-labs.me',
    // Parsoid "prefix", see below (optional)
    'prefix' => 'wiki.hakase-labs.me'
);

That's it. Save and exit.

Note:

Please change the URL with your own domain name.

Next, change the ownership permissions for the mediawiki directory to the 'nginx' user and group.

chown -R nginx:nginx /var/www/mediawiki

VisualEditor extensions installation has been completed.

Step 5 - Testing

Open your web browser and visit the following MediaWiki URL, mine is: http://wiki.hakase-labs.me

Now, login as admin.

Open MediaWiki

Once logged in, click the 'Edit' tab to edit the home page. You should get VisualEditor as shown below.

Open the VisualEditor in MediaWiki

The VisualEditor installation and configuration of MediaWiki on CentOS 7 has been completed successfully.

Reference

Share this page:

5 Comment(s)