comparison MoinMoin/action/revert.py @ 3356:2dd4904cfee4

better revert action, make action menu GET again implements FeatureRequests/CommentsForReverts, because it is two-stage now the action menu can be GET again
author Johannes Berg <johannes AT sipsolutions DOT net>
date Thu, 20 Mar 2008 16:23:15 +0100
parents b5cc2b8dc753
children bb04265ce89a
comparison
equal deleted inserted replaced
3355:19a7a6efaa21 3356:2dd4904cfee4
1 # -*- coding: iso-8859-1 -*- 1 # -*- coding: iso-8859-1 -*-
2 """ 2 """
3 MoinMoin - revert a page to a previous revision 3 MoinMoin - revert a page to a previous revision
4 4
5 @copyright: 2000-2004 Juergen Hermann <jh@web.de>, 5 @copyright: 2000-2004 Juergen Hermann <jh@web.de>,
6 2006 MoinMoin:ThomasWaldmann 6 2006 MoinMoin:ThomasWaldmann,
7 2007 MoinMoin:ReimarBauer,
8 2008 MoinMoin:JohannesBerg
7 @license: GNU GPL, see COPYING for details. 9 @license: GNU GPL, see COPYING for details.
8 """ 10 """
11 from MoinMoin import wikiutil
12 from MoinMoin.PageEditor import PageEditor
13 from MoinMoin.action import ActionBase
14
15 class revert(ActionBase):
16 """ revert page action
17
18 Note: the action name is the class name
19 """
20 def __init__(self, pagename, request):
21 ActionBase.__init__(self, pagename, request)
22 self.use_ticket = True
23 _ = self._
24 self.form_trigger = 'revert'
25 self.form_trigger_label = _('Revert')
26
27 def is_allowed(self):
28 # this is not strictly necessary because the underlying storage code checks
29 # as well
30 _ = self._
31 may = self.request.user.may
32 allowed = may.write(self.pagename) and may.delete(self.pagename)
33 return allowed, _('You are not allowed to revert this page!')
34
35 def check_condition(self):
36 _ = self._
37 if not self.request.rev:
38 # same string as in PageEditor...
39 note = _('You were viewing the current revision of this page when you called the revert action. '
40 'If you want to revert to an older revision, first view that older revision and '
41 'then call revert to this (older) revision again.')
42 return note
43
44 if not self.page.exists():
45 return _('This page is already deleted or was never created!')
46 else:
47 return None
48
49 def do_action(self):
50 """ Delete pagename """
51 form = self.form
52 comment = form.get('comment', [u''])[0]
53 comment = wikiutil.clean_input(comment)
54
55 if self.request.method != 'POST':
56 return False, u''
57
58 rev = self.request.rev
59 pg = PageEditor(self.request, self.pagename)
60
61 try:
62 msg = pg.revertPage(rev, comment)
63 # make it show the current version...
64 self.request.rev = None
65 except PageEditor.RevertError, error:
66 msg = unicode(error)
67 except PageEditor.Unchanged, error:
68 msg = unicode(error)
69
70 return True, msg
71
72 def get_form_html(self, buttons_html):
73 _ = self._
74
75 d = {
76 'pagename': self.pagename,
77 'comment_label': _("Optional reason for reverting this page"),
78 'buttons_html': buttons_html,
79 'querytext': _('Really revert this page?'),
80 'rev': self.request.rev
81 }
82
83 return '''
84 <strong>%(querytext)s</strong>
85 <table>
86 <tr>
87 <td class="label"><label>%(comment_label)s</label></td>
88 <td class="content">
89 <input type="text" name="comment" size="80" maxlength="200">
90 <input type="hidden" name="rev" value="%(rev)d">
91 </td>
92 </tr>
93 <tr>
94 <td></td>
95 <td class="buttons">
96 %(buttons_html)s
97 </td>
98 </tr>
99 </table>
100 ''' % d
101
102
9 103
10 def execute(pagename, request): 104 def execute(pagename, request):
11 """ restore another revision of a page as a new current revision """ 105 """ Glue code for actions """
12 from MoinMoin.PageEditor import PageEditor 106 revert(pagename, request).render()
13
14 if request.request_method != 'POST':
15 return
16
17 rev = request.rev
18 pg = PageEditor(request, pagename)
19
20 try:
21 msg = pg.revertPage(rev)
22 except PageEditor.RevertError, error:
23 msg = unicode(error)
24
25 request.reset()
26 request.theme.add_msg(msg, "dialog")
27 pg.send_page()