Wikisophia, entombed

It turns out that creating a static version of a MediaWiki instance is non-trivial; who knew? This is due, in part, to ResourceLoader and other performance-hacks.

There is nothing a little recursive wget can’t fix, of course; but the problem is that naïve wget produces files of the form:

load.php?modules=jquery.client&version=20150104T015506Z&*

which Apache will never match, since they look like a base-file plus query-string.

One clever mechanism for dealing with pseudo-query-string filenames is to rewrite the query-delimiter as %3F:1

RewriteCond %{QUERY_STRING} !=""
RewriteRule ^(.*)$ $1\%3f%{QUERY_STRING} [L]

Since the underlying files appear to lack extensions, however, Apache will serve them as e.g. text/html;2 which browers refuse to interpret as, say, CSS and JavaScript.

We can employ a little rewrite- and mod_header-trickery to serve them with appropriate MIME-types:

RewriteCond %{QUERY_STRING} only=styles
RewriteRule ^load.php - [QSA,E=content_type:text/css]

RewriteCond %{QUERY_STRING} only=scripts
RewriteRule ^load.php - [QSA,E=content_type:text/javascript]

RewriteCond %{QUERY_STRING} modules=jquery
RewriteRule ^load.php - [QSA,E=content_type:text/javascript]

<FilesMatch "load\.php">
        Header set Content-type %{content_type}e
</FilesMatch>

Voilà! A static MediaWiki instance with a little breakage here and there; but, in the main, functional.

Motivation

The motivation for this was that Wikisophia used to be a showcase for WikiTeX and mod_tex; it never fully recovered, however, from the great server meltdown of 2012.

Since the code, furthermore, suffered from complexity and bitrot; it seemed like a good idea to get it working one last time and take a snapshot for posterity.

Footnotes:

1

I also took the extra step of URL-decoding the filenames; but I wonder if this couldn’t have been solved by using noescape.

2

Or whatever the DefaultType happens to be