Short description
When you use cvs and have been editing a file, you can do cvs diff filename.py and see what you've changed in a file before you do your cvs commit filename.py. It would be nice to do the same thing in a wiki. Sure you can preview your current version, but it would be nice to be able to see a highlighted diff of what you're previewing and the unchanged version is. That would make it easier to remember what changes you've made and check them in the preview. Perhaps it could just do the diff when you click Preview or you could add a "Diff and Preview" button.
This is a pretty interesting feature. Any plans to include it in moin? -- DimitrisGlezos (1/4/07)
Yes, I will be happy to have this feature too! -- AlexeyEfimov (18.10.2007)
Here's a hacked up patch to implement this. It's not pretty, but Works For Me (TM).
* looking for arch@arch.thinkmo.de--2003-archives/moin--main--1.3--patch-884 to compare with * comparing to arch@arch.thinkmo.de--2003-archives/moin--main--1.3--patch-884: ... done. * modified files --- orig/MoinMoin/PageEditor.py +++ mod/MoinMoin/PageEditor.py @@ -174,6 +174,7 @@ conflict_msg = None edit_lock_message = None preview = kw.get('preview', None) + dodiff = kw.get('dodiff', False) emit_anchor = not kw.get('staytop', 0) from MoinMoin.formatter.text_html import Formatter @@ -401,11 +402,12 @@ self.request.write(''' <p> <input type="submit" name="button_save" value="%s"> -<input type="submit" name="button_preview" value="%s"> %s +<input type="submit" name="button_preview" value="%s"> +<input type="submit" name="button_preview_diff" value="%s"> %s <input type="submit" name="button_cancel" value="%s"> </p> <p> -''' % (save_button_text, _('Preview'), button_spellcheck, cancel_button_text,)) +''' % (save_button_text, _('Preview'), _('Diff'), button_spellcheck, cancel_button_text, )) if self.cfg.mail_smarthost: self.request.write(''' @@ -442,8 +444,17 @@ + '</dl>') if preview is not None: - self.send_page(self.request, content_id='preview', content_only=1, - hilite_re=badwords_re) + if dodiff: + if self.default_formatter: + from MoinMoin.formatter.text_html import Formatter + self.formatter = Formatter(self.request, store_pagelinks=1) + self.request.write(self.formatter.startContent('preview')) + from MoinMoin import wikiaction + wikiaction.do_diff(self.page_name, self.request, preview) + self.request.write(self.formatter.endContent()) + else: + self.send_page(self.request, content_id='preview', content_only=1, + hilite_re=badwords_re) self.request.write(self.request.formatter.endContent()) wikiutil.send_footer(self.request, self.page_name) --- orig/MoinMoin/wikiaction.py +++ mod/MoinMoin/wikiaction.py @@ -29,7 +29,7 @@ ### Misc Actions ############################################################################# -def do_diff(pagename, request): +def do_diff(pagename, request, newtext=None): """ Handle "action=diff" checking for either a "rev=formerrevision" parameter or rev1 and rev2 parameters @@ -82,13 +82,18 @@ ignorews = 0 _ = request.getText + + oldpagename = pagename # get a list of old revisions, and back out if none are available currentpage = Page(request, pagename) revisions = currentpage.getRevList() if len(revisions) < 2: - currentpage.send_page(request, msg=_("No older revisions available!")) - return + if newtext is None: + currentpage.send_page(request, msg=_("No older revisions available!")) + return + else: + oldpagename = '$EmptyPage$' # hack if date: # this is how we get called from RecentChanges rev1 = 0 @@ -105,8 +110,9 @@ # This action generate content in the user language request.setContentLanguage(request.lang) - request.http_headers() - wikiutil.send_title(request, _('Diff for "%s"') % (pagename,), pagename=pagename) + if newtext is None: + request.http_headers() + wikiutil.send_title(request, _('Diff for "%s"') % (pagename,), pagename=pagename) if (rev1>0 and rev2>0 and rev1>rev2) or (rev1==0 and rev2>0): rev1,rev2 = rev2,rev1 @@ -125,7 +131,7 @@ break if rev1 == -1: - oldpage = Page(request, pagename, rev=revisions[1]) + oldpage = Page(request, oldpagename, rev=revisions[1]) oldcount1 = oldcount1 - 1 elif rev1 == 0: oldpage = currentpage @@ -149,6 +155,9 @@ newpage.set_raw_body("") # avoid loading from disk oldrev2 = 0 # XXX + if not (newtext is None): + newpage.set_raw_body(newtext) + edit_count = abs(oldcount1 - oldcount2) # this should use the formatter, but there is none? @@ -190,7 +199,8 @@ request.write('</pre>') request.write('</div>\n') # end content div - wikiutil.send_footer(request, pagename, showpage=1) + if newtext is None: + wikiutil.send_footer(request, pagename, showpage=1) def do_info(pagename, request): @@ -593,8 +603,9 @@ # Preview, spellcheck or spellcheck add new words if (request.form.has_key('button_preview') or request.form.has_key('button_spellcheck') or - request.form.has_key('button_newwords')): - pg.sendEditor(preview=savetext, comment=comment) + request.form.has_key('button_newwords') or + request.form.has_key('button_preview_diff')): + pg.sendEditor(preview=savetext, comment=comment, dodiff=request.form.has_key('button_preview_diff')) # Edit was canceled elif request.form.has_key('button_cancel'):
Good luck, -- JohannesBerg 2005-08-11 22:52:14
Note: This is fairly broken when someone else edits the page during the time at which you do. You'll still diff against the version you started from, and I'm not sure if it really renews the edit lock. -- JohannesBerg 2005-09-27 16:16:10
A nicer patch for 1.5 which depends on RefactoringProposals/DiffCreation
# HG changeset patch # User johannes@sipsolutions.net # Node ID a578c03ab6bffbb0ba22c7ac6a4033291e3982b9 # Parent 8e9cde09becae14ac999773a92014a8a93380723 This patch adds a diff button to the editors to allow previewing the diff. diff -r 8e9cde09beca -r a578c03ab6bf MoinMoin/PageEditor.py --- a/MoinMoin/PageEditor.py Wed Jul 19 23:31:41 2006 +0100 +++ b/MoinMoin/PageEditor.py Wed Jul 19 23:34:40 2006 +0100 @@ -131,6 +131,7 @@ class PageEditor(Page): @keyword preview: if given, show this text in preview mode @keyword staytop: don't go to #preview @keyword comment: comment field (when preview is true) + @keyword diffto: old text if preview diff should be shown """ from MoinMoin import i18n try: @@ -147,6 +148,7 @@ class PageEditor(Page): conflict_msg = None edit_lock_message = None preview = kw.get('preview', None) + diffto = kw.get('diffto', None) staytop = kw.get('staytop', 0) from MoinMoin.formatter.text_html import Formatter @@ -330,7 +332,8 @@ If you don't want that, hit '''%(cancel_ self.request.write(''' <input class="button" type="submit" name="button_save" value="%s" onClick="flgChange = false;"> <input class="button" type="submit" name="button_preview" value="%s" onClick="flgChange = false;"> -''' % (save_button_text, _('Preview'),)) +<input class="button" type="submit" name="button_diff" value="%s" onClick="flgChange = false;"> +''' % (save_button_text, _('Preview'), _('Diff'),)) if not (self.request.cfg.editor_force and self.request.cfg.editor_default == 'text'): self.request.write(''' @@ -424,8 +427,11 @@ If you don't want that, hit '''%(cancel_ content_id = 'previewbelow' else: content_id = 'preview' - self.send_page(self.request, content_id=content_id, content_only=1, - hilite_re=badwords_re) + if diffto is None: + self.send_page(self.request, content_id=content_id, content_only=1, + hilite_re=badwords_re) + else: + self.send_diff(diffto, content_id=content_id, difftitle = _('Unsaved changes')) self.request.write(self.request.formatter.endContent()) wikiutil.send_footer(self.request, self.page_name) diff -r 8e9cde09beca -r a578c03ab6bf MoinMoin/PageGraphicalEditor.py --- a/MoinMoin/PageGraphicalEditor.py Wed Jul 19 23:31:41 2006 +0100 +++ b/MoinMoin/PageGraphicalEditor.py Wed Jul 19 23:34:40 2006 +0100 @@ -45,6 +45,7 @@ class PageGraphicalEditor(PageEditor.Pag @keyword preview: if given, show this text in preview mode @keyword staytop: don't go to #preview @keyword comment: comment field (when preview is true) + @keyword diffto: old text if preview diff should be shown """ from MoinMoin import i18n try: @@ -62,6 +63,7 @@ class PageGraphicalEditor(PageEditor.Pag conflict_msg = None edit_lock_message = None preview = kw.get('preview', None) + diffto = kw.get('diffto', None) staytop = kw.get('staytop', 0) # check edit permissions @@ -236,11 +238,12 @@ If you don't want that, hit '''%(cancel_ self.request.write(''' <input class="button" type="submit" name="button_save" value="%s"> <input class="button" type="submit" name="button_preview" value="%s"> +<input class="button" type="submit" name="button_diff" value="%s"> <input class="button" type="submit" name="button_switch" value="%s"> %s <input class="button" type="submit" name="button_cancel" value="%s"> <input type="hidden" name="editor" value="gui"> -''' % (save_button_text, _('Preview'), _('Text mode'), button_spellcheck, cancel_button_text,)) +''' % (save_button_text, _('Preview'), _('Diff'), _('Text mode'), button_spellcheck, cancel_button_text,)) self.sendconfirmleaving() # TODO update state of flgChange to make this work, see PageEditor @@ -348,8 +351,11 @@ If you don't want that, hit '''%(cancel_ content_id = 'previewbelow' else: content_id = 'preview' - self.send_page(self.request, content_id=content_id, content_only=1, - hilite_re=badwords_re) + if diffto is None: + self.send_page(self.request, content_id=content_id, content_only=1, + hilite_re=badwords_re) + else: + self.send_diff(diffto, _('Unsaved changes'), content_id=content_id) self.request.write(self.request.formatter.endContent()) # end content div wikiutil.send_footer(self.request, self.page_name) diff -r 8e9cde09beca -r a578c03ab6bf MoinMoin/wikiaction.py --- a/MoinMoin/wikiaction.py Wed Jul 19 23:31:41 2006 +0100 +++ b/MoinMoin/wikiaction.py Wed Jul 19 23:34:40 2006 +0100 @@ -610,6 +610,9 @@ def do_edit(pagename, request): request.form.has_key('button_newwords')): pg.sendEditor(preview=savetext, comment=comment) + elif request.form.has_key('button_diff'): + pg.sendEditor(preview=savetext, comment=comment, diffto=pg.getlines()) + # Preview with mode switch elif request.form.has_key('button_switch'): pg.sendEditor(preview=savetext, comment=comment, staytop=1)
-- JohannesBerg 2005-10-12 13:27:30