# XiphInfra:Wiki VM

Wiki VM
Maintainer(s) ePirat
Host mf4
IPs 192.168.2.180
Service(s) Wiki

As the name suggest, the Wiki VM runs this MediaWiki instance.

It runs an Apache2 server with PHP module, in front of it is a reverse proxy (nginx) running on Catfish. If you need to add or adjust things like headers and the HTTPS redirect, check the nginx config on Catfish, not the Apache2 config.

The current version of MediaWiki and the installed Modules can be found here.

## Important Modules

These are the most important modules that we have in use:

### Math and Mathoid

The Math module allows us to use equations similar as in LaTeX:

`[itex]E=mc^2[/itex]` will display as ${\displaystyle E=mc^{2}}$

The extension uses Mathoid to render equations, this is how it's configured:

```/* Math */
\$wgUseTeX           = true;
\$wgTexvc            = "\$IP/extensions/Math/math/texvc";
\$wgMathMathMLUrl    = "http://127.0.0.1:10042";
\$wgMathValidModes   = array(MW_MATH_MATHML, MW_MATH_PNG, MW_MATH_SOURCE);

/* Set Mathoid as default rendering option */
\$wgDefaultUserOptions['math'] = MW_MATH_MATHML;
```

Once the Math extension is configure, as mentioned, it needs Mathoid to render MathML and SVGs. It's a bit tricky to install therefore below is a short guide how to do so:

#### Fetch the source code

```cd /opt/
git clone https://github.com/wikimedia/mathoid
```

#### Install a relatively new node.js version

```wget https://nodejs.org/dist/v4.2.4/node-v4.2.4-linux-x64.tar.xz
tar xfv ./node-v4.2.4-linux-x64.tar.xz
mv ./node-v4.2.4-linux-x64.tar.xz /opt/node-v4.2.4
```

```echo export PATH=/opt/node-v4.2.4/bin:\$PATH >> ~/.bashrc
```

#### Install dependencies

Inside the mathoid folder do:

```npm install
```

#### Change config

Remove the default config symlink and crate one for the prod config:

```rm config.yaml
ln -s config.prod.yaml config.yaml
```

Adjust the config accordingly, currently the config looks similar to:

```# Number of worker processes to spawn.
# Set to 0 to run everything in a single process without clustering.
# Use 'ncpu' to run as many workers as there are CPU units
num_workers: ncpu

# Log error messages and gracefully restart a worker if v8 reports that it
# uses more heap (note: not RSS) than this many mb.
worker_heap_limit_mb: 500

# Logger info
logging:
level: warn
streams:
# Use gelf-stream -> logstash
#- type: gelf
#  port: 12201

# Statsd metrics reporter
metrics:
#type: statsd
#port: 8125

services:
- name: mathoid
module: ./app.js
conf:
interface: 127.0.0.1
port: 10042
svg: true
img: false
texvcinfo: true
speech: true
sppechOn: false
```

#### Try it

Let's try to start it:

```npm start
```

If it start successfully, go to a Wiki Page, edit it and add a simple equation and preview the page. (Make sure to use a unique equation, as caching could prevent that Mathoid is used, if the equation already exists.)

If everything works as expected, write a systemd unit or such and start Mathoid with it, for production use.

#### Troubleshooting

Maybe useful for debugging, you can use curl to make a request to Mathoid like this:

```curl -d 'q=E=fobarmc^2' http://127.0.0.1:10042/
```

If you get errors like `spawn java ENOENT` make sure you have set

```img: false
```

in your config, as else it will try to use Apache™ Batik, which requires Java. I guess not having PNGs is a fair tradeoff, if that saves us from having to use java on the VM.

If there are problems while installing dependencies, make sure your nodejs version is recent enough, try to remove the modules and reinstall them:

```rm -rf ./node_modules
npm cache clear
npm install
```

### SyntaxHighlight (GeSHi)

This is used to highlight code blocks:

```<syntaxhighlight lang="php">
\$foo = "bar";
</syntaxhighlight>
```

will display as:

```\$foo = "bar";
```

Luckily, this one is much easier to install. It does not, contrary to what the name suggest, depend on GeSHi anymore, but has switched to Pygments, so make sure that is installed. That's it. (Phew, much easier compared to Mathoid)