This patch adds prev/next revision buttons to old and new revision sides, thus fully enabling revision navigation in diff action.
1 diff -r 2c025e231b5f MoinMoin/action/diff.py
2 --- a/MoinMoin/action/diff.py Sat Jan 16 07:01:45 2010 +0300
3 +++ b/MoinMoin/action/diff.py Sat Jan 16 07:42:37 2010 +0300
4 @@ -11,6 +11,7 @@
5 from MoinMoin import wikiutil
6 from MoinMoin.logfile import editlog
7 from MoinMoin.Page import Page
8 +from bisect import bisect_right, bisect_left
9
10 def execute(pagename, request):
11 """ Handle "action=diff"
12 @@ -113,23 +114,20 @@
13 request.theme.send_closing_html()
14 return
15
16 + # Assuming that revision list is sorted and reversed
17 + # (as currently done by Page.getRevList()),
18 + # we need to reverse it again for bisect functions working correctly.
19 + revlist.reverse()
20 +
21 title = _('Differences between revisions %d and %d') % (oldrev, newrev)
22 if edit_count > 1:
23 title += ' ' + _('(spanning %d versions)') % (edit_count, )
24 title = f.text(title)
25
26 - # Revision list starts from 2...
27 - if oldrev <= min(revlist):
28 - disable_prev = u' disabled="disabled"'
29 - else:
30 - disable_prev = u''
31 + page_url = wikiutil.escape(currentpage.url(request), True)
32
33 - if newrev >= max(revlist):
34 - disable_next = u' disabled="disabled"'
35 - else:
36 - disable_next = u''
37 -
38 - page_url = wikiutil.escape(currentpage.url(request), True)
39 + def enabled(val):
40 + return not val and u' disabled="disabled"' or u''
41
42 revert_html = ""
43 if request.user.may.revert(pagename):
44 @@ -143,13 +141,10 @@
45 </div>
46 </form>
47 </td>
48 - """ % (page_url, rev2, _("Revert to this revision"), disable_next)
49 + """ % (page_url, rev2, _("Revert to this revision"), enabled(newrev < revlist[-1]))
50
51 - navigation_html = """
52 -<span class="diff-header">%s</span>
53 -<table class="diff">
54 -<tr>
55 - <td style="border:0">
56 + other_diff_button_html = """
57 + <td style="border:0; width:1%%">
58 <form action="%s" method="get">
59 <div style="text-align:left">
60 <input name="action" value="diff" type="hidden">
61 @@ -159,31 +154,54 @@
62 </div>
63 </form>
64 </td>
65 - %s
66 - <td style="border:0">
67 - <form action="%s" method="get">
68 - <div style="text-align:right">
69 - <input name="action" value="diff" type="hidden">
70 - <input name="rev1" value="%d" type="hidden">
71 - <input name="rev2" value="%d" type="hidden">
72 - <input value="%s" type="submit"%s>
73 - </div>
74 - </form>
75 - </td>
76 +"""
77 +
78 + navigation_html = """
79 +<span class="diff-header">%%s</span>
80 +<table class="diff">
81 +<tr>
82 + %(button)s
83 + %%s
84 + %(button)s
85 </tr>
86 </table>
87 -""" % (title,
88 - page_url, oldrev - 1, oldrev, _("Previous change"), disable_prev,
89 +""" % {'button': other_diff_button_html}
90 +
91 + prev_oldrev = revlist[bisect_left(revlist, oldrev) - 1]
92 + next_oldrev = (oldrev < revlist[-1]) and revlist[bisect_right(revlist, oldrev)] or revlist[-1]
93 + prev_newrev = revlist[bisect_left(revlist, newrev) - 1]
94 + next_newrev = (newrev < revlist[-1]) and revlist[bisect_right(revlist, newrev)] or revlist[-1]
95 +
96 + navigation_html = navigation_html % (title,
97 + page_url, prev_oldrev, oldrev, _("Previous change"), enabled(oldrev > revlist[0]),
98 revert_html,
99 - page_url, newrev, newrev + 1, _("Next change"), disable_next, )
100 + page_url, newrev, next_newrev, _("Next change"), enabled(newrev < revlist[-1]), )
101
102 request.write(f.rawHTML(navigation_html))
103
104 oldlog = oldpage.editlog_entry()
105 newlog = newpage.editlog_entry()
106
107 + page = Page(request, pagename)
108 +
109 + def rev_nav_link(enabled, old_rev, new_rev, caption, css_classes, enabled_title, disabled_title):
110 + if enabled:
111 + return page.link_to(request, on=1, querystr={
112 + 'action': 'diff',
113 + 'rev1': old_rev,
114 + 'rev2': new_rev,
115 + }, css_class="diff-nav-link %(css_classes)s" % {
116 + 'css_classes': css_classes,
117 + }, title=enabled_title) + request.formatter.text(caption) + page.link_to(request, on=0)
118 + else:
119 + return '<span class="diff-no-nav-link %(css_classes)s" title="%(disabled_title)s">%(caption)s</span>' % {
120 + 'css_classes': css_classes,
121 + 'disabled_title': disabled_title,
122 + 'caption': caption,
123 + }
124 +
125 rev_info_html = """
126 - <div class="diff-info diff-info-header">%(rev_header)s</div>
127 + <div class="diff-info diff-info-header">%%(rev_prev_link)s %(rev_header)s %%(rev_next_link)s</div>
128 <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>
129 <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>
130 <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>
131 @@ -196,6 +214,8 @@
132 }
133
134 rev_info_old_html = rev_info_html % {
135 + 'rev_prev_link': rev_nav_link(oldrev > revlist[0], prev_oldrev, newrev, '<', 'diff-prev-link diff-old-rev', _('Diff with previous old revision'), _("No previous revision available for diff")),
136 + 'rev_next_link': rev_nav_link((oldrev < revlist[-1]) and (revlist[bisect_right(revlist, oldrev)] < newrev), next_oldrev, newrev, '>', 'diff-next-link diff-old-rev', _('Diff with next old revision'), _("Can't change to newer revision")),
137 'rev': oldrev,
138 'rev_size': oldpage.size(),
139 'rev_author': oldlog.getEditor(request) or _('N/A'),
140 @@ -204,6 +224,8 @@
141 }
142
143 rev_info_new_html = rev_info_html % {
144 + 'rev_prev_link': rev_nav_link((newrev > revlist[0]) and (oldrev < revlist[bisect_left(revlist, newrev) - 1]), oldrev, prev_newrev, '<', 'diff-prev-link diff-new-rev', _('Diff with previous new revision'), _("Can't change to older revision")),
145 + 'rev_next_link': rev_nav_link(newrev < revlist[-1], oldrev, next_newrev, '>', 'diff-next-link diff-new-rev', _('Diff with next new revision'), _("No newer revision available fo diff")),
146 'rev': newrev,
147 'rev_size': newpage.size(),
148 'rev_author': newlog.getEditor(request) or _('N/A'),
-- HarryB 2010-01-15 20:22:01 that's a very nice feature thanks for that. I understand that this feature is already installed on this wiki?
But when browsing at different revisions, the center of the diff is now moving. Is this intended? Didnt use to do this in previous versions.Well, this feature is not pushed to moin repo yet, bu i hope it will be there soon (at least, before 1.9.1, i hope). The diff view is aligned by content (more precisely, the default table flow alignment rules are in place, because there is no scpecific css width definitions in standard themes). -- EugeneSyromyatnikov 2010-01-15 23:20:32
Implemented in http://hg.moinmo.in/moin/1.9/rev/2b641be7728c. -- EugeneSyromyatnikov 2010-01-17 15:38:28