Using MediaWiki for my personal website
I first started using MediaWiki as my website platform in 2007, after a bit of platform hopping I launched CaveLab October 2019 — again using MediaWiki. So why do I choose to use MediaWiki, instead of (insert platform here)? Well, for both personal and technical reasons:
- Having used the wiki syntax for a few years, I'm quite comfortable with it.
- It was easy to migrate all the content from 2007 to this site.
- Image handling is awesome, images can be bulk uploaded though the API and Mediawiki creates all image sizes needed, and keeps track of where I have used the different images.
- It's very easy to link internally, and MediaWiki keeps track of what links where.
- Moving and renaming pages is easy, MediaWiki makes redirects and fixes them if they end up double (one redirect points to another redirect).
- Full revision history meaning I don't loose anything, and I can go back and look at old revisions of pages.
- I like to start pages simple, and expand them later on. This allows me to quickly publish information about ongoing projects.
- Templates!
After trying several times — I've found that I am great at writing draft blog posts, but terrible at publishing them. This left me with an ever growing pile of drafts, and very few published posts. With the Wiki structure, I start with a simple page and build upon that. And a simple page is always better than no page.
Hosting
MediaWiki is a PHP web application and needs a web server and database — pretty basic stuff. But it can be quite heavy, so to get good performance I've placed it behind a Varnish cache and use a CDN for static files. I'm running it on a Hetzner VPS. I've written about the web stack on the about page.
I've also performed some load testing, and the site performs quite well. You never know when a "Reddit kiss of death" may happen.
Editing
I'm pretty comfortable with the wiki syntax, but I have also enabled the visual editor. Getting Parsoid installed and configured was a lot easier than I anticipated — there is a APT package for it. Now that I have it enabled, I find that I don't really use it. I have enabled CharInsert extension to make inserting tags and blocks faster, here is my Edittools definition used by CharInsert.
Images
Bulk upload
I currently have 2,193 files, most of which are images. I needed an easy way to bulk upload and create galleries. To accomplish this I use Pywikibot, GThumb and some custom scripts.
I have a custom command configured in gThumb:
echo %F >> ~/gthumb.files && echo File:%B >> ~/gthumb.gallery
This prints the full path of the selected images to ~/gthumb.files
, and gallery entries in wiki syntax for the selected images to ~/gthumb.gallery
.
Then I have a script that uploads each image in ~/gthumb.files
to the wiki using Pywikibot, and copies the gallery syntax to the clipboard:
#!/bin/bash
set -e
echo "Input image upload description"
read img_desc
while read p; do
cd ~/dev/pywikibot/core_stable/
echo $p
exiftool -gps:all= $p
pipenv run python3 pwb.py upload -keep -noverify $p "$img_desc" < /dev/tty
done <gthumb.files
cd ~
cat gthumb.gallery | xclip -i -sel clipboard
rm gthumb.files
rm gthumb.gallery
So this is my workflow for bulk uploading images:
- Select images in gThumb and run my custom command
- Execute the upload script for Pywikibot and enter an image description (will be used on all images)
- Paste gallery entries in a gallery wiki syntax block
WebP support
Custom requirements
I had a few custom requirements that MediaWiki didn't support out-of-the-box:
- DNS prefetch and pre-connect in the html head.
- Analytics scripts from https://plausible.io/
- Embedded HTML video elements
- Rendering part list tables from json files (from my logistics system)
To accommodate this, I made a custom extension: https://github.com/thomasjsn/StdoutParserFunctions