annotate MoinMoin/action/revert.py @ 3366:80ecec6e008b

action.revert: keep revert action in log
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Thu, 20 Mar 2008 21:14:58 +0100
parents bb04265ce89a
children 48acb9e0a097
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1104
abe498212fb8 move revert code to action/revert.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
abe498212fb8 move revert code to action/revert.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
2 """
abe498212fb8 move revert code to action/revert.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
3 MoinMoin - revert a page to a previous revision
abe498212fb8 move revert code to action/revert.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
4
1918
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1881
diff changeset
5 @copyright: 2000-2004 Juergen Hermann <jh@web.de>,
3356
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
6 2006 MoinMoin:ThomasWaldmann,
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
7 2007 MoinMoin:ReimarBauer,
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
8 2008 MoinMoin:JohannesBerg
1104
abe498212fb8 move revert code to action/revert.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
9 @license: GNU GPL, see COPYING for details.
abe498212fb8 move revert code to action/revert.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
10 """
3356
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
11 from MoinMoin import wikiutil
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
12 from MoinMoin.PageEditor import PageEditor
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
13 from MoinMoin.action import ActionBase
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
14
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
15 class revert(ActionBase):
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
16 """ revert page action
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
17
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
18 Note: the action name is the class name
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
19 """
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
20 def __init__(self, pagename, request):
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
21 ActionBase.__init__(self, pagename, request)
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
22 self.use_ticket = True
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
23 _ = self._
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
24 self.form_trigger = 'revert'
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
25 self.form_trigger_label = _('Revert')
3357
bb04265ce89a fix revert action. I suck.
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3356
diff changeset
26 self.method = 'POST'
3356
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
27
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
28 def is_allowed(self):
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
29 # this is not strictly necessary because the underlying storage code checks
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
30 # as well
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
31 _ = self._
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
32 may = self.request.user.may
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
33 allowed = may.write(self.pagename) and may.delete(self.pagename)
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
34 return allowed, _('You are not allowed to revert this page!')
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
35
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
36 def check_condition(self):
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
37 _ = self._
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
38 if not self.request.rev:
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
39 # same string as in PageEditor...
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
40 note = _('You were viewing the current revision of this page when you called the revert action. '
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
41 'If you want to revert to an older revision, first view that older revision and '
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
42 'then call revert to this (older) revision again.')
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
43 return note
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
44
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
45 if not self.page.exists():
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
46 return _('This page is already deleted or was never created!')
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
47 else:
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
48 return None
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
49
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
50 def do_action(self):
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
51 """ Delete pagename """
3366
80ecec6e008b action.revert: keep revert action in log
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3357
diff changeset
52 _ = self._
3356
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
53
3357
bb04265ce89a fix revert action. I suck.
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3356
diff changeset
54 if self.request.request_method != 'POST':
3356
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
55 return False, u''
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
56
3366
80ecec6e008b action.revert: keep revert action in log
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3357
diff changeset
57 form = self.form
3356
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
58 rev = self.request.rev
3366
80ecec6e008b action.revert: keep revert action in log
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3357
diff changeset
59 comment = form.get('comment', [u''])[0]
80ecec6e008b action.revert: keep revert action in log
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3357
diff changeset
60 system_comment = _(u"Revert to revision %(rev)d.") % {'rev': int(rev)}
80ecec6e008b action.revert: keep revert action in log
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3357
diff changeset
61 if not comment:
80ecec6e008b action.revert: keep revert action in log
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3357
diff changeset
62 comment = system_comment
80ecec6e008b action.revert: keep revert action in log
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3357
diff changeset
63 else:
80ecec6e008b action.revert: keep revert action in log
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3357
diff changeset
64 comment = "%(comment)s (%(system_comment)s)" % {"comment": comment,
80ecec6e008b action.revert: keep revert action in log
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3357
diff changeset
65 "system_comment": system_comment}
80ecec6e008b action.revert: keep revert action in log
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3357
diff changeset
66
80ecec6e008b action.revert: keep revert action in log
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3357
diff changeset
67 comment = wikiutil.clean_input(comment)
3356
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
68 pg = PageEditor(self.request, self.pagename)
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
69
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
70 try:
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
71 msg = pg.revertPage(rev, comment)
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
72 # make it show the current version...
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
73 self.request.rev = None
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
74 except PageEditor.RevertError, error:
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
75 msg = unicode(error)
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
76 except PageEditor.Unchanged, error:
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
77 msg = unicode(error)
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
78
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
79 return True, msg
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
80
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
81 def get_form_html(self, buttons_html):
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
82 _ = self._
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
83
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
84 d = {
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
85 'pagename': self.pagename,
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
86 'comment_label': _("Optional reason for reverting this page"),
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
87 'buttons_html': buttons_html,
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
88 'querytext': _('Really revert this page?'),
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
89 'rev': self.request.rev
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
90 }
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
91
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
92 return '''
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
93 <strong>%(querytext)s</strong>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
94 <table>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
95 <tr>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
96 <td class="label"><label>%(comment_label)s</label></td>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
97 <td class="content">
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
98 <input type="text" name="comment" size="80" maxlength="200">
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
99 <input type="hidden" name="rev" value="%(rev)d">
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
100 </td>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
101 </tr>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
102 <tr>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
103 <td></td>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
104 <td class="buttons">
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
105 %(buttons_html)s
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
106 </td>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
107 </tr>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
108 </table>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
109 ''' % d
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
110
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
111
1104
abe498212fb8 move revert code to action/revert.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
112
abe498212fb8 move revert code to action/revert.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
113 def execute(pagename, request):
3356
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
114 """ Glue code for actions """
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
115 revert(pagename, request).render()