74
75
def history(page, pagename, request):
75
76
# show history as default
76
77
_ = request.getText
77
default_count, limit_max_count = request.cfg.history_count
78
default_count, limit_max_count = request.cfg.history_count[0:2]
79
paging = request.cfg.history_paging
79
max_count = int(request.form.get('max_count', [default_count])[0])
82
max_count = int(request.values.get('max_count', default_count))
81
84
max_count = default_count
82
max_count = min(max_count, limit_max_count)
85
max_count = max(1, min(max_count, limit_max_count))
87
# read in the complete log of this page
88
log = editlog.EditLog(request, rootpagename=pagename)
93
count_select_html = ""
98
log_size = log.lines()
101
offset = int(request.values.get('offset', 0))
104
offset = max(min(offset, log_size - 1), 0)
106
paging_info_html += f.paragraph(1, css_class="searchstats info-paging-info") + _("Showing page edit history entries from '''%(start_offset)d''' to '''%(end_offset)d''' out of '''%(total_count)d''' entries total.", wiki=True) % {
107
'start_offset': log_size - min(log_size, offset + max_count) + 1,
108
'end_offset': log_size - offset,
109
'total_count': log_size,
112
# generating offset navigating links
113
if max_count < log_size or offset != 0:
115
cur_offset = max_count
116
near_count = 5 # request.cfg.pagination_size
118
min_offset = max(0, (offset + max_count - 1) / max_count - near_count)
119
max_offset = min((log_size - 1) / max_count, offset / max_count + near_count)
122
def add_offset_link(offset, caption=None):
123
offset_links.append(f.table_cell(1, css_class="info-offset-item") +
124
page.link_to(request, on=1, querystr={
126
'offset': str(offset),
127
'max_count': str(max_count),
128
}, css_class="info-offset-nav-link", rel="nofollow") + f.text(caption or str(log_size - offset)) + page.link_to(request, on=0) +
132
# link to previous page - only if not at start
134
add_offset_link(((offset - 1) / max_count) * max_count, _("Newer"))
136
# link to beggining of event log - if min_offset is not minimal
139
# adding gap only if min_offset not explicitly following beginning
141
offset_links.append(f.table_cell(1, css_class="info-offset-gap") + f.text(u'\u2026') + f.table_cell(0))
143
# generating near pages links
144
for cur_offset in range(min_offset, max_offset + 1):
145
# note that current offset may be not multiple of max_count,
146
# so we check whether we should add current offset marker like this
147
if not offset_added and offset <= cur_offset * max_count:
148
# current info history view offset
149
offset_links.append(f.table_cell(1, css_class="info-offset-item info-cur-offset") + f.text(str(log_size - offset)) + f.table_cell(0))
152
# add link, if not at this offset
153
if offset != cur_offset * max_count:
154
add_offset_link(cur_offset * max_count)
156
# link to the last page of event log
157
if max_offset < (log_size - 1) / max_count:
158
if max_offset < (log_size - 1) / max_count - 1:
159
offset_links.append(f.table_cell(1, css_class="info-offset-gap") + f.text(u'\u2026') + f.table_cell(0))
160
add_offset_link(((log_size - 1) / max_count) * max_count)
162
# special case - if offset is greater than max_offset * max_count
163
if offset > max_offset * max_count:
164
offset_links.append(f.table_cell(1, css_class="info-offset-item info-cur-offset") + f.text(str(log_size - offset)) + f.table_cell(0))
167
if offset < (log_size - max_count):
168
add_offset_link(((offset + max_count) / max_count) * max_count, _("Older"))
171
paging_nav_html += "".join([
172
f.table(1, css_class="searchpages"),
174
"".join(offset_links),
179
# generating max_count switcher
180
# we do it only in case history_count has additional values
181
if len(request.cfg.history_count) > 2:
182
max_count_possibilities = list(set(request.cfg.history_count))
183
max_count_possibilities.sort()
185
cur_count_added = False
188
for count in max_count_possibilities:
189
# max count value can be not in list of predefined values
190
if max_count <= count and not cur_count_added:
191
max_count_html.append("".join([
192
f.span(1, css_class="info-count-item info-cur-count"),
193
f.text(str(max_count)),
196
cur_count_added = True
198
# checking for limit_max_count to prevent showing unavailable options
199
if max_count != count and count <= limit_max_count:
200
max_count_html.append("".join([
201
f.span(1, css_class="info-count-item"),
202
page.link_to(request, on=1, querystr={
204
'offset': str(offset),
205
'max_count': str(count),
206
}, css_class="info-count-link", rel="nofollow"),
208
page.link_to(request, on=0),
212
count_select_html += "".join([
213
f.span(1, css_class="info-count-selector"),
215
f.text(_("%s items per page")) % (f.span(1, css_class="info-count-selector info-count-selector-divider") + f.text(" | ") + f.span(0)).join(max_count_html),
84
220
# open log for this page
85
221
from MoinMoin.util.dataset import TupleDataset, Column
101
237
kw.update(dict(rel='nofollow'))
102
238
return page.link_to(request, text, querystr=query, **kw)
104
# read in the complete log of this page
105
log = editlog.EditLog(request, rootpagename=pagename)
240
def render_file_action(text, pagename, filename, request, do):
241
url = AttachFile.getAttachUrl(pagename, filename, request, do=do)
243
f = request.formatter
244
link = f.url(1, url) + f.text(text) + f.url(0)
247
may_write = request.user.may.write(pagename)
248
may_delete = request.user.may.delete(pagename)
107
251
pgactioncount = 0
108
252
for line in log.reverse():
255
if paging and count <= offset:
109
258
rev = int(line.rev)
111
260
if line.action in ('SAVE', 'SAVENEW', 'SAVE/REVERT', 'SAVE/RENAME', ):
136
285
filename = wikiutil.url_unquote(line.extra)
137
286
comment = "%s: %s %s" % (line.action, filename, line.comment)
139
if line.action != 'ATTDEL':
140
from MoinMoin.action import AttachFile
141
if AttachFile.exists(request, pagename, filename):
142
size = AttachFile.size(request, pagename, filename)
143
if line.action == 'ATTNEW':
144
actions.append(render_action(_('view'), {'action': 'AttachFile', 'do': 'view', 'target': '%s' % filename}))
145
elif line.action == 'ATTDRW':
146
actions.append(render_action(_('edit'), {'action': 'AttachFile', 'drawing': '%s' % filename.replace(".draw", "")}))
148
actions.append(render_action(_('get'), {'action': 'AttachFile', 'do': 'get', 'target': '%s' % filename}))
149
if request.user.may.delete(pagename):
150
actions.append(render_action(_('del'), {'action': 'AttachFile', 'do': 'del', 'target': '%s' % filename}))
287
if AttachFile.exists(request, pagename, filename):
288
size = AttachFile.size(request, pagename, filename)
289
actions.append(render_file_action(_('view'), pagename, filename, request, do='view'))
290
actions.append(render_file_action(_('get'), pagename, filename, request, do='get'))
292
actions.append(render_file_action(_('del'), pagename, filename, request, do='del'))
294
actions.append(render_file_action(_('edit'), pagename, filename, request, do='modify'))