--- MoinMoin/macro/RecentChanges.py.155a.old	Sun Oct 22 16:17:52 2006
+++ MoinMoin/macro/RecentChanges.py	Sun Oct 15 23:04:18 2006
@@ -44,6 +44,7 @@
 
     return wikiutil.make_breakable(comment, _MAX_COMMENT_LENGTH)
 
+# Format a single page's day's worth of page edits.
 def format_page_edits(macro, lines, bookmark_usecs):
     request = macro.request
     _ = request.getText
@@ -51,34 +52,67 @@
     line = lines[0]
     pagename = line.pagename
     tnow = time.time()
-    is_new = lines[-1].action == 'SAVENEW'
-    # check whether this page is newer than the user's bookmark
-    hilite = line.ed_time_usecs > (bookmark_usecs or line.ed_time_usecs)
+
     page = Page(request, line.pagename)
 
-    html_link = ''
-    if not page.exists():
+#    request.write("pagename=%s<br>\n " % line.pagename)
+    
+    latestrev = None
+    oldestrevline = None
+    for line in lines:
+#        request.write("- rev=%s<br>\n" % line.rev)
+        # Determine the first & last _real_ page revision
+        # (i.e. attachnew/del == 999999; we don't care about these)
+        lrev = int(line.rev)
+        if lrev != 99999999:
+            if latestrev == None:
+                latestrev = lrev
+            oldestrevline = line
+
+    if latestrev and not page.get_rev(-1, latestrev)[2]:
+        # If the latest page revision was a delete, 
         # indicate page was deleted
         html_link = request.theme.make_icon('deleted')
-    elif is_new:
-        # show "NEW" icon if page was created after the user's bookmark
-        if hilite:
-            img = request.theme.make_icon('new')
-            html_link = wikiutil.link_tag(request, wikiutil.quoteWikinameURL(pagename),
-                                          img, formatter=macro.formatter)
-    elif hilite:
-        # show "UPDATED" icon if page was edited after the user's bookmark
-        img = request.theme.make_icon('updated')
-        html_link = wikiutil.link_tag(request,
-                                      wikiutil.quoteWikinameURL(pagename) + "?action=diff&date=%d" % bookmark_usecs,
+#        request.write("- DELETED<br>\n")
+    elif oldestrevline and oldestrevline.action == 'SAVENEW':
+        # the oldest change was a create, show it as "new"
+        img = request.theme.make_icon('new')
+        html_link = wikiutil.link_tag(request, wikiutil.quoteWikinameURL(pagename),
                                       img, formatter=macro.formatter)
+#        request.write("- NEW<br>\n")
     else:
-        # show "DIFF" icon else
-        img = request.theme.make_icon('diffrc')
-        html_link = wikiutil.link_tag(request,
-                                      wikiutil.quoteWikinameURL(line.pagename) + "?action=diff",
-                                      img, formatter=macro.formatter)
+        # else call it modified.
+        img = request.theme.make_icon('updated')
+        html_link = ''
+
+        if latestrev:
+            # Try to link from the latest rev to one-before the oldest rev.
+            # Need to figure out what the next-oldest revision is.
+            oldestrev = int(oldestrevline.rev)
+            found = False
+            prehistoric_rev = None
+            for rev in page.getRevList():
+                if found:
+                    prehistoric_rev = rev
+                    break
+                elif rev == oldestrev:
+                    found = True
+
+            if prehistoric_rev:
+                html_link = wikiutil.link_tag(request,
+                                  wikiutil.quoteWikinameURL(pagename) 
+                                  + "?action=diff&rev1=%d&rev2=%d" % (prehistoric_rev, latestrev),
+                                  img, formatter=macro.formatter)
+#                request.write("- DIFF between %d and %d<br>\n" % (prehistoric_rev, latestrev))
 
+        if not html_link:
+            # There wasn't anything to diff (probably just attachment changes)
+            # so just link to the page.
+            html_link = wikiutil.link_tag(request, wikiutil.quoteWikinameURL(pagename),
+                                          img, formatter=macro.formatter)
+            
+#        request.write("- MOD<br>\n")
+#    request.write("<br>\n")
     # print name of page, with a link to it
     force_split = len(page.page_name) > _MAX_PAGENAME_LENGTH
     
@@ -278,7 +312,6 @@
     request.write(request.theme.recentchanges_header(d))
     
     pages = {}
-    ignore_pages = {}
 
     today = request.user.getTime(tnow)[0:3]
     this_day = today
@@ -296,8 +329,6 @@
         if ((this_day != day or (not hilite and not max_days))) and len(pages) > 0:
             # new day or bookmark reached: print out stuff 
             this_day = day
-            for page in pages:
-                ignore_pages[page] = None
             pages = pages.values()
             pages.sort(cmp_lines)
             pages.reverse()
@@ -324,10 +355,7 @@
         elif this_day != day:
             # new day but no changes
             this_day = day
-
-        if line.pagename in ignore_pages:
-            continue
-        
+       
         # end listing by default if user has a bookmark and we reached it
         if not max_days and not hilite:
             msg = _('[Bookmark reached]')
@@ -342,8 +370,6 @@
             # end of loop reached: print out stuff 
             # XXX duplicated code from above
             # but above does not trigger if we have the first day in wiki history
-            for page in pages:
-                ignore_pages[page] = None
             pages = pages.values()
             pages.sort(cmp_lines)
             pages.reverse()
