Mediawiki

From Jon's Wiki
Revision as of 03:20, 20 September 2017 by Johnno (talk | contribs)

Installation

This assumes Ubuntu 14.04 LTS, the new Mediawiki LTS version 1.27 and a passing familiarity with Git. First, some prerequisites:

apt-get install git apache2 libapache2-mod-php5 php5-curl php5-mysql curl

Now clone the core code into the target directory:

git clone http://gerrit.wikimedia.org/r/p/mediawiki/core.git mediawiki

Next, we need to pull in the dependencies with PHP composer. First install composer from the download page, then use it to pull dependencies into MediaWiki:

cd mediawiki
composer install

Managing skins and extensions

MediaWiki has two directories for these: skins and extensions. There are several ways to manage them, listed here with increasing complexity:

  1. manually download the skins and extensions you need from the Mediawiki Skin and Extension Distributor pages and unzip them into the codebase,
  2. manage each skin and extension using a git clone in the appropriate place in the codebase, or
  3. manage the git repositories of all skins and extensions externally, and use git submodule update to fetch the ones you need, and create symbolic links to the directories in the codebase to enable them.

Let's do things the hard way. Clone the extensions and skins root repositories, and set up the git submodules:

git clone https://gerrit.wikimedia.org/r/mediawiki/skins skins-available
cd skins-available
git submodule init
cd .. 
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions extensions-available
cd extensions-available
git submodule init
cd ..

You'll need the Vector skin right off the bat:

cd skins-available
git submodule update --recursive Vector
cd ../mediawiki/skins
ln -s ../../skins-available/Vector

Now when we want an extension, say the Cite extension, we can:

cd extensions-available
git submodule update --recursive Cite
cd ../mediawiki/extensions
ln -s ../../extensions-available/Cite

You should now be able to point Apache or nginx at the mediawiki directory and install it using the browser (you may need to set up a MySQL database and/or user).

Visual Editor

Install Parsoid

Parsoid is a small Node.js REST service that parses between MediaWiki syntax and HTML DOM. Add the apt repository:

apt-key advanced --keyserver keys.gnupg.net --recv-keys 90E9F83F22250DD7
apt-add-repository 'deb https://releases.wikimedia.org/debian jessie-mediawiki main'
apt-get update

Then install and configure Parsoid:

apt-get install parsoid
vi /etc/mediawiki/parsoid/config.yaml  # change URL to point to installed api.php

Example config.yaml looks like:

worker_heartbeat_timeout: 300000
logging:
  level: info
services:
  - module: ../src/lib/index.js
    entrypoint: apiServiceWorker
    conf:
      useSelser: true
      mwApis:
      -
        uri: 'https://your.wiki.nz/w/api.php'
        domain: 'your.wiki.nz'

Install the required MediaWiki extensions

Install Visual Editor and its dependent extension (UniversalLanguageSelector) into the Mediawiki extensions directory:

cd extensions-available
git submodule update --recursive VisualEditor UniversalLanguageSelector
cd ../mediawiki/extensions
ln -s ../../extensions-available/VisualEditor
ln -s ../../extensions-available/UniversalLanguageSelector

Then edit LocalSettings.php and add this at the bottom:

wfLoadExtension('UniversalLanguageSelector');
wfLoadExtension('VisualEditor.php');

# VisualEditor extension configuration
$wgDefaultUserOptions['visualeditor-enable'] = 1;
$wgDefaultUserOptions['visualeditor-editor'] = "visualeditor";
$wgSessionsInObjectCache = true;
$wgVisualEditorAvailableNamespaces = [
  NS_MAIN => true,
  NS_USER => true,
  NS_TEMPLATE => false,
  "_merge_strategy" => "array_plus",
];

# VisualEditor connection to the parsoid service
$wgVirtualRestConfig['modules']['parsoid'] = [
  'url' => 'http://localhost:8142',
  'domain' => 'your.wiki.nz',
  'forwardCookies' => true,
];

Caching

PHP opcache

Like any PHP application, use the opcache. If your PHP version is < 5.5 install php5-xcache, otherwise enable the built-in opcache by adding this in php.ini:

[opcache]
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.use_cwd=1
opcache.validate_timestamps=1
opcache.revalidate_freq=0
opcache.fast_shutdown=0

MediaWiki file cache

Use the file cache, Luke. It's simple but effective. In LocalSettings.php:

$wgUseFileCache = true;
$wgFileCacheDirectory = "/var/cache/mediawiki";
$wgShowIPinHeader = false; 

And create the appropriate cache directory:

sudo mkdir -p /var/cache/mediawiki
sudo chown www-data:www-data /var/cache/mediawiki