From 2c97ef3abd96219f943251932daf8b6778c0b2d7 Mon Sep 17 00:00:00 2001
From: Paul Wise <pabs3@bonedaddy.net>
Date: Sat, 20 Apr 2013 13:46:50 +0800
Subject: [PATCH] Implement an incremental dump process

---
 MoinMoin/script/export/dump.py | 37 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/MoinMoin/script/export/dump.py b/MoinMoin/script/export/dump.py
index d770e5b..c545c1a 100644
--- a/MoinMoin/script/export/dump.py
+++ b/MoinMoin/script/export/dump.py
@@ -12,6 +12,8 @@ import sys, os, time, codecs, shutil, re, errno
 from MoinMoin import config, wikiutil, Page, user
 from MoinMoin import script
 from MoinMoin.action import AttachFile
+from MoinMoin.logfile import editlog
+from MoinMoin.util.filesys import touch
 
 url_prefix_static = "."
 logo_html = '<img src="logo.png">'
@@ -126,6 +128,21 @@ General syntax: moin [options] export dump [dump-options]
             help = "User the dump will be performed as (for ACL checks, etc)"
         )
 
+    def changed_pages(self, request, timestamp):
+        pages = []
+        old_pages = []
+        unreadable_pages = []
+        version = wikiutil.timestamp2version(timestamp)
+        log = editlog.EditLog(request)
+        for line in log:
+            if not request.user.may.read(line.pagename):
+                unreadable_pages.append(line.pagename)
+            elif line.ed_time_usecs < version:
+                old_pages.append(line.pagename)
+            else:
+                pages.append(line.pagename)
+        return (unreadable_pages, old_pages, pages)
+
     def mainloop(self):
         """ moin-dump's main code. """
 
@@ -157,7 +174,25 @@ General syntax: moin [options] export dump [dump-options]
         # use this user for permissions checks
         request.user = user.User(request, name=self.options.dump_user)
 
-        pages = request.rootpage.getPageList(user='') # get list of all pages in wiki
+        timestamp = None
+        timestamp_file = os.path.join(outputdir, 'moin-last-update')
+        try:
+            timestamp = os.stat(timestamp_file).st_mtime
+        except OSError, err:
+            if err.errno == errno.EEXIST:
+                with open(timestamp_file, 'w') as f:
+                    f.write('This is a MoinMoin timestamp file\r\n')
+                    f.write('Please delete it to rebuild all pages\r\n')
+                    f.close()
+            else:
+                script.fatal("Cannot check last update time of '%s'!" % timestamp_file)
+        if timestamp:
+            unreadable, old, pages = self.changed_pages(request, timestamp)
+            touch(timestamp_file)
+            if unreadable or old:
+                script.log('Ignored %s old or unreadable pages' % (len(unreadable) + len(old)))
+        else:
+            pages = request.rootpage.getPageList(user='') # get list of all pages in wiki
         pages.sort()
         if self.options.page: # did user request a particular page or group of pages?
             try:
-- 
1.8.2.1

