Attachment 'ApprovePage.py'
Download 1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - ApprovePage action
4
5 This action allows you to delete a page.
6
7 @copyright: 2005 by Robert Penz <robert.penz@outertech.com>
8 @license: GNU GPL, see COPYING for details.
9 """
10
11 import os
12 from MoinMoin import config, wikiutil
13 from MoinMoin.PageEditor import PageEditor
14
15
16 def execute(pagename, request):
17 _ = request.getText
18 actname = __name__.split('.')[-1]
19 # Create a page editor that does not do edior backups, becuase
20 # approve generate "approved" version, of the page.
21 page = PageEditor(request, pagename, do_editor_backup=0)
22
23 # be extra paranoid in dangerous actions
24 if actname in request.cfg.actions_excluded \
25 or not request.user.may.approve(pagename):
26 return page.send_page(request,
27 msg = _('You are not allowed to approve this page.'))
28
29 # check whether page exists at all
30 if not page.exists():
31 return page.send_page(request,
32 msg = _('This page is already deleted or was never created!'))
33
34 # check whether the user clicked the approve button
35 if request.form.has_key('button') and request.form.has_key('ticket') and request.form.has_key('revision'):
36 # check whether this is a valid approve request (make outside
37 # attacks harder by requiring two full HTTP transactions)
38 if not wikiutil.checkTicket(request.form['ticket'][0]):
39 return page.send_page(request,
40 msg = _('Please use the interactive user interface to approve pages!'))
41
42 # check if the revision changed
43 if int(request.form['revision'][0]) != page.getRevList()[0]:
44 return page.send_page(request,
45 msg = _('The pages has changed, cannot simply approve the new revision!'))
46
47 # Approve the page
48 # in the first colum is the revision and in the second the username
49 open(os.path.abspath(os.path.join(request.page.getPagePath(), "approved")),"a").write("%08d\t%s\n" % (page.getRevList()[0], request.user.name))
50
51 return page.send_page(request,
52 msg = _('Page "%s" has been successfully approved!') % (pagename,))
53
54 # send approval form
55 ticket = wikiutil.createTicket()
56 querytext = _('Really approve this page?')
57 button = _('Approve')
58 revision = page.getRevList()[0]
59 #comment_label = _("Optional reason for the deletion")
60
61 # TODO: this form suck, redesign like RenamePage
62 formhtml = '''
63 <form method="post" action="">
64 <strong>%(querytext)s</strong>
65 <input type="hidden" name="action" value="%(actname)s">
66 <input type="hidden" name="ticket" value="%(ticket)s">
67 <input type="hidden" name="revision" value="%(revision)s">
68 <input type="submit" name="button" value="%(button)s">
69 <p>
70 </form>''' % {
71 'querytext': querytext,
72 'actname': actname,
73 'ticket': ticket,
74 'button': button,
75 'revision': revision
76 }
77
78 return page.send_page(request, msg=formhtml)
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.