Parsoid (Deprecated)

From 24PinTech Wiki
Jump to navigation Jump to search

Introduction

Parsoid is the back-end for VisualEditor (VE). Essentially, it takes the HTML contents from VE and parses it into wikitext, which is the syntax that MediaWiki uses to display pages. It runs off of node.js and can be installed as a service from a package through apt-get, but I've only been able to get it to work when using the running developer setup through PM2.

Installation

This part has already been documented on the MediaWiki website. If you want to install it traditionally, click here, but if you'd like to install a developer setup, click here. I basically followed the same process for the developer setup, but I'll still document what was completed.

.

First, you'll want to install node.js and git by running sudo apt-get install nodejs git. Verify that it's been installed by running node --version and then git --version. Next, create and navigate to /etc/mediawiki/ by running sudo mkdir /etc/mediawiki && cd /etc/mediawiki. Once you're ready to pull the contents from the Parsoid git directory, run sudo git clone https://gerrit.wikimedia.org/r/p/mediawiki/services/parsoid and wait for the download to finish. Move into the newly created parsoid directory by running cd parsoid, and then completing the install by running sudo npm install.

Configuration

In order to create and then edit the configuration file, run sudo cp config.example.yaml config.yaml && sudo vim config.yaml. In there, you'll see something that looks like this:

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

Modify the value of the uri to properly point to your wiki's API file, and then the domain to match the domain. Make sure that the uri and domain match, so for instance if you use localhost in the uri, make sure that you use it in the domain as well. Next, you'll want to configure LocalSettings.php for MediaWiki. Navigate to your wiki's root directory and then run sudo vim LocalSettings.php. At the bottom, add the following:

wfLoadExtension("VisualEditor");

$wgDefaultUserOptions["visualeditor-enable"] = 1;
$wgHiddenPrefs[] = "visualeditor-enable";

$wgVirtualRestConfig["modules"]["parsoid"] = array(
     "url" => "http://localhost:8000",
     "domain" => "localhost",
     "prefix" => "localhost"
);

For our wiki's configuration, we replaced localhost with the IP on the eth0 interface. This can be checked by running ifconfig eth0. If you're running a private wiki, add this to the bottom of your configuration as well:

$wgSessionsInObjectCache = true;
$wgVirtualRestConfig["modules"]["parsoid"]["forwardCookies"] = true;

Note: Please be aware that there are security implications by sending cookie headers to Parsoid over HTTP.

PM2

In order to run the developer setup of Parsoid headless and in the background, you'll want to use PM2. You can install it by running sudo npm install pm2 -g. npm (node package manager) should come pre-installed with node.js and is used to install packages for node.js. Once you've installed PM2, navigate to /etc/mediawiki/parsoid and run the command sudo pm2 start npm -- start. This should start an instance of Parsoid in the background, and you can check if it's there by running sudo pm2 list.

Pm2 list.png

.

.

.

.

.

Troubleshooting

Parsoid can be a pain if it isn't working, so here are a few things that you can try if Parsoid is throwing some errors:

HTTP Error 500

This happens when you don't have cURL installed. It can be fixed by running sudo apt-get install php7.2-curl and then sudo systemctl restart php7.2-fpm. If you aren't running PHP 7.2, then change the version number in the packages to accommodate your current configuration.

HTTP Error 406

I'm not sure why this happens, but navigate to /etc/mediawiki/parsoid/lib/config and run sudo vim ParsoidConfig.js and change the following line from true to false:

ParsoidConfig.prototype.strictAcceptCheck = false;

Alternatively, you can add the following to /etc/mediawiki/parsoid/config.yaml above the line that reads mwApis::

strictAcceptCheck: false

Other

If you're getting other errors, try doing the following: