Attachment 'approvepage2.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     Changes by Oliver Siemoneit 4.12.2006:
  11     * made action 1.5 compatible
  12 """
  13 
  14 import os
  15 from MoinMoin import config, wikiutil
  16 from MoinMoin.PageEditor import PageEditor
  17 
  18 
  19 def execute(pagename, request):
  20     _ = request.getText
  21     actname = __name__.split('.')[-1]
  22     # Create a page editor that does not do edior backups, becuase
  23     # approve generate "approved" version, of the page.
  24     page = PageEditor(request, pagename, do_editor_backup=0)
  25 
  26     # be extra paranoid in dangerous actions
  27     if actname in request.cfg.actions_excluded \
  28             or not request.user.may.approve(pagename):
  29         return page.send_page(request,
  30             msg = _('You are not allowed to approve this page.'))
  31 
  32     # check whether page exists at all
  33     if not page.exists():
  34         return page.send_page(request,
  35             msg = _('This page is already deleted or was never created!'))
  36 
  37     # check whether the user clicked the approve button
  38     if request.form.has_key('button') and request.form.has_key('ticket') and request.form.has_key('revision'):
  39         # check whether this is a valid approve request (make outside
  40         # attacks harder by requiring two full HTTP transactions)
  41         if not wikiutil.checkTicket(request, request.form['ticket'][0]):
  42             return page.send_page(request,
  43                 msg = _('Please use the interactive user interface to approve pages!'))
  44 
  45         # check if the revision changed
  46         if int(request.form['revision'][0]) != page.getRevList()[0]:
  47             return page.send_page(request,
  48                 msg = _('The pages has changed, cannot simply approve the new revision!'))
  49 
  50         # Approve the page
  51         # in the first colum is the revision and in the second the username
  52         open(os.path.abspath(os.path.join(request.page.getPagePath(), "approved")),"a").write("%08d\t%s\n" % (page.getRevList()[0], request.user.name))
  53 
  54         return page.send_page(request,
  55                 msg = _('Page "%s" has been successfully approved!') % (pagename,))
  56 
  57     # send approval form
  58     ticket = wikiutil.createTicket(request)
  59     querytext = _('Really approve this page?')
  60     button = _('Approve')
  61     revision = page.getRevList()[0]
  62     #comment_label = _("Optional reason for the deletion")
  63 
  64     # TODO: this form suck, redesign like RenamePage
  65     formhtml = '''
  66 <form method="post" action="">
  67 <strong>%(querytext)s</strong>
  68 <input type="hidden" name="action" value="%(actname)s">
  69 <input type="hidden" name="ticket" value="%(ticket)s">
  70 <input type="hidden" name="revision" value="%(revision)s">
  71 <input type="submit" name="button" value="%(button)s">
  72 <p>
  73 </form>''' % {
  74     'querytext': querytext,
  75     'actname': actname,
  76     'ticket': ticket,
  77     'button': button,
  78     'revision': revision
  79 }
  80 
  81     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.
  • [get | view] (2010-02-05 17:13:18, 2.6 KB) [[attachment:ApprovePage-191.py]]
  • [get | view] (2005-10-18 14:16:34, 2.8 KB) [[attachment:ApprovePage.py]]
  • [get | view] (2005-11-08 14:48:57, 2.9 KB) [[attachment:ApprovePage.py-20050811]]
  • [get | view] (2005-11-08 14:51:44, 2.9 KB) [[attachment:ApprovePage.py-20050811-2]]
  • [get | view] (2010-11-18 09:43:04, 7.1 KB) [[attachment:Page.diff-v193-18112010]]
  • [get | view] (2010-02-05 17:15:25, 78.1 KB) [[attachment:Page.py]]
  • [get | view] (2010-11-18 09:41:22, 79.2 KB) [[attachment:Page.py-v193-18112010]]
  • [get | view] (2010-02-05 17:15:58, 4.3 KB) [[attachment:Page.py.patch]]
  • [get | view] (2008-02-12 01:09:14, 4.3 KB) [[attachment:PageApproval.diff]]
  • [get | view] (2010-02-05 17:25:50, 21.4 KB) [[attachment:approval-history.png]]
  • [get | view] (2010-11-18 10:19:10, 2.4 KB) [[attachment:approvePage.py-v193-18112010]]
  • [get | view] (2006-12-04 21:40:20, 3.0 KB) [[attachment:approvepage2.py]]
  • [get | view] (2005-10-18 14:17:03, 4.5 KB) [[attachment:modern.py]]
  • [get | view] (2010-11-18 09:42:23, 3.8 KB) [[attachment:modern_iso.diff-v193-18112010]]
  • [get | view] (2005-11-08 14:48:07, 4.6 KB) [[attachment:modern_iso.py]]
  • [get | view] (2010-11-18 09:40:06, 6.2 KB) [[attachment:modern_iso.py-v193-18112010]]
  • [get | view] (2006-12-04 21:40:00, 4.9 KB) [[attachment:modern_iso2.py]]
  • [get | view] (2010-11-18 09:40:39, 15.0 KB) [[attachment:modernized_iso.py-v193-18112010]]
  • [get | view] (2006-12-04 21:40:39, 1.5 KB) [[attachment:page.diff]]
  • [get | view] (2010-11-18 10:10:42, 7.2 KB) [[attachment:rightsidebar_iso.py-v193-18112010]]
  • [get | view] (2010-02-05 17:13:56, 29.0 KB) [[attachment:solenoid_iso-191.py]]
  • [get | view] (2010-02-05 17:15:05, 1.4 KB) [[attachment:solenoid_iso-191.py.patch]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.