changeset 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 19a7a6efaa21
children bb04265ce89a
files MoinMoin/PageEditor.py MoinMoin/action/revert.py MoinMoin/theme/__init__.py
diffstat 3 files changed, 103 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/PageEditor.py	Thu Mar 20 16:20:23 2008 +0100
+++ b/MoinMoin/PageEditor.py	Thu Mar 20 16:23:15 2008 +0100
@@ -668,11 +668,12 @@
         _ = self.request.getText
 
         if not self.request.user.may.revert(self.page_name):
-            raise self.RevertError(_('You are not allowed to revert this page!'))
+            # no real message necessary, cannot happen if
+            # user doesn't try to exploit us
+            raise self.RevertError('not allowed')
         elif revision is None:
-            raise self.RevertError(_('You were viewing the current revision of this page when you called the revert action. '
-                    'If you want to revert to an older revision, first view that older revision and '
-                    'then call revert to this (older) revision again.'))
+            # see above
+            raise self.RevertError('cannot revert to current rev')
         else:
             revstr = '%08d' % revision
             pg = Page(self.request, self.page_name, rev=revision)
--- a/MoinMoin/action/revert.py	Thu Mar 20 16:20:23 2008 +0100
+++ b/MoinMoin/action/revert.py	Thu Mar 20 16:23:15 2008 +0100
@@ -3,25 +3,104 @@
     MoinMoin - revert a page to a previous revision
 
     @copyright: 2000-2004 Juergen Hermann <jh@web.de>,
-                2006 MoinMoin:ThomasWaldmann
+                2006 MoinMoin:ThomasWaldmann,
+                2007 MoinMoin:ReimarBauer,
+                2008 MoinMoin:JohannesBerg
     @license: GNU GPL, see COPYING for details.
 """
+from MoinMoin import wikiutil
+from MoinMoin.PageEditor import PageEditor
+from MoinMoin.action import ActionBase
+
+class revert(ActionBase):
+    """ revert page action
+
+    Note: the action name is the class name
+    """
+    def __init__(self, pagename, request):
+        ActionBase.__init__(self, pagename, request)
+        self.use_ticket = True
+        _ = self._
+        self.form_trigger = 'revert'
+        self.form_trigger_label = _('Revert')
+
+    def is_allowed(self):
+        # this is not strictly necessary because the underlying storage code checks
+        # as well
+        _ = self._
+        may = self.request.user.may
+        allowed = may.write(self.pagename) and may.delete(self.pagename)
+        return allowed, _('You are not allowed to revert this page!')
+
+    def check_condition(self):
+        _ = self._
+        if not self.request.rev:
+            # same string as in PageEditor...
+            note = _('You were viewing the current revision of this page when you called the revert action. '
+                     'If you want to revert to an older revision, first view that older revision and '
+                     'then call revert to this (older) revision again.')
+            return note
+
+        if not self.page.exists():
+            return _('This page is already deleted or was never created!')
+        else:
+            return None
+
+    def do_action(self):
+        """ Delete pagename """
+        form = self.form
+        comment = form.get('comment', [u''])[0]
+        comment = wikiutil.clean_input(comment)
+
+        if self.request.method != 'POST':
+            return False, u''
+
+        rev = self.request.rev
+        pg = PageEditor(self.request, self.pagename)
+
+        try:
+            msg = pg.revertPage(rev, comment)
+            # make it show the current version...
+            self.request.rev = None
+        except PageEditor.RevertError, error:
+            msg = unicode(error)
+        except PageEditor.Unchanged, error:
+            msg = unicode(error)
+
+        return True, msg
+
+    def get_form_html(self, buttons_html):
+        _ = self._
+
+        d = {
+            'pagename': self.pagename,
+            'comment_label': _("Optional reason for reverting this page"),
+            'buttons_html': buttons_html,
+            'querytext': _('Really revert this page?'),
+            'rev': self.request.rev
+            }
+
+        return '''
+<strong>%(querytext)s</strong>
+<table>
+    <tr>
+        <td class="label"><label>%(comment_label)s</label></td>
+        <td class="content">
+            <input type="text" name="comment" size="80" maxlength="200">
+            <input type="hidden" name="rev" value="%(rev)d">
+        </td>
+    </tr>
+    <tr>
+        <td></td>
+        <td class="buttons">
+            %(buttons_html)s
+        </td>
+    </tr>
+</table>
+''' % d
+
+
 
 def execute(pagename, request):
-    """ restore another revision of a page as a new current revision """
-    from MoinMoin.PageEditor import PageEditor
-
-    if request.request_method != 'POST':
-        return
-
-    rev = request.rev
-    pg = PageEditor(request, pagename)
-
-    try:
-        msg = pg.revertPage(rev)
-    except PageEditor.RevertError, error:
-        msg = unicode(error)
-
-    request.reset()
-    request.theme.add_msg(msg, "dialog")
-    pg.send_page()
+    """ Glue code for actions """
+    revert(pagename, request).render()
--- a/MoinMoin/theme/__init__.py	Thu Mar 20 16:20:23 2008 +0100
+++ b/MoinMoin/theme/__init__.py	Thu Mar 20 16:23:15 2008 +0100
@@ -1008,10 +1008,9 @@
             'do_button': _("Do"),
             'baseurl': self.request.getScriptname(),
             'pagename_quoted': wikiutil.quoteWikinameURL(self.request.page.page_name),
-            'pageurl': self.request.page.url(self.request),
             }
         html = '''
-<form class="actionsmenu" method="POST" action="%(pageurl)s">
+<form class="actionsmenu" method="GET" action="">
 <div>
     <label>%(label)s</label>
     <select name="action"