changeset 2671:9bc7d2c14e1f

Add suport for reverting pages (text-only for now). Attempts to make data form results reporting don't change anything.
author Karol Nowak <grzywacz@sul.uni.lodz.pl>
date Mon, 13 Aug 2007 23:51:26 +0200
parents 8afeb0c659b1
children 9bbe70281718
files MoinMoin/action/revert.py MoinMoin/xmlrpc/__init__.py jabberbot/commands.py jabberbot/xmlrpcbot.py jabberbot/xmppbot.py
diffstat 5 files changed, 72 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/revert.py	Mon Aug 13 23:49:59 2007 +0200
+++ b/MoinMoin/action/revert.py	Mon Aug 13 23:51:26 2007 +0200
@@ -46,4 +46,6 @@
         e = PageRevertedEvent(request, pagename, request.rev, revstr)
         send_event(e)
 
-    pg.send_page(msg=msg)
+    if request.action != "xmlrpc":
+        pg.send_page(msg=msg)
+
--- a/MoinMoin/xmlrpc/__init__.py	Mon Aug 13 23:49:59 2007 +0200
+++ b/MoinMoin/xmlrpc/__init__.py	Mon Aug 13 23:51:26 2007 +0200
@@ -556,6 +556,28 @@
 
         return xmlrpclib.Boolean(1)
 
+    def xmlrpc_revertPage(self, pagename, revision):
+        """Revert a page to previous revision
+
+        This is mainly intended to be used by the jabber bot.
+
+        @param pagename: the page name (unicode or utf-8)
+        @param revision: revision to revert to
+        @rtype bool
+        @return true on success
+
+        """
+        if not self.request.user.may.write(pagename):
+            return xmlrpclib.Fault(1, "You are not allowed to edit this page")
+
+        from MoinMoin.action import revert
+        self.request.rev = int(self._instr(revision))
+        msg = revert.execute(pagename, self.request)
+        if msg:
+            return xmlrpclib.Fault(1, "Revert failed: %s" % (msg ,))
+        else:
+            return xmlrpclib.Boolean(1)
+
     def xmlrpc_searchPages(self, query_string):
         """ Searches pages for query_string.
             Returns a list of tuples (foundpagename, context)
--- a/jabberbot/commands.py	Mon Aug 13 23:49:59 2007 +0200
+++ b/jabberbot/commands.py	Mon Aug 13 23:51:26 2007 +0200
@@ -138,6 +138,18 @@
         self.mtime = None
         self.regexp = kwargs.get('regexp', False)
 
+
+class RevertPage(BaseDataCommand):
+
+    description = u"revert a page to previous revision"
+    parameter_list = u"page_name revision"
+
+    def __init__(self, jid, pagename, revision):
+        BaseDataCommand.__init__(self, jid)
+        self.pagename = pagename
+        self.revision = revision
+
+
 class GetUserLanguage:
     """Request user's language information from wiki"""
 
@@ -147,3 +159,4 @@
         """
         self.jid = jid
         self.language = None
+
--- a/jabberbot/xmlrpcbot.py	Mon Aug 13 23:49:59 2007 +0200
+++ b/jabberbot/xmlrpcbot.py	Mon Aug 13 23:51:26 2007 +0200
@@ -130,6 +130,8 @@
             self.get_language_by_jid(command)
         elif isinstance(command, cmd.Search):
             self.do_search(command)
+        elif isinstance(command, cmd.RevertPage):
+            self.do_revert(command)
 
     def report_error(self, jid, text, data={}):
         # Dummy function, so that the string appears in a .po file
@@ -242,6 +244,27 @@
 
     do_search = _xmlrpc_decorator(do_search)
 
+    def do_revert(self, command):
+        """Performs a page revert"""
+
+        # Dummy function, so that the string appears in a .po file
+        _ = lambda x: x
+
+        self.multicall.revertPage(command.pagename, command.revision)
+        data = self._get_multicall_result(command.jid)
+
+        if type(data) == bool and data:
+            cmd_data = {'text': _("Page has been reverted.")}
+        elif isinstance(str, data) or isinstance(unicode, data):
+            cmd_data = {'text': _("Revert failed: %(reason)s" % {'reason': data})}
+        else:
+            cmd_data = {'text': _("Revert failed.")}
+
+        info = cmd.NotificationCommand([command.jid], cmd_data, async=False, msg_type=u"chat")
+        self.commands_out.put_nowait(info)
+
+    do_revert = _xmlrpc_decorator(do_revert)
+
     def get_language_by_jid(self, command):
         """Returns language of the a user identified by the given JID"""
 
--- a/jabberbot/xmppbot.py	Mon Aug 13 23:49:59 2007 +0200
+++ b/jabberbot/xmppbot.py	Mon Aug 13 23:51:26 2007 +0200
@@ -165,7 +165,7 @@
         self.contact_check = 600
         self.stopping = False
 
-        self.known_xmlrpc_cmds = [cmd.GetPage, cmd.GetPageHTML, cmd.GetPageList, cmd.GetPageInfo, cmd.Search]
+        self.known_xmlrpc_cmds = [cmd.GetPage, cmd.GetPageHTML, cmd.GetPageList, cmd.GetPageInfo, cmd.Search, cmd.RevertPage]
         self.internal_commands = ["ping", "help", "searchform"]
 
         self.xmlrpc_commands = {}
@@ -373,14 +373,19 @@
                 self.send_message(command.jid, data, u"chat")
             else:
                 form_title = _("Search results").encode("utf-8")
-                form = forms.Form(xmlnode_or_type="result", title=form_title)
 
+		warnings = []
                 for no, warning in enumerate(warnings):
-                    name = "warning%d" % (no, )
-                    form.add_field(name=name, field_type="fixed", value=warning)
+                    field = forms.Field(name="warning", field_type="fixed", value=warning)
+		    warnings.append(forms.Item([field]))
+
+		reported = [forms.Field(name="url", field_type="text-single"), forms.Field(name="description", field_type="text-single")]
+		if warnings:
+			reported.append(forms.Field(name="warning", field_type="fixed"))
+
+		form = forms.Form(xmlnode_or_type="result", title=form_title, reported_fields=reported)
 
                 for no, result in enumerate(results):
-                    name = "result%d" % (no, )
                     url = forms.Field(name="url", value=result["url"], field_type="text-single")
                     description = forms.Field(name="description", value=result["description"], field_type="text-single")
                     item = forms.Item([url, description])
@@ -491,7 +496,7 @@
         form.add_field(name="search_type", options=[title_search, full_search], field_type="list-single", label=search_label)
         form.add_field(name="search", field_type="text-single", label=search_label2)
 
-        self.send_form(jid, form, _("Wiki search"))
+	self.send_form(jid, form, _("Wiki search"))
 
     def is_internal(self, command):
         """Check if a given command is internal