I don't have access to database1 and Dotclear2 has no API for managing comments, I looked around what's there for interfacing to web applications.

Firstly WWW::Mechanize. You need to script whole process including any asynchronous calls, and it uses regexes to extract stuff from the page. Yuck, I gave up.

Then there is Greasemonkey for Firefox, On one hand, it's tied to browser so you can't just do it unattended from cron. On other hand, you have access to the form no matter what dynamic javascript atrocities are required to render it, and you can reuse its own code to fetch all that is needed, tick the boxes and submit. Actually... not so fast! G-m runs user scripts not as normal webpage javascript, but from its sandbox3, so you can't just copy code between the console and g-m script and expect it to always work the same way. For example Dotclear uses "ancient" jQuery 1.2 for which API documentation is not available anymore. But even if you wanted to, no you can't call it from g-m code because safety, not even using "unsafeWindow" hack. You have to preload your own jQuery into the sandbox and use that, keeping the difference between sandbox and actual document in mind when debugging.

Oh, and the debugging. Looks like it is not much a priority. Just sprinkle log statement about. But actually, your precious log statements and errors may be eaten completely...

I eventually got it working together, but together with my recent interfacings with yet more byzantine system I have to wonder. How we ended up in this sad place? If someone tried to create a programming language to prevent access from outside code at runtime, they would not be able to outdo C++. And this Firefox problem shows it isn't just about C++. Mozilla was supposed to be XUL-scriptable since long time ago, but in reality customizing web application isn't much easier than to customize C++ ones. By now, one would expect plenty of user-side customizations, but this never happened, not even with CSS. Users instead pester web administrators for whatever tiny adjustments they need, even if they are programmers themselves.


[1] As proper netizen I should prolly host it myself, but.. why. It does what I need and as a free service with domain registration I consider it decent bang for the buck.

[2] The engine this blog runs on, hosted by Gandi.

[3] Not optional. I found it ridiculous what hoops you must jump through just to paste something into g-m code editor the first time.