~ubuntu-branches/ubuntu/oneiric/moin/oneiric-security

« back to all changes in this revision

Viewing changes to MoinMoin/action/info.py

  • Committer: Bazaar Package Importer
  • Author(s): Jamie Strandboge
  • Date: 2010-03-30 12:55:34 UTC
  • mfrom: (0.1.17 sid)
  • Revision ID: james.westby@ubuntu.com-20100330125534-4c2ufc1rok24447l
Tags: 1.9.2-2ubuntu1
* Merge from Debian testing (LP: #521834). Based on work by Stefan Ebner.
  Remaining changes:
 - Remove python-xml from Suggests field, the package isn't anymore in
   sys.path.
 - Demote fckeditor from Recommends to Suggests; the code was previously
   embedded in moin, but it was also disabled, so there's no reason for us
   to pull this in by default currently. Note: This isn't necessary anymore
   but needs a MIR for fckeditor, so postpone dropping this change until
   lucid+1
* debian/rules:
  - Replace hardcoded python2.5 with python* and hardcore python2.6 for ln
* debian/control.in: drop versioned depends on cdbs

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
from MoinMoin.Page import Page
14
14
from MoinMoin.logfile import editlog
15
15
from MoinMoin.widget import html
 
16
from MoinMoin.action import AttachFile
16
17
 
17
18
def execute(pagename, request):
18
19
    """ show misc. infos about a page """
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
 
80
 
78
81
        try:
79
 
            max_count = int(request.form.get('max_count', [default_count])[0])
80
 
        except:
 
82
            max_count = int(request.values.get('max_count', default_count))
 
83
        except ValueError:
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))
 
86
 
 
87
        # read in the complete log of this page
 
88
        log = editlog.EditLog(request, rootpagename=pagename)
 
89
 
 
90
        offset = 0
 
91
        paging_info_html = ""
 
92
        paging_nav_html = ""
 
93
        count_select_html = ""
 
94
 
 
95
        f = request.formatter
 
96
 
 
97
        if paging:
 
98
            log_size = log.lines()
 
99
 
 
100
            try:
 
101
                offset = int(request.values.get('offset', 0))
 
102
            except ValueError:
 
103
                offset = 0
 
104
            offset = max(min(offset, log_size - 1), 0)
 
105
 
 
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,
 
110
            } + f.paragraph(0)
 
111
 
 
112
            # generating offset navigating links
 
113
            if max_count < log_size or offset != 0:
 
114
                offset_links = []
 
115
                cur_offset = max_count
 
116
                near_count = 5 # request.cfg.pagination_size
 
117
 
 
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)
 
120
                offset_added = False
 
121
 
 
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={
 
125
                            'action': 'info',
 
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) +
 
129
                        f.table_cell(0)
 
130
                    )
 
131
 
 
132
                # link to previous page - only if not at start
 
133
                if offset > 0:
 
134
                    add_offset_link(((offset - 1) / max_count) * max_count, _("Newer"))
 
135
 
 
136
                # link to beggining of event log - if min_offset is not minimal
 
137
                if min_offset > 0:
 
138
                    add_offset_link(0)
 
139
                    # adding gap only if min_offset not explicitly following beginning
 
140
                    if min_offset > 1:
 
141
                        offset_links.append(f.table_cell(1, css_class="info-offset-gap") + f.text(u'\u2026') + f.table_cell(0))
 
142
 
 
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))
 
150
                        offset_added = True
 
151
 
 
152
                    # add link, if not at this offset
 
153
                    if offset != cur_offset * max_count:
 
154
                        add_offset_link(cur_offset * max_count)
 
155
 
 
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)
 
161
 
 
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))
 
165
 
 
166
                # link to next page
 
167
                if offset < (log_size - max_count):
 
168
                    add_offset_link(((offset + max_count) / max_count) * max_count, _("Older"))
 
169
 
 
170
                # generating html
 
171
                paging_nav_html += "".join([
 
172
                    f.table(1, css_class="searchpages"),
 
173
                    f.table_row(1),
 
174
                    "".join(offset_links),
 
175
                    f.table_row(0),
 
176
                    f.table(0),
 
177
                ])
 
178
 
 
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()
 
184
            max_count_html = []
 
185
            cur_count_added = False
 
186
 
 
187
 
 
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)),
 
194
                        f.span(0),
 
