Mercurial > moin > 1.9
changeset 5445:2b641be7728c
action/diff.py: Added navigation links to change revision in left/right pane separately.
NOTE: util/diff_html.py output has been changed: now in case of identical texts passed it outputs message string 'No differences found!' inside table in td with class "diff-same" (previously it outputs only this message string without any table at all).
author | Eugene Syromyatnikov <evgsyr@gmail.com> |
---|---|
date | Sun, 17 Jan 2010 18:30:16 +0300 |
parents | 48874d70abff |
children | 709089f30164 8946d234bc25 |
files | MoinMoin/action/diff.py MoinMoin/util/diff_html.py MoinMoin/web/static/htdocs/classic/css/screen.css MoinMoin/web/static/htdocs/modern/css/screen.css MoinMoin/web/static/htdocs/modernized/css/screen.css MoinMoin/web/static/htdocs/rightsidebar/css/screen.css |
diffstat | 6 files changed, 128 insertions(+), 106 deletions(-) [+] |
line wrap: on
line diff
--- a/MoinMoin/action/diff.py Sun Jan 17 12:29:02 2010 +0100 +++ b/MoinMoin/action/diff.py Sun Jan 17 18:30:16 2010 +0300 @@ -102,34 +102,15 @@ oldrev = oldpage.get_real_rev() newrev = newpage.get_real_rev() - revlist = currentpage.getRevList() - - # code below assumes that the page exists and has at least - # one revision in the revlist, just bail out if not. Users - # shouldn't really run into this anyway. - if not revlist: - request.write(f.div(0)) # end content div - request.theme.send_footer(pagename) - request.theme.send_closing_html() - return - title = _('Differences between revisions %d and %d') % (oldrev, newrev) if edit_count > 1: title += ' ' + _('(spanning %d versions)') % (edit_count, ) title = f.text(title) - # Revision list starts from 2... - if oldrev <= min(revlist): - disable_prev = u' disabled="disabled"' - else: - disable_prev = u'' + page_url = wikiutil.escape(currentpage.url(request), True) - if newrev >= max(revlist): - disable_next = u' disabled="disabled"' - else: - disable_next = u'' - - page_url = wikiutil.escape(currentpage.url(request), True) + def enabled(val): + return not val and u' disabled="disabled"' or u'' revert_html = "" if request.user.may.revert(pagename): @@ -143,13 +124,10 @@ </div> </form> </td> - """ % (page_url, rev2, _("Revert to this revision"), disable_next) + """ % (page_url, rev2, _("Revert to this revision"), enabled(newrev < currentrev)) - navigation_html = """ -<span class="diff-header">%s</span> -<table class="diff"> -<tr> - <td style="border:0"> + other_diff_button_html = """ + <td style="border:0; width:1%%"> <form action="%s" method="get"> <div style="text-align:left"> <input name="action" value="diff" type="hidden"> @@ -159,31 +137,51 @@ </div> </form> </td> - %s - <td style="border:0"> - <form action="%s" method="get"> - <div style="text-align:right"> - <input name="action" value="diff" type="hidden"> - <input name="rev1" value="%d" type="hidden"> - <input name="rev2" value="%d" type="hidden"> - <input value="%s" type="submit"%s> - </div> - </form> - </td> +""" + + navigation_html = """ +<span class="diff-header">%%s</span> +<table class="diff"> +<tr> + %(button)s + %%s + %(button)s </tr> </table> -""" % (title, - page_url, oldrev - 1, oldrev, _("Previous change"), disable_prev, +""" % {'button': other_diff_button_html} + + prev_oldrev = (oldrev > 1) and (oldrev - 1) or 1 + next_oldrev = (oldrev < currentrev) and (oldrev + 1) or currentrev + + prev_newrev = (newrev > 1) and (newrev - 1) or 1 + next_newrev = (newrev < currentrev) and (newrev + 1) or currentrev + + navigation_html = navigation_html % (title, + page_url, prev_oldrev, oldrev, _("Previous change"), enabled(oldrev > 1), revert_html, - page_url, newrev, newrev + 1, _("Next change"), disable_next, ) + page_url, newrev, next_newrev, _("Next change"), enabled(newrev < currentrev), ) request.write(f.rawHTML(navigation_html)) oldlog = oldpage.editlog_entry() newlog = newpage.editlog_entry() + def rev_nav_link(enabled, old_rev, new_rev, caption, css_classes, enabled_title, disabled_title): + if enabled: + return currentpage.link_to(request, on=1, querystr={ + 'action': 'diff', + 'rev1': old_rev, + 'rev2': new_rev, + }, css_class="diff-nav-link %s" % css_classes, title=enabled_title) + request.formatter.text(caption) + currentpage.link_to(request, on=0) + else: + return '<span class="diff-no-nav-link %(css_classes)s" title="%(disabled_title)s">%(caption)s</span>' % { + 'css_classes': css_classes, + 'disabled_title': disabled_title, + 'caption': caption, + } + rev_info_html = """ - <div class="diff-info diff-info-header">%(rev_header)s</div> + <div class="diff-info diff-info-header">%%(rev_prev_link)s %(rev_header)s %%(rev_next_link)s</div> <div class="diff-info diff-info-rev-size"><span class="diff-info-caption">%(rev_size_caption)s:</span> <span class="diff-info-value">%%(rev_size)d</span></div> <div class="diff-info diff-info-rev-author"><span class="diff-info-caption">%(rev_author_caption)s:</span> <span class="diff-info-value">%%(rev_author)s</span></div> <div class="diff-info diff-info-rev-comment"><span class="diff-info-caption">%(rev_comment_caption)s:</span> <span class="diff-info-value">%%(rev_comment)s</span></div> @@ -196,6 +194,8 @@ } rev_info_old_html = rev_info_html % { + 'rev_prev_link': rev_nav_link(oldrev > 1, prev_oldrev, newrev, u'\u2190', 'diff-prev-link diff-old-rev', _('Diff with older revision in left pane'), _("No older revision available for diff")), + 'rev_next_link': rev_nav_link((oldrev < currentrev) and (next_oldrev < newrev), next_oldrev, newrev, u'\u2192', 'diff-next-link diff-old-rev', _('Diff with newer revision in left pane'), _("Can't change to revision newer than in right pane")), 'rev': oldrev, 'rev_size': oldpage.size(), 'rev_author': oldlog.getEditor(request) or _('N/A'), @@ -204,6 +204,8 @@ } rev_info_new_html = rev_info_html % { + 'rev_prev_link': rev_nav_link((newrev > 1) and (oldrev < prev_newrev), oldrev, prev_newrev, u'\u2190', 'diff-prev-link diff-new-rev', _('Diff with older revision in right pane'), _("Can't change to revision older than revision in left pane")), + 'rev_next_link': rev_nav_link(newrev < currentrev, oldrev, next_newrev, u'\u2192', 'diff-next-link diff-new-rev', _('Diff with newer revision in right pane'), _("No newer revision available for diff")), 'rev': newrev, 'rev_size': newpage.size(), 'rev_author': newlog.getEditor(request) or _('N/A'),
--- a/MoinMoin/util/diff_html.py Sun Jan 17 12:29:02 2010 +0100 +++ b/MoinMoin/util/diff_html.py Sun Jan 17 18:30:16 2010 +0300 @@ -47,12 +47,6 @@ seqobj = difflib.SequenceMatcher(None, seq1, seq2) linematch = seqobj.get_matching_blocks() - if len(seq1) == len(seq2) and linematch[0] == (0, 0, len(seq1)): - # No differences. - return " - " + _("No differences found!") - - lastmatch = (0, 0) - result = """ <table class="diff"> """ @@ -60,7 +54,11 @@ if old_top or new_top: result += '<tr><td class="%s">%s</td><td class="%s">%s</td></tr>' % (old_top_class, old_top, new_top_class, new_top) - result += """ + if len(seq1) == len(seq2) and linematch[0] == (0, 0, len(seq1)): + # No differences. + result += '<tr><td class="diff-same" colspan="2">' + _("No differences found!") + '</td></tr>' + else: + result += """ <tr> <td class="diff-removed"> <span> @@ -75,14 +73,16 @@ </tr> """ % (_('Deletions are marked like this.'), _('Additions are marked like this.'), ) - # Print all differences - for match in linematch: - # Starts of pages identical? - if lastmatch == match[0:2]: - lastmatch = (match[0] + match[2], match[1] + match[2]) - continue - llineno, rlineno = lastmatch[0]+1, lastmatch[1]+1 - result += """ + lastmatch = (0, 0) + + # Print all differences + for match in linematch: + # Starts of pages identical? + if lastmatch == match[0:2]: + lastmatch = (match[0] + match[2], match[1] + match[2]) + continue + llineno, rlineno = lastmatch[0]+1, lastmatch[1]+1 + result += """ <tr class="diff-title"> <td> %s: @@ -92,57 +92,57 @@ </td> </tr> """ % (request.formatter.line_anchorlink(1, llineno) + request.formatter.text(t_line % llineno) + request.formatter.line_anchorlink(0), - request.formatter.line_anchorlink(1, rlineno) + request.formatter.text(t_line % rlineno) + request.formatter.line_anchorlink(0)) - - leftpane = '' - rightpane = '' - linecount = max(match[0] - lastmatch[0], match[1] - lastmatch[1]) - for line in range(linecount): - if line < match[0] - lastmatch[0]: - if line > 0: - leftpane += '\n' - leftpane += seq1[lastmatch[0] + line] - if line < match[1] - lastmatch[1]: - if line > 0: - rightpane += '\n' - rightpane += seq2[lastmatch[1] + line] - - charobj = difflib.SequenceMatcher(None, leftpane, rightpane) - charmatch = charobj.get_matching_blocks() - - if charobj.ratio() < 0.5: - # Insufficient similarity. - if leftpane: - leftresult = """<span>%s</span>""" % indent(escape(leftpane)) - else: - leftresult = '' + request.formatter.line_anchorlink(1, rlineno) + request.formatter.text(t_line % rlineno) + request.formatter.line_anchorlink(0)) - if rightpane: - rightresult = """<span>%s</span>""" % indent(escape(rightpane)) - else: - rightresult = '' - else: - # Some similarities; markup changes. - charlast = (0, 0) + leftpane = '' + rightpane = '' + linecount = max(match[0] - lastmatch[0], match[1] - lastmatch[1]) + for line in range(linecount): + if line < match[0] - lastmatch[0]: + if line > 0: + leftpane += '\n' + leftpane += seq1[lastmatch[0] + line] + if line < match[1] - lastmatch[1]: + if line > 0: + rightpane += '\n' + rightpane += seq2[lastmatch[1] + line] - leftresult = '' - rightresult = '' - for thismatch in charmatch: - if thismatch[0] - charlast[0] != 0: - leftresult += """<span>%s</span>""" % indent( - escape(leftpane[charlast[0]:thismatch[0]])) - if thismatch[1] - charlast[1] != 0: - rightresult += """<span>%s</span>""" % indent( - escape(rightpane[charlast[1]:thismatch[1]])) - leftresult += escape(leftpane[thismatch[0]:thismatch[0] + thismatch[2]]) - rightresult += escape(rightpane[thismatch[1]:thismatch[1] + thismatch[2]]) - charlast = (thismatch[0] + thismatch[2], thismatch[1] + thismatch[2]) + charobj = difflib.SequenceMatcher(None, leftpane, rightpane) + charmatch = charobj.get_matching_blocks() - leftpane = '<br>\n'.join([indent(x) for x in leftresult.splitlines()]) - rightpane = '<br>\n'.join([indent(x) for x in rightresult.splitlines()]) + if charobj.ratio() < 0.5: + # Insufficient similarity. + if leftpane: + leftresult = """<span>%s</span>""" % indent(escape(leftpane)) + else: + leftresult = '' - # removed width="50%%" - result += """ + if rightpane: + rightresult = """<span>%s</span>""" % indent(escape(rightpane)) + else: + rightresult = '' + else: + # Some similarities; markup changes. + charlast = (0, 0) + + leftresult = '' + rightresult = '' + for thismatch in charmatch: + if thismatch[0] - charlast[0] != 0: + leftresult += """<span>%s</span>""" % indent( + escape(leftpane[charlast[0]:thismatch[0]])) + if thismatch[1] - charlast[1] != 0: + rightresult += """<span>%s</span>""" % indent( + escape(rightpane[charlast[1]:thismatch[1]])) + leftresult += escape(leftpane[thismatch[0]:thismatch[0] + thismatch[2]]) + rightresult += escape(rightpane[thismatch[1]:thismatch[1] + thismatch[2]]) + charlast = (thismatch[0] + thismatch[2], thismatch[1] + thismatch[2]) + + leftpane = '<br>\n'.join([indent(x) for x in leftresult.splitlines()]) + rightpane = '<br>\n'.join([indent(x) for x in rightresult.splitlines()]) + + # removed width="50%%" + result += """ <tr> <td class="diff-removed"> %s @@ -153,7 +153,7 @@ </tr> """ % (leftpane, rightpane) - lastmatch = (match[0] + match[2], match[1] + match[2]) + lastmatch = (match[0] + match[2], match[1] + match[2]) if old_bottom or new_bottom: result += '<tr><td class="%s">%s</td><td class="%s">%s</td></tr>' % (old_top_class, old_top, new_top_class, new_top)
--- a/MoinMoin/web/static/htdocs/classic/css/screen.css Sun Jan 17 12:29:02 2010 +0100 +++ b/MoinMoin/web/static/htdocs/classic/css/screen.css Sun Jan 17 18:30:16 2010 +0300 @@ -438,6 +438,11 @@ text-align: center; } +td.diff-same { + text-align: center; + border: 0; +} + .searchresult dd span { font-weight: bold; }
--- a/MoinMoin/web/static/htdocs/modern/css/screen.css Sun Jan 17 12:29:02 2010 +0100 +++ b/MoinMoin/web/static/htdocs/modern/css/screen.css Sun Jan 17 18:30:16 2010 +0300 @@ -498,6 +498,11 @@ text-align: center; } +td.diff-same { + text-align: center; + border: 0; +} + table.navigation { float: right; margin: 2px;
--- a/MoinMoin/web/static/htdocs/modernized/css/screen.css Sun Jan 17 12:29:02 2010 +0100 +++ b/MoinMoin/web/static/htdocs/modernized/css/screen.css Sun Jan 17 18:30:16 2010 +0300 @@ -454,6 +454,11 @@ text-align: center; } +td.diff-same { + text-align: center; + border: 0; +} + table.navigation { float: right; margin: 2px;
--- a/MoinMoin/web/static/htdocs/rightsidebar/css/screen.css Sun Jan 17 12:29:02 2010 +0100 +++ b/MoinMoin/web/static/htdocs/rightsidebar/css/screen.css Sun Jan 17 18:30:16 2010 +0300 @@ -389,6 +389,11 @@ text-align: center; } +td.diff-same { + text-align: center; + border: 0; +} + .searchresult dd span { font-weight: bold; }