[Pywikipedia-svn] SVN: [7219] branches/rewrite/pywikibot/site.py

russblau at svn.wikimedia.org russblau at svn.wikimedia.org
Mon Sep 7 18:12:56 UTC 2009


Revision: 7219
Author:   russblau
Date:     2009-09-07 18:12:56 +0000 (Mon, 07 Sep 2009)

Log Message:
-----------
Edit conflict detection.

Modified Paths:
--------------
    branches/rewrite/pywikibot/site.py

Modified: branches/rewrite/pywikibot/site.py
===================================================================
--- branches/rewrite/pywikibot/site.py	2009-09-07 09:12:09 UTC (rev 7218)
+++ branches/rewrite/pywikibot/site.py	2009-09-07 18:12:56 UTC (rev 7219)
@@ -2187,16 +2187,23 @@
         except NoPage:
             lastrev = None
             if not recreate:
-                raise 
+                raise
         token = self.token(page, "edit")
+        # getting token also updates the 'lastrevid' value, which allows us to
+        # detect if page has been changed since last time text was retrieved.
+        
+        # note that the server can still return an 'editconflict' error
+        # if the page is updated after the token is retrieved but
+        # before the page is saved.
         self.lock_page(page)
         if lastrev is not None and page.latestRevision() != lastrev:
-            raise Error("editpage: Edit conflict detected; saving aborted.")
+            raise EditConflict(
+                "editpage: Edit conflict detected; saving aborted.")
         req = api.Request(site=self, action="edit",
                           title=page.title(withSection=False),
                           text=text, token=token, summary=summary)
-##        if lastrev is not None:
-##            req["basetimestamp"] = page._revisions[lastrev].timestamp
+        if lastrev is not None:
+            req["basetimestamp"] = page._revisions[lastrev].timestamp
         if minor:
             req['minor'] = ""
         elif notminor:





More information about the Pywikipedia-svn mailing list