comparison MoinMoin/action/info.py @ 1016:8b196cdb11e8

move info action code to own file, fix some links by using page.link_to
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 23 Jul 2006 22:53:26 +0200
parents
children 05e4cd948a0f
comparison
equal deleted inserted replaced
1015:e527eea93da5 1016:8b196cdb11e8
1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - info action
4
5 Displays page history, some general page infos and statistics.
6
7 @copyright: 2000-2004 by Jürgen Hermann <jh@web.de>,
8 2006 by MoinMoin:ThomasWaldmann
9 @license: GNU GPL, see COPYING for details.
10 """
11
12 from MoinMoin import config, wikiutil, action
13 from MoinMoin.Page import Page
14 from MoinMoin.logfile import editlog
15
16 def execute(pagename, request):
17 """ show misc. infos about a page """
18 if not request.user.may.read(pagename):
19 Page(request, pagename).send_page(request)
20 return
21
22 def general(page, pagename, request):
23 _ = request.getText
24
25 request.write('<h2>%s</h2>\n' % _('General Information'))
26
27 # show page size
28 request.write(("<p>%s</p>" % _("Page size: %d")) % page.size())
29
30 # show SHA digest fingerprint
31 import sha
32 digest = sha.new(page.get_raw_body().encode(config.charset)).hexdigest().upper()
33 request.write('<p>%(label)s <tt>%(value)s</tt></p>' % {
34 'label': _("SHA digest of this page's content is:"),
35 'value': digest,
36 })
37
38 # show attachments (if allowed)
39 attachment_info = action.getHandler(request, 'AttachFile', 'info')
40 if attachment_info:
41 request.write(attachment_info(pagename, request))
42
43 # show subscribers
44 subscribers = page.getSubscribers(request, include_self=1, return_users=1)
45 if subscribers:
46 request.write('<p>', _('The following users subscribed to this page:'))
47 for lang in subscribers.keys():
48 request.write('<br>[%s] ' % lang)
49 for user in subscribers[lang]:
50 # do NOT disclose email addr, only WikiName
51 userhomepage = Page(request, user.name)
52 if userhomepage.exists():
53 request.write(userhomepage.link_to(request) + ' ')
54 else:
55 request.write(user.name + ' ')
56 request.write('</p>')
57
58 # show links
59 links = page.getPageLinks(request)
60 if links:
61 request.write('<p>', _('This page links to the following pages:'), '<br>')
62 for linkedpage in links:
63 request.write("%s%s " % (Page(request, linkedpage).link_to(request), ",."[linkedpage == links[-1]]))
64 request.write("</p>")
65
66 def history(page, pagename, request):
67 # show history as default
68 _ = request.getText
69
70 # open log for this page
71 from MoinMoin.util.dataset import TupleDataset, Column
72
73 history = TupleDataset()
74 history.columns = [
75 Column('rev', label='#', align='right'),
76 Column('mtime', label=_('Date'), align='right'),
77 Column('size', label=_('Size'), align='right'),
78 Column('diff', label='<input type="submit" value="%s">' % (_("Diff"))),
79 Column('editor', label=_('Editor'), hidden=not request.cfg.show_names),
80 Column('comment', label=_('Comment')),
81 Column('action', label=_('Action')),
82 ]
83
84 # generate history list
85 revisions = page.getRevList()
86 versions = len(revisions)
87
88 may_revert = request.user.may.revert(pagename)
89
90 # read in the complete log of this page
91 log = editlog.EditLog(request, rootpagename=pagename)
92 count = 0
93 for line in log.reverse():
94 rev = int(line.rev)
95 actions = ""
96 if line.action in ['SAVE', 'SAVENEW', 'SAVE/REVERT', ]:
97 size = page.size(rev=rev)
98 if count == 0: # latest page
99 actions = '%s&nbsp;%s' % (actions, page.link_to(request,
100 text=_('view'),
101 querystr=''))
102 actions = '%s&nbsp;%s' % (actions, page.link_to(request,
103 text=_('raw'),
104 querystr='action=raw', rel='nofollow'))
105 actions = '%s&nbsp;%s' % (actions, page.link_to(request,
106 text=_('print'),
107 querystr='action=print', rel='nofollow'))
108 else:
109 actions = '%s&nbsp;%s' % (actions, page.link_to(request,
110 text=_('view'),
111 querystr='action=recall&rev=%d' % rev, rel='nofollow'))
112 actions = '%s&nbsp;%s' % (actions, page.link_to(request,
113 text=_('raw'),
114 querystr='action=raw&rev=%d' % rev, rel='nofollow'))
115 actions = '%s&nbsp;%s' % (actions, page.link_to(request,
116 text=_('print'),
117 querystr='action=print&rev=%d' % rev, rel='nofollow'))
118 if may_revert and size: # you can only revert to nonempty revisions
119 actions = '%s&nbsp;%s' % (actions, page.link_to(request,
120 text=_('revert'),
121 querystr='action=revert&rev=%d' % rev, rel='nofollow'))
122 if count == 0:
123 rchecked = ' checked="checked"'
124 lchecked = ''
125 elif count == 1:
126 lchecked = ' checked="checked"'
127 rchecked = ''
128 else:
129 lchecked = rchecked = ''
130 diff = '<input type="radio" name="rev1" value="%d"%s><input type="radio" name="rev2" value="%d"%s>' % (rev, lchecked, rev, rchecked)
131 comment = line.comment
132 if not comment and '/REVERT' in line.action:
133 comment = _("Revert to revision %(rev)d.") % {'rev': int(line.extra)}
134 else: # ATT*
135 rev = '-'
136 diff = '-'
137
138 filename = wikiutil.url_unquote(line.extra)
139 comment = "%s: %s %s" % (line.action, filename, line.comment)
140 size = 0
141 if line.action != 'ATTDEL':
142 from MoinMoin.action import AttachFile
143 page_dir = AttachFile.getAttachDir(request, pagename)
144 filepath = os.path.join(page_dir, filename)
145 try:
146 # FIXME, wrong path on non-std names
147 size = os.path.getsize(filepath)
148 except:
149 pass
150 if line.action == 'ATTNEW':
151 actions = '%s&nbsp;%s' % (actions, page.link_to(request,
152 text=_('view'),
153 querystr='action=AttachFile&do=view&target=%s' % filename, rel='nofollow'))
154 elif line.action == 'ATTDRW':
155 actions = '%s&nbsp;%s' % (actions, page.link_to(request,
156 text=_('edit'),
157 querystr='action=AttachFile&drawing=%s' % filename.replace(".draw", ""), rel='nofollow'))
158
159 actions = '%s&nbsp;%s' % (actions, page.link_to(request,
160 text=_('get'),
161 querystr='action=AttachFile&do=get&target=%s' % filename, rel='nofollow'))
162 actions = '%s&nbsp;%s' % (actions, page.link_to(request,
163 text=_('del'),
164 querystr='action=AttachFile&do=del&target=%s' % filename, rel='nofollow'))
165 # XXX use?: wikiutil.escape(filename)
166
167 history.addRow((
168 rev,
169 request.user.getFormattedDateTime(wikiutil.version2timestamp(line.ed_time_usecs)),
170 str(size),
171 diff,
172 line.getEditor(request) or _("N/A"),
173 wikiutil.escape(comment) or '&nbsp;',
174 actions,
175 ))
176 count += 1
177 if count >= 100:
178 break
179
180 # print version history
181 from MoinMoin.widget.browser import DataBrowserWidget
182
183 request.write('<h2>%s</h2>\n' % _('Revision History'))
184
185 if not count: # there was no entry in logfile
186 request.write(_('No log entries found.'))
187 return
188
189 # TODO: this form activates revert, which should use POST, but
190 # other actions should use get. Maybe we should put the revert
191 # into the page view itself, and not in this form.
192 request.write('<form method="GET" action="">\n')
193 request.write('<div id="page-history">\n')
194 request.write('<input type="hidden" name="action" value="diff">\n')
195
196 history_table = DataBrowserWidget(request)
197 history_table.setData(history)
198 history_table.render()
199 request.write('</div>\n')
200 request.write('</form>\n')
201
202 # main function
203 _ = request.getText
204 page = Page(request, pagename)
205 qpagename = wikiutil.quoteWikinameURL(pagename)
206 title = page.split_title(request)
207
208 request.http_headers()
209
210 # This action uses page or wiki language TODO: currently
211 # page.language is broken and not available now, when we fix it,
212 # this will be automatically fixed.
213 lang = page.language or request.cfg.language_default
214 request.setContentLanguage(lang)
215
216 request.theme.send_title(_('Info for "%s"') % (title,), pagename=pagename)
217 menu_items = [
218 (_('Show "%(title)s"') % {'title': _('Revision History')},
219 {'action': 'info'}),
220 (_('Show "%(title)s"') % {'title': _('General Page Infos')},
221 {'action': 'info', 'general': '1'}),
222 (_('Show "%(title)s"') % {'title': _('Page hits and edits')},
223 {'action': 'info', 'hitcounts': '1'}),
224 ]
225 request.write('<div id="content">\n') # start content div
226 request.write("<p>")
227 for text, querystr in menu_items:
228 request.write("[%s] " % page.link_to(request, text=text, querystr=querystr, rel='nofollow'))
229 request.write("</p>")
230
231 show_hitcounts = int(request.form.get('hitcounts', [0])[0]) != 0
232 show_general = int(request.form.get('general', [0])[0]) != 0
233
234 if show_hitcounts:
235 from MoinMoin.stats import hitcounts
236 request.write(hitcounts.linkto(pagename, request, 'page=' + wikiutil.url_quote_plus(pagename)))
237 elif show_general:
238 general(page, pagename, request)
239 else:
240 history(page, pagename, request)
241
242 request.write('</div>\n') # end content div
243 request.theme.send_footer(pagename)
244 request.theme.send_closing_html()
245