User Tools

Site Tools


linux:install_mediawiki_pdf_creator

This is an old revision of the document!


Install Mediawiki PDF Creator

This page shows how to setup the Wiki plugin called 'Collection' that allows creation of PDF books from wiki pages and the setup of the renderer server used to actually render the PDFs.

Prerequisites

You must have a CentOS machine already set up in accordance with the “Install CentOS 6” guide.

A very useful extension to the Wiki is the Collection extension. This gives the ability to create 'books' from wiki pages and export them to PDF. In order to render the pages correctly the extension uses a render server. If the wiki is not discoverable from its location by external sites, it may be necessary to set-up our own internal rendering server. The following guide outlines the steps to install and run the rendering server.

You must have a Mediawiki installation already setup in accordance with the “Install Mediawiki” guide.

Install Packages

The packages “ploticus” and “pdftk” are not available in the normal Centos but are available from rpmforge.

wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
rpm -i rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
rm -f rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
wget http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
rpm --import RPM-GPG-KEY.dag.txt
rm -f RPM-GPG-KEY.dag.txt

The package “python-virtualenv” is not available in the normal Centos but are available from the ELEP repository.

wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpm
rm -f epel-release-6-8.noarch.rpm

Several packages are needed in order for the render server to function correctly, these can be installed using the following command as root

yum install gcc gcc-c++ libevent-devel python python-imaging python-devel python-virtualenv libjpeg make ocaml *libz* *libxslt* *freetype* \
 *lcms* *libz* *texlive-latex* ploticus dvipng ImageMagick pdftk tkinter libjpeg-devel ruby-tcltk *libxml* python-lxml tk*

Install mwlib

Run the following commands as root:

virtualenv --distribute --no-site-packages ~/pp
export PATH=~/pp/bin:$PATH
hash -r
export PIP_INDEX_URL=http://pypi.pediapress.com/simple/
pip install pil
pip install greenlet gevent roman simplejson sqlite3dbm py lxml qserve apipkg pyPdf bottle timelib pyparsing
pip install -i http://pypi.pediapress.com/simple/ mwlib
pip install -i http://pypi.pediapress.com/simple/ mwlib.rl
pip install -i http://pypi.pediapress.com/simple/ pyfribidi

Add Path Variables

We need to add a script to set the path correctly on boot. Run the following as root

echo "PATH=\$PATH:/root/pp/bin" >> /etc/profile
echo "export PATH" >> /etc/profile

=Testing Renderer= On the server you should be able to run the following to build a pdf with two chapters.

mw-zip -c http://mediawiki.example.com/mediawiki/ -o test.zip Install_Linux Install_Java
mw-render -c test.zip -o test.pdf -w rl

To test the mw-zip command with json, use

mw-zip -c http://mediawiki.example.com/mediawiki/ -o test.zip -m metabook.json

Example json is:

{
	"type":"collection",
	"title":"MyTitle",
	"subtitle":"MySubtitle",
	"licenses":
	[
		{
			"type":"license",
			"name":"License",
			"mw_rights_icon":"",
			"mw_rights_page":"",
			"mw_rights_url":"",
			"mw_rights_text":""
		}
	],
	"items":
	[
		{
			"type":"article",
			"content_type":"text\/x-wiki",
			"title":"Install Mediawiki",
			"revision":"24805",
			"latest":"24805",
			"timestamp":"1400760710",
			"url":"http:\/\/mediawiki.example.com\/mediawiki\/index.php\/Install_Mediawiki",
			"currentVersion":1
		},
		{
			"type":"article",
			"content_type":"text\/x-wiki",
			"title":"Install Postgresql",
			"revision":"18554",
			"latest":"18554",
			"timestamp":"1368629961",
			"url":"http:\/\/mediawiki.example.com\/mediawiki\/index.php\/Install_Postgresql",
			"currentVersion":1
		}
	]
}

Download Collection Plugin

