changeset 973:49a9baa51a1f

Fixed getDiff, added interwikiName, mergeContents (preliminary). Added entries to my CHANGES file.
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Fri, 14 Jul 2006 16:59:35 +0200
parents 213776426ce2
children fbbee7e00ffe
files MoinMoin/xmlrpc/__init__.py docs/CHANGES.aschremmer
diffstat 2 files changed, 66 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/xmlrpc/__init__.py	Fri Jul 14 16:58:43 2006 +0200
+++ b/MoinMoin/xmlrpc/__init__.py	Fri Jul 14 16:59:35 2006 +0200
@@ -557,23 +557,75 @@
             oldcontents = lambda: ""
         else:
             oldpage = Page(request, pagename, rev=from_rev)
-            oldcontents = lambda: oldpage.get_raw_body()
+            oldcontents = lambda: oldpage.get_raw_body_str()
         
         if to_rev is None:
             newcontents = lambda: currentpage.get_raw_body()
         else:
             newpage = Page(request, pagename, rev=to_rev)
-            newcontents = lambda: newpage.get_raw_body()
+            newcontents = lambda: newpage.get_raw_body_str()
             newrev = newpage.get_real_rev()
         
         if oldcontents() and oldpage.get_real_rev() == newpage.get_real_rev():
             return xmlrpclib.Fault("ALREADY_CURRENT", "There are no changes.")
         
-        newcontents = newcontents().encode("utf-8")
+        newcontents = newcontents()
         conflict = wikiutil.containsConflictMarker(newcontents)
-        diffblob = xmlrpclib.Binary(compress(textdiff(oldcontents().encode("utf-8"), newcontents)))
+        diffblob = xmlrpclib.Binary(compress(textdiff(oldcontents(), newcontents)))
         
         return {"conflict": conflict, "diff": diffblob, "diffversion": 1, "current": currentpage.get_real_rev()}
+    
+    def xmlrpc_interwikiName(self):
+        """ Returns the interwiki name of the current wiki. """
+        name = self.request.cfg.interwikiname
+        if name is None:
+            return None
+        else:
+            return self._outstr(name)
+    
+    def xmlrpc_mergeChanges(self, pagename, diff, local_rev, delta_remote_rev, last_remote_rev, interwiki_name):
+        """ Merges a diff sent by the remote machine and returns the number of the new revision.
+            Additionally, this method tags the new revision.
+            
+            @param pagename: The pagename that is currently dealt with.
+            @param diff: The diff that can be applied to the version specified by delta_remote_rev.
+            @param local_rev: The revno of the page on the other wiki system, used for the tag.
+            @param delta_remote_rev: The revno that the diff is taken against.
+            @param last_remote_rev: The last revno of the page `pagename` that is known by the other wiki site.
+            @param interwiki_name: Used to build the interwiki tag.
+        """
+        from MoinMoin.util.bdiff import decompress, patch
+        
+        pagename = self._instr(pagename)
+       
+        # User may read page?
+        if not self.request.user.may.read(pagename) or not self.request.user.may.write(pagename):
+            return self.notAllowedFault()
+
+        # XXX add locking here!
+        
+        # current version of the page
+        currentpage = Page(self.request, pagename)
+
+        if currentpage.get_real_rev() != last_remote_rev:
+            return xmlrpclib.Fault("LASTREV_INVALID", "The page was changed")
+        
+        if not currentpage.exists() and diff is None:
+            return xmlrpclib.Fault("NOT_EXIST", "The page does not exist and no diff was supplied.")
+        
+        # base revision used for the diff
+        basepage = Page(self.request, pagename, rev=delta_remote_rev)
+        
+        # generate the new page revision by applying the diff
+        newcontents = patch(basepage.get_raw_body_str(), decompress(str(diff)))
+        
+        # write page
+        # XXX ...
+        
+        # XXX add a tag (interwiki_name, local_rev, current rev) to the page
+        # XXX return current rev
+        # XXX finished
+        
         
     # XXX BEGIN WARNING XXX
     # All xmlrpc_*Attachment* functions have to be considered as UNSTABLE API -
--- a/docs/CHANGES.aschremmer	Fri Jul 14 16:58:43 2006 +0200
+++ b/docs/CHANGES.aschremmer	Fri Jul 14 16:59:35 2006 +0200
@@ -8,6 +8,8 @@
     * Implement actual syncronisation.
     * Implement a cross-site authentication system, i.e. mainly an
       identity storage.
+    * Clean up trailing whitespace.
+    * Add page locking.
 
   New Features:
     * XMLRPC method to return the Moin version
@@ -15,12 +17,15 @@
     * Conflict icon in RecentChanges
     * XMLRPC Authentication System
     * Binary Diffing
+    * XMLRPC method to get binary diffs
+    * 
 
   Bugfixes (only stuff that is buggy in moin/1.6 main branch):
-    * ...
+    * Conflict resolution fixes.
 
   Other Changes:
     * Refactored conflict resolution and XMLRPC code.
+    * Enhanced API at some points.
 
   Developer notes:
     * ...
@@ -40,12 +45,15 @@
          backported the client code from python 2.4
 Week 23: Debian-Sprint in Extremadura, Spain. Initial thoughts about Mercurial as a base for syncronisation.
 Week 24: Evaluation of OpenID as a base for authentication, written local testing scripts
-Week 25: Conference in Chile.
+Week 25: Conference in Chile (FET 2006).
 Week 26: Implementation of the XMLRPC authentication system, added binary
          diffing (mainly taken from Mercurial, but had to merge 5 changesets,
          remove some mercurial dependencies and document it. Currently, Mercurial
          uses a module written in C to solve the problem, so the Python code
          was not cared for anymore.)
+Week 27: Europython, Geneva.
+Week 28: Debian-Edu Developer Camp. Implemented getDiff XMLRPC method, added preliminary SyncPages action,
+         added interwikiName XMLRPC method, added mergeChanges XMLRPC method.
 
 Time plan
 =========