195
                    ]))
 
196
                    cur_count_added = True
 
197
 
 
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={
 
203
                            'action': 'info',
 
204
                            'offset': str(offset),
 
205
                            'max_count': str(count),
 
206
                            }, css_class="info-count-link", rel="nofollow"),
 
207
                        f.text(str(count)),
 
208
                        page.link_to(request, on=0),
 
209
                        f.span(0),
 
210
                    ]))
 
211
 
 
212
            count_select_html += "".join([
 
213
                f.span(1, css_class="info-count-selector"),
 
214
                    f.text(" ("),
 
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),
 
216
                    f.text(")"),
 
217
                f.span(0),
 
218
            ])
83
219
 
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)
103
239
 
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)
 
242
            if url:
 
243
                f = request.formatter
 
244
                link = f.url(1, url) + f.text(text) + f.url(0)
 
245
                return link
 
246
 
 
247
        may_write = request.user.may.write(pagename)
 
248
        may_delete = request.user.may.delete(pagename)
 
249
 
106
250
        count = 0
107
251
        pgactioncount = 0
108
252
        for line in log.reverse():
 
253
            count += 1
 
254
 
 
255
            if paging and count <= offset:
 
256
                continue
 
257
 
109
258
            rev = int(line.rev)
110
259
            actions = []
111
260
            if line.action in ('SAVE', 'SAVENEW', 'SAVE/REVERT', 'SAVE/RENAME', ):
135
284
 
136
285
                filename = wikiutil.url_unquote(line.extra)
137
286
                comment = "%s: %s %s" % (line.action, filename, line.comment)
138
 
                size = 0
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", "")}))
147
 
 
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'))
 
291
                    if may_delete:
 
292
                        actions.append(render_file_action(_('del'), pagename, filename, request, do='del'))
 
293
                    if may_write:
 
294
                        actions.append(render_file_action(_('edit'), pagename, filename, request, do='modify'))
 
295
                else:
 
296
                    size = 0
151
297
 
152
298
            history.addRow((
153
299
                rev,
156
302
                diff,
157
303
                line.getEditor(request) or _("N/A"),
158
304
                wikiutil.escape(comment) or '&nbsp;',
159
 
                "&nbsp;".join(actions),
 
305
                "&nbsp;".join(a for a in actions if a),
160
306
            ))
161
 
            count += 1
162
 
            if count >= max_count:
 
307
            if (count >= max_count + offset) or (paging and count >= log_size):
163
308
                break
164
309
 
165
310
        # print version history
179
324
        div.append(history_table.render(method="GET"))
180
325
 
181
326
        form = html.FORM(method="GET", action="")
 
327
        if paging:
 
328
            form.append(f.div(1, css_class="info-paging-info") + paging_info_html + count_select_html + f.div(0))
 
329
            form.append("".join([
 
330
                f.div(1, css_class="info-paging-nav info-paging-nav-top"),
 
331
                paging_nav_html,
 
332
                f.div(0),
 
333
            ]))
182
334
        form.append(div)
 
335
        if paging:
 
336
            form.append("".join([
 
337
                f.div(1, css_class="info-paging-nav info-paging-nav-bottom"),
 
338
                paging_nav_html,
 
339
                f.div(0)
 
340
            ]))
183
341
        request.write(unicode(form))
184
342
 
185
343
    # main function
187
345
    page = Page(request, pagename)
188
346
    title = page.split_title()
189
347
 
190
 
    request.emit_http_headers()
191
 
 
192
348
    request.setContentLanguage(request.lang)
193
349
    f = request.formatter
194
350
 
207
363
        request.write("[%s] " % page.link_to(request, text=text, querystr=querystr, rel='nofollow'))
208
364
    request.write(f.paragraph(0))
209
365
 
210
 
    try:
211
 
        show_hitcounts = int(request.form.get('hitcounts', [0])[0]) != 0
212
 
    except ValueError:
213
 
        show_hitcounts = False
214
 
    try:
215
 
        show_general = int(request.form.get('general', [0])[0]) != 0
216
 
    except ValueError:
217
 
        show_general = False
 
366
    show_hitcounts = int(request.values.get('hitcounts', 0)) != 0
 
367
    show_general = int(request.values.get('general', 0)) != 0
218
368
 
219
369
    if show_hitcounts:
220
370
        from MoinMoin.stats import hitcounts