changeset 779:9834dda36973

Added conflict icon in RecentChanges, refactored conflict handling in the code. Translators, esp. german translators!, there seems to be an outdated string. You will see it on the editing conflict.
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Fri, 02 Jun 2006 00:07:16 +0200
parents 43b158d3cf22
children 3b6a22e4e2f9
files MoinMoin/Page.py MoinMoin/PageEditor.py MoinMoin/PageGraphicalEditor.py MoinMoin/action/__init__.py MoinMoin/macro/RecentChanges.py
diffstat 5 files changed, 41 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/Page.py	Sun May 28 01:54:35 2006 +0200
+++ b/MoinMoin/Page.py	Fri Jun 02 00:07:16 2006 +0200
@@ -1681,4 +1681,23 @@
         text = text.replace(u'\r', u'')
         return text
 
+    def isConflict(self):
+        """ Returns true if there is a known editing conflict for that page.
+        
+        @return: true if there is a known conflict.
+        """
 
+        cache = caching.CacheEntry(self.request, self, 'conflict', scope='item')
+        return cache.exists()
+    
+    def setConflict(self, state):
+        """ Sets the editing conflict flag.
+        
+        @param state: bool, true if there is a conflict.
+        """
+        
+        cache = caching.CacheEntry(self.request, self, 'conflict', scope='item')
+        if state:
+            cache.update("") # touch it!
+        else:
+            cache.remove()
--- a/MoinMoin/PageEditor.py	Sun May 28 01:54:35 2006 +0200
+++ b/MoinMoin/PageEditor.py	Fri Jun 02 00:07:16 2006 +0200
@@ -109,6 +109,7 @@
             self.set_raw_body(verynewtext)
             return True
 
+        # this should never happen, except for empty pages
         return False
 
     def sendconfirmleaving(self):
@@ -923,7 +924,10 @@
                 if newtext==saved_page.get_raw_body():
                     msg = _("You already saved this page!")
                     return msg
-                
+                else:
+                    msg = _("You already edited this page! Please do not use the back button.")
+                    raise self.EditConflict, msg
+
             msg = _("""Sorry, someone else saved the page while you edited it.
 
 Please do the following: Use the back button of your browser, and cut&paste
--- a/MoinMoin/PageGraphicalEditor.py	Sun May 28 01:54:35 2006 +0200
+++ b/MoinMoin/PageGraphicalEditor.py	Fri Jun 02 00:07:16 2006 +0200
@@ -141,6 +141,8 @@
             # page creation
             rev = 0
 
+        self.setConflict(bool(conflict_msg))
+        
         # Page editing is done using user language
         self.request.setContentLanguage(self.request.lang)
 
--- a/MoinMoin/action/__init__.py	Sun May 28 01:54:35 2006 +0200
+++ b/MoinMoin/action/__init__.py	Fri Jun 02 00:07:16 2006 +0200
@@ -427,26 +427,19 @@
     # Save new text
     else:
         try:
+            still_conflict = "/!\ '''Edit conflict" in savetext
+            pg.setConflict(still_conflict)
             savemsg = pg.saveText(savetext, rev, trivial=trivial, comment=comment)
-        except pg.EditConflict, msg:
+        except pg.EditConflict, e:
+            msg = e.message
+
             # Handle conflict and send editor
-
-            # TODO: conflict messages are duplicated from PageEditor,
-            # refactor to one place only.
-            conflict_msg = _('Someone else changed this page while you were editing!')
             pg.set_raw_body(savetext, modified=1)
-            if pg.mergeEditConflict(rev):
-                conflict_msg = _("""Someone else saved this page while you were editing!
-Please review the page and save then. Do not save this page as it is!
-Have a look at the diff of %(difflink)s to see what has been changed.""") % {
-                    'difflink': pg.link_to(pg.request,
-                                           querystr='action=diff&rev=%d' % rev)
-                    }
-                # We don't send preview when we do merge conflict
-                pg.sendEditor(msg=conflict_msg, comment=comment)
-                return
-            else:
-                savemsg = conflict_msg
+
+            pg.mergeEditConflict(rev)
+            # We don't send preview when we do merge conflict
+            pg.sendEditor(msg=msg, comment=comment)
+            return
         
         except pg.SaveError, msg:
             # msg contain a unicode string
--- a/MoinMoin/macro/RecentChanges.py	Sun May 28 01:54:35 2006 +0200
+++ b/MoinMoin/macro/RecentChanges.py	Fri Jun 02 00:07:16 2006 +0200
@@ -60,6 +60,11 @@
     if not page.exists():
         # indicate page was deleted
         html_link = request.theme.make_icon('deleted')
+    elif page.isConflict():
+        img = request.theme.make_icon('help') # XXX introduce new icon
+        html_link = wikiutil.link_tag(request,
+                                      wikiutil.quoteWikinameURL(pagename) + "?action=edit",
+                                      img, formatter=macro.formatter)
     elif is_new:
         # show "NEW" icon if page was created after the user's bookmark
         if hilite: