MediaWiki

From wiki
Revision as of 10:07, 20 March 2016 by Vincent (talk | contribs) (php-curl)


Warning Warning: This page is a work in progress and is not completed. Important informations might be missing or wrong.
Warning Warning: These instructions were only tested on Debian. It will probably work for other Linux distributions, but you might need to adapt the provided instructions.

Install MediaWiki

Warning Warning: Debian packages are currently unmaintained and outdated. This guide will install MediaWiki from source. For your security, don't forget to follow upstream releases and update your installation.

Prerequisite

DNS

This guide assume that you are using a dedicated subdomain for your wiki like https://wiki.example.com. Don't forget to point that domain to your webserver.

Database

You will need a database server store all dynamic data (users, articles…). You can check the MariaDB installation guide.

Nginx

In this guide, we will use Nginx as a web server. Please check the Nginx installation guide.

Get source

# cd /var/www
# curl https://releases.wikimedia.org/mediawiki/1.26/mediawiki-1.26.2.tar.gz | tar xz
# chown -R www-data: mediawiki*

Configure PHP

Edit file /etc/php5/mods-available/local-common.ini and add folder /var/www/mediawiki-1.26.2/ to the open_basedir setting.

Configure Nginx

create certificate

update nginx config

/mw-config

chown root:www-data /etc/mediawiki/LocalSettings.php
chmod 640 /etc/mediawiki/LocalSettings.php

Install Extensions

ParserFunctions

This extension is bundled by default with MediaWiki. You just need to activate it.

Add the line wfLoadExtension( 'ParserFunctions' ); to the file /var/www/mediawiki*/LocalSettings.php

SyntaxHighlight

This extension is bundled by default with MediaWiki. You just need to activate it.

Add the line wfLoadExtension( 'SyntaxHighlight_GeSHi' ); to the file /var/www/mediawiki*/LocalSettings.php

TemplateData

Allows you to describe your templates using structured data for a better experience with the VisualEditor.

https://www.mediawiki.org/wiki/Extension:TemplateData

VisualEditor

Parsoid

The VisualEditor extension require Parsoid to be installed.

Install

The project is still you and instruction might change. See mediawiki instructions.

Configuration
Connect to MediaWiki

Edit configuration in /etc/mediawiki/parsoid/settings.js

parsoidConfig.setMwApi({ uri: 'https://wiki.example.com:443/api.php', prefix: 'localhost', domain: 'wiki.example.com' });


Warning Warning: If you have changed the listening port of your webserver (you are using Sslh), you might need to change the 443 in the line above.

You can check your ports using

# netstat -plnt |grep nginx
tcp        0      0 203.0.113.23:4433          0.0.0.0:*               LISTEN      1462/nginx: worker 
tcp        0      0 203.0.113.23:80            0.0.0.0:*               LISTEN      1462/nginx: worker 
tcp6       0      0 2001:db8:3:47d0::2e:7::443 :::*                    LISTEN      1462/nginx: worker 
tcp6       0      0 2001:db8:3:47d0::2e:7::80  :::*                    LISTEN      1462/nginx: worker

Parsoid seems to pick the IPV4 port. 4433 in this case

Logging

If you have issue with making Parsoid work, you can enable debug logging. Just add the line debug: true, in /etc/mediawiki/parsoid/settings.js

exports.setup = function(parsoidConfig) {
    debug: true,
    ...

Logs are written in /var/log/parsoid/parsoid.log

Restarting

After changing the config, you need to restart Parsoid.

# service parsoid restart

php-curl

VisualEditor require the curl PHP extension

# apt install php5-curl

MobileFrontend

Because a lot of your traffic will come from mobile devices.

  • Download MobileFrontend
  • Extract it in /var/www/mediawiki*/extensions/
  • Add the following to /var/www/mediawiki*/LocalSettings.php
    require_once "$IP/extensions/MobileFrontend/MobileFrontend.php";
    $wgMFAutodetectMobileView = true;
    # disable talk and watch features
    $wgMFPageActions = array( 'edit', 'upload' );
    

For more information, check the extension documentation

Speedup

By default the MediaWiki installation is pretty slow.

Localisation cache

Uncomment the line about $wgCacheDirectory in /var/www/mediawiki*/LocalSettings.php.

## Set $wgCacheDirectory to a writable directory on the web server
## to make your wiki go slightly faster. The directory should not
## be publically accessible from the web.
$wgCacheDirectory = "$IP/cache";

Page cache

# Enable generated page cache
$wgUseFileCache = true;
$wgFileCacheDirectory = "$IP/cache";

Enable CronJob

First create the log file

# touch /var/log/mediawiki-runJobs.log
# chown www-data:adm /var/log/mediawiki-runJobs.log
# chmod 640 /var/log/mediawiki-runJobs.log

Then add the following line in /etc/crontab

0  0    * * *   www-data /usr/bin/php /var/www/mediawiki-1.26.2/maintenance/runJobs.php > /var/log/mediawiki-runJobs.log

Finally you can disable jobs running on user visits in /var/www/mediawiki*/LocalSettings.php

# Jobs are run by the cronjob. No need to run them on use visits
# https://www.mediawiki.org/wiki/Manual:$wgJobRunRate
$wgJobRunRate = 0;

You can check the number of jobs in the queue at https://wiki.example.com/api.php?action=query&meta=siteinfo&siprop=statistics&format=jsonfm

Other Settings

Capital Links

By default, MediaWiki forces the first letter of a page title to be upper case. The advantage of it is that you can omit the first capital in links,

Eg. You have a page named Test. You can link to it like This is a [[test]].

The drawback is that you can't create a page with lower case title.

Change that in /var/www/mediawiki*/LocalSettings.php.

$wgCapitalLinks = false;