view MoinMoin/action/ @ 2330:38f4f0311a98

Attempt to remove situations when unnecessary PageChangedEvent is sent.
author Karol Nowak <>
date Tue, 26 Jun 2007 15:25:15 +0200
parents 23d90aae61b5
children 88c539512520
line wrap: on
line source
# -*- coding: iso-8859-1 -*-
    MoinMoin - revert a page to a previous revision

    @copyright: 2000-2004 Juergen Hermann <>,
                2006 MoinMoin:ThomasWaldmann
    @license: GNU GPL, see COPYING for details.
from MoinMoin.Page import Page

def execute(pagename, request):
    """ restore another revision of a page as a new current revision """
    from MoinMoin.PageEditor import PageEditor
    _ = request.getText
    msg = None
    rev = request.rev
    pg = Page(request, pagename, rev=rev)

    if not request.user.may.revert(pagename):
        msg = _('You are not allowed to revert this page!')
    elif rev is None:
        msg = _('You were viewing the current revision of this page when you called the revert action. '
                'If you want to revert to an older revision, first view that older revision and '
                'then call revert to this (older) revision again.')
        newpg = PageEditor(request, pagename)

        revstr = '%08d' % rev
            msg = newpg.saveText(pg.get_raw_body(), 0, extra=revstr, action="SAVE/REVERT", page_edit=False)
            pg = newpg
        except newpg.SaveError, msg:
            msg = unicode(msg)

        key = request.form.get('key', ['text_html'])[0]

        # Remove cache entry (if exists)
        pg = Page(request, pagename)
        from MoinMoin import caching
        caching.CacheEntry(request, pg, key, scope='item').remove()
        caching.CacheEntry(request, pg, "pagelinks", scope='item').remove()
        # Notify observers
        from import PageRevertedEvent, send_event
        e = PageRevertedEvent(request, pagename, request.rev, revstr)