[Moin-user] Re: getting notified when a page has been updated?

Fredrik Lundh fredrik at pythonware.com
Sun Jan 29 11:11:01 EST 2006

Nir Soffer wrote:

> The easiest way will be to abuse a SecurityPolicy class. It is notified
> about each read or write action, and return True or False, but it can
> also do anything you like :-)
> To get the page html, I think you want to use something like this your
> SecurityPolicy, when the user is allowed to edit:
> # Invalidate the page cache
> import caching
> caching.CacheEntry(request, page, page.getFormatterName()).remove()
> # Render the page
> # You may need to hack the current user while rendering, because users
> get
> # different content according to their language, preferences and
> permissions.
> html = request.redirectedOutput(page.send_page, request, count_hit=0)
> # write the html here...
> return True
> >
> > any pointers to documentation or existing plugins that do this
> Check util/antispam and search MoinMoin wiki for SecurityPolicy

here's what I came up with:

# wikiconfig.py

from MoinMoin.multiconfig import DefaultConfig
from MoinMoin.security import Permissions
from MoinMoin.caching import CacheEntry

class Config(DefaultConfig):

    ... standard config stuff goes here ...

    class SecurityPolicy(Permissions):
        def save(self, page, newtext, rev, **kw):
            request = page.request
            CacheEntry(request, page, page.getFormatterName()).remove()
            html = request.redirectedOutput(
                page.send_page, request, count_hit=0, content_only=1
            # ... save html.encode("utf-8") to page.page_name + ".moin"
            return True

if nobody finds any serious problems with this, I'll post it to the wiki.

thanks! /F

PS. btw, is there any easy way to add a warning message to the wiki page if
the HTML save fails?  I can do "raise page.SaveError(msg)" if things go wrong,
but I don't really want to lose the wiki changes in this case.

More information about the Moin-user mailing list