You can download the latest version of the Collection plugin [http://www.mediawiki.org/wiki/Special:ExtensionDistributor/Collection here].

Install Collection Plugin

You can find full instructions for installation [http://www.mediawiki.org/wiki/Extension:Collection#Installation here].

Download and copy to /data/www/html/mediawiki/extensions

cd /data/www/html/mediawiki
wget https://codeload.github.com/wikimedia/mediawiki-extensions-Collection/legacy.tar.gz/REL1_22
mv REL1_22 Collections.tar.gz
tar -xzf Collections.tar.gz -C /data/www/html/mediawiki/extensions
rm -f Collections.tar.gz
cd extensions
mv wikimedia-mediawiki-extensions-Collection-* Collection

Add the following to the bottom of the LocalSettings.php for the Wiki (/data/www/html/mediawiki) - Changing the IP address to the IP address of the server.

$wgCollectionMWServeURL = 'localhost:8899/';
$wgCollectionFormats = array( 
    'rl' => 'PDF', 
    'odf' => 'ODT' 
);
require_once("$IP/extensions/Collection/Collection.php");

Fix Collection Plugin

You now have to fix a bug that has been left in the Collection plugin. This is for Collection 1.6.1 on Mediawiki 1.22.6 with PHP 5.3.3.

Firstly, ensure SELinux is disabled. If it is enabled, the curl_exec() call will fail. If you don't want to disable SELinux, try running the following command, it may work

setsebool -P httpd_can_network_connect 1

Secondly, you need to edit $IP/extensions/Collection/Collection.body.php

In the function

static function mwServeCommand( $command, $args ) {

Replace

$serveURL = $wgCollectionMWServeURL;

with

$serveURL = 'mediawiki.example.com:8899/';

and then replace

$response = Http::post($serveURL, array('postData' => $args));

with

		$boundary = '--myboundary-bps';
		$retval= '';
		foreach($args as $key => $value){
		        $retval .= "--$boundary\nContent-Disposition: form-data; name=\"$key\"\n\n$value\n";
		}
		$retval .= "--$boundary--";
		$body = $retval;
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data; boundary=$boundary"));
		curl_setopt($ch, CURLOPT_URL, $serveURL);
		curl_setopt($ch, CURLOPT_POST, true);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
		$response = curl_exec($ch);

Manually Start Render Server

SSH in as root and run the following

iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 8899 -j ACCEPT
service iptables save
service iptables restart
mkdir /var/log/renderer/
nohup nserve > /var/log/renderer/log_nserve 2>&1 &
nohup mw-qserve > /var/log/renderer/log_mw-qserve 2>&1 &
nohup nslave --cachedir /tmp/cache/ > /var/log/renderer/log_nslave 2>&1 &

You should now be able to use the Collection plugin functionality on the Wiki

Setup the Render Server as a Service

Create /etc/init.d/pdfrenderer as root

#!/bin/bash
  - chkconfig: 2345 95 20
  - /etc/rc.d/init.d/pdfrenderer
  - Description: Starts and stops the Collection PDF renderer for creating PDF books in the wiki.
PATH=$PATH:/root/pp/bin
case $1 in
start)
echo -n "Starting nserve: "
nohup /root/pp/bin/nserve > /var/log/renderer/log_nserve 2>&1 &
echo "Done"
echo -n "Starting mw-qserve: "
nohup /root/pp/bin/mw-qserve > /var/log/renderer/log_mw-qserve 2>&1 &
echo "Done"
echo -n "Starting nslave: "
nohup /root/pp/bin/nslave --cachedir /tmp/cache/ > /var/log/renderer/log_nslave 2>&1 &
echo "Done"
;;
stop)
echo -n "Stopping nslave: "
PID_N_SLAVE=`ps -ef | grep nslave | grep -v grep | awk '{print $2}'`
kill -9  $PID_N_SLAVE
echo "Done"

echo -n "Stopping mw-qserve: "
PID_MW_QSERVE=`ps -ef | grep mw-qserve | grep -v grep | awk '{print $2}'`
kill -9  $PID_MW_QSERVE
echo "Done"

echo -n "Stopping nserve: "
PID_NSERVE=`ps -ef | grep nserve | grep -v grep | awk '{print $2}'`
kill -9  $PID_NSERVE
echo "Done"
;;
  *)
echo "Usage: pdfrenderer {start|stop}"
exit 1
esac
exit 0

Install as service

chmod u+x /etc/init.d/pdfrenderer
chkconfig --add pdfrenderer
chkconfig pdfrenderer on

=References=

linux/install_mediawiki_pdf_creator.1590344492.txt.gz · Last modified: (external edit)