So, the Avarthrel Wiki has been up for a while now, and it’s now running pretty nicely on MoinMoin. (Update, April 2013: Obviously, the wiki has been now migrated to MediaWiki.)
Recently, I started making the system run a bit smoother by tweaking the MoinMoin builtins and customising stuff. I took the Moniker theme, and customised it lightly so that it looks neater and the boxes fit the theme better - the Flattr button that no one clicks is right on the sidebar, for example.
But I also started working on some hacks under the surface.
One of the annoying things about MoinMoin is that there’s no MediaWiki-style templates. That is to say, you can’t have parametric transclusion of stuff out of the box. You usually have to resort to copypasting things.
Unless you whip out your favourite Python editor, that is.
MoinMoin has an extensible syntax, at least. My first task was to create some kind of a macro for page categorisation. 186 lines of Python later, I can say things like
<<AvarthrelIndex(series=Characters(2) | subpages=Personality | problem=needs coherence)>>
And boom, you can have an article sorted by series, state of completion (independently in each article series), and even add a list of subpages and problems. It also adds a design note subpage link. Article headers are now easy to make coherent.
Still, it was 186 lines of Python. Had this been MediaWiki, I would not have to edit any program code at all - just template stuff. I wouldn’t have had to roll my own parameter parsing. I would have been able to edit it in web browser and save it there, now I had to deploy it on server as an administrator.
But developing this wasn’t entirely painful. I just edited code, the macro occasionally failed to work, and it just provided a nice fat error message on the page. It’s important that error handling works.
There is a small problem with macros, though: All of the arguments have to be on the same line, which impedes readability.
So, how do we go out from that, if we really want multi-line parsing of stuff? Let’s target another MoinMoin feature: Parsers. You can write parts of MoinMoin pages in completely different languages and the thing will just spit the same old HTML for you.
I’m implementing infoboxes as a form of parser - basically, the editors can supply infobox information in JSON format, and MoinMoin parses that and emits some HTML tables. We have JSON metadata for the pages! Woohoo! We’re modern and stuff!
I chose JSON because Python 2.7 has a built in JSON parser. You can parse it really easily:
Simple enough, right? We try to parse stuff. If the input is not in fact valid JSON, we handle it by just outputting an informative error message.
What does MoinMoin think of it?
[“<p”, “ class="asset-centered-big"”, “>”, “<img src="/assets/blog/m/mo/moinnothelpful.png" alt=""/>”, “</p>”]
Nope. I tested this dozens of times in Python interpreter. If I feed JSON parser utter rubbish, it throws a
ValueError. I can catch that exception. There is no way the invalid input in JSON should even be a slightest concern to MoinMoin itself - I’m handling this stuff, not the software.
And yet, MoinMoin seems to be concerned about it.
In fact, writing parsers is a nightmare of an experience. It seems that it reduces MoinMoin into a program that can only say “premature end of script headers” to everything. It won’t produce Apache log entries. I enable MoinMoin’s logging, and log file stays empty.
It even does this if my script has runtime error somewhere. It’s really frustrating to feed the script to Python to have it compile the script without errors, then have MoinMoin run into an error which it helpfully labels a “premature end of script headers”.
MoinMoin just doesn’t talk about parser errors.
I really hope I find a less frustrating way to develop parsers, because this is ridiculous. In a pinch, I could try turning this into a macro, but that would make the JSON less user-editable.
Update, 2012-09-15: I figured out how to debug the thing - through assigning CGI environment variables and invoking the CGI program on command line. The thing actually works now. Still, I maintain that debugging parsers could be made wayyyyyy easier. Having actual error messages would be very nice. =)