JP van Oosten

Creating MoinMoin pages programmatically

May 13, 2010

Recently, I installed a MoinMoin wiki and a mailing list using mlmmj for a group of people, and I wanted to create a restricted page on the wiki with the subscribers of the list.

Since this mailing list is not owned by the user the wiki runs as, the script had to be executed as root. As soon as the subscribers were collected, the effective user id was changed with a simple call to os.seteuid. This also meant I could not create a macro and have the page update from within the wiki itself.

The solution I found was to create a user which was privileged to edit a page with ACLs. The MoinMoin wiki has a page which shows you how to edit pages programmatically, but for some reason I also had to set the valid property of the user to 1 (MoinMoin seems to use valid = 0 by default, not False).

It felt a bit like a hack, but it worked. As a nice bonus, the PageEditor.saveText method throws a PageEditor.Unchanged exception if the page is not changed, so only a new revision is filed when the page contents actually do change.