Attachment 'patch-RecentChanges-improved-diff-links-revised.diff'
Download 1 # HG changeset patch
2 # User Paul Boddie <paul@boddie.org.uk>
3 # Date 1368454794 -7200
4 # Node ID 50e35dc5622ab16e4bb6a7f9c347ee7d1ba74d58
5 # Parent 0063e98b14aab37c5859b724b5ad75f8257f9bbf
6 Fixed diff range links to avoid comparisons with uploaded attachments.
7
8 diff -r 0063e98b14aa -r 50e35dc5622a MoinMoin/macro/RecentChanges.py
9 --- a/MoinMoin/macro/RecentChanges.py Thu May 02 22:57:54 2013 +0200
10 +++ b/MoinMoin/macro/RecentChanges.py Mon May 13 16:19:54 2013 +0200
11 @@ -107,22 +107,77 @@
12
13 # print editor name or IP
14 d['editors'] = None
15 + d['editors_detailed'] = None
16 if request.cfg.show_names:
17 +
18 + # one line means only one revision
19 if len(lines) > 1:
20 counters = {}
21 - for idx in range(len(lines)):
22 - name = lines[idx].getEditor(request)
23 - if not name in counters:
24 - counters[name] = []
25 - counters[name].append(idx+1)
26 - poslist = [(v, k) for k, v in counters.items()]
27 - poslist.sort()
28 +
29 + # track the editor name and build suitable ranges
30 + current_name = None
31 + current_edit_rev = None
32 + current_idx = None
33 +
34 + # visit each line, recording the editor name, change number range
35 + # and revision number range
36 + for idx, edit_line in enumerate(lines):
37 +
38 + # get the edit details for the log line
39 + name = edit_line.getEditor(request)
40 + edit_rev = int(edit_line.rev)
41 +
42 + # record the editor and details
43 + if current_name != name:
44 + if current_name is not None:
45 + if not counters.has_key(current_name):
46 + counters[current_name] = []
47 + counters[current_name].append((range(current_idx + 1, idx + 1), (edit_rev, current_edit_rev)))
48 +
49 + # start a new range only for genuine page revisions
50 + if edit_line.action.startswith("ATT"):
51 + current_name = None
52 + current_edit_rev = None
53 + current_idx = None
54 + else:
55 + current_name = name
56 + current_edit_rev = edit_rev
57 + current_idx = idx
58 +
59 + # for the final change, get a diff to the revision before
60 + else:
61 + if current_name is not None:
62 + if not counters.has_key(current_name):
63 + counters[current_name] = []
64 + counters[current_name].append((range(current_idx + 1, idx + 2), (edit_rev - 1, current_edit_rev)))
65 +
66 + # get the editors in order
67 + editors = [(v, k) for k, v in counters.items()]
68 + editors.sort()
69 +
70 + # prepare a dictionary of editor details for display
71 d['editors'] = []
72 - for positions, name in poslist:
73 + d['editors_detailed'] = []
74 +
75 + for details, name in editors:
76 +
77 + # get the combined index list
78 + all_idx_list = []
79 + for idx_list, rev_range in details:
80 + all_idx_list += idx_list
81 +
82 + # make the editor summary
83 d['editors'].append("%s [%s]" % (
84 - name, util.rangelist(positions)))
85 + name, util.rangelist(all_idx_list)))
86 +
87 + # make the editor details for display
88 + d['editors_detailed'].append((
89 + name, page, details))
90 +
91 else:
92 - d['editors'] = [line.getEditor(request)]
93 + name = line.getEditor(request)
94 + d['editors'] = [name]
95 + d['editors_detailed'] = [(name, page, None)]
96
97 comments = []
98 for idx in range(len(lines)):
99 diff -r 0063e98b14aa -r 50e35dc5622a MoinMoin/theme/__init__.py
100 --- a/MoinMoin/theme/__init__.py Thu May 02 22:57:54 2013 +0200
101 +++ b/MoinMoin/theme/__init__.py Mon May 13 16:19:54 2013 +0200
102 @@ -14,7 +14,7 @@
103 from MoinMoin import i18n, wikiutil, config, version, caching
104 from MoinMoin.action import get_available_actions
105 from MoinMoin.Page import Page
106 -from MoinMoin.util import pysupport
107 +from MoinMoin.util import pysupport, rangelist
108
109 modules = pysupport.getPackageModules(__file__)
110
111 @@ -1448,8 +1448,39 @@
112 html.append('<td class="rcicon2">%(info_html)s</td>\n' % d)
113
114 html.append('<td class="rceditor">')
115 - if d['editors']:
116 - html.append('<br>'.join(d['editors']))
117 + if d['editors_detailed']:
118 + notfirst = 0
119 + for name, page, details in d['editors_detailed']:
120 + if notfirst:
121 + html.append('<br>')
122 +
123 + html.append(name)
124 +
125 + if details is not None:
126 + html.append(" [")
127 + notfirstlink = 0
128 +
129 + for idx_list, rev_range in details:
130 + if notfirstlink:
131 + html.append(',')
132 +
133 + # handle pages with previous content
134 + start_rev, end_rev = rev_range
135 + if start_rev > 0:
136 + html.append(
137 + page.link_to_raw(self.request, "%s" % rangelist(idx_list),
138 + querystr={'action': 'diff', 'rev1': start_rev,
139 + 'rev2': end_rev}, rel='nofollow'))
140 +
141 + # handle initial edits of pages
142 + else:
143 + html.append(
144 + page.link_to_raw(self.request, "%s" % rangelist(idx_list),
145 + rel='nofollow'))
146 + notfirstlink = 1
147 + html.append("]")
148 +
149 + notfirst = 1
150 html.append('</td>\n')
151
152 html.append('<td class="rccomment">')
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.