annotate 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
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')
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
26
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
27 def is_allowed(self):
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
28 # 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
29 # as well
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
30 _ = self._
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
31 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
32 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
33 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
34
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
35 def check_condition(self):
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
36 _ = self._
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
37 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
38 # 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
39 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
40 '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
41 '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
42 return note
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
43
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
44 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
45 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
46 else:
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
47 return None
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
48
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
49 def do_action(self):
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
50 """ Delete pagename """
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
51 form = self.form
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
52 comment = form.get('comment', [u''])[0]
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
53 comment = wikiutil.clean_input(comment)
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
54
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
55 if self.request.method != 'POST':
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
56 return False, u''
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
57
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
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
59 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
60
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
61 try:
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
62 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
63 # 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
64 self.request.rev = None
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
65 except PageEditor.RevertError, error:
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
66 msg = unicode(error)
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
67 except PageEditor.Unchanged, error:
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
68 msg = unicode(error)
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 return True, msg
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
71
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
72 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
73 _ = self._
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
74
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
75 d = {
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
76 'pagename': self.pagename,
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
77 '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
78 'buttons_html': buttons_html,
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
79 '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
80 'rev': self.request.rev
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
81 }
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
82
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
83 return '''
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
84 <strong>%(querytext)s</strong>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
85 <table>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
86 <tr>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
87 <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
88 <td class="content">
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
89 <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
90 <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
91 </td>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
92 </tr>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
93 <tr>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
94 <td></td>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
95 <td class="buttons">
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
96 %(buttons_html)s
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
97 </td>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
98 </tr>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
99 </table>
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
100 ''' % d
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
101
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
102
1104
abe498212fb8 move revert code to action/revert.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
103
abe498212fb8 move revert code to action/revert.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
104 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
105 """ Glue code for actions """
2dd4904cfee4 better revert action, make action menu GET again
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3325
diff changeset
106 revert(pagename, request).render()