Back to index

moin  1.9.0~rc2
info.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - info action
00004 
00005     Displays page history, some general page infos and statistics.
00006 
00007     @copyright: 2000-2004 Juergen Hermann <jh@web.de>,
00008                 2006-2008 MoinMoin:ThomasWaldmann
00009     @license: GNU GPL, see COPYING for details.
00010 """
00011 
00012 from MoinMoin import config, wikiutil, action
00013 from MoinMoin.Page import Page
00014 from MoinMoin.logfile import editlog
00015 from MoinMoin.widget import html
00016 from MoinMoin.action import AttachFile
00017 
00018 def execute(pagename, request):
00019     """ show misc. infos about a page """
00020     if not request.user.may.read(pagename):
00021         Page(request, pagename).send_page()
00022         return
00023 
00024     def general(page, pagename, request):
00025         _ = request.getText
00026         f = request.formatter
00027 
00028         request.write(f.heading(1, 1),
00029                       f.text(_('General Information')),
00030                       f.heading(0, 1))
00031 
00032         request.write(f.paragraph(1),
00033                       f.text(_("Page size: %d") % page.size()),
00034                       f.paragraph(0))
00035 
00036         from MoinMoin.support.python_compatibility import hash_new
00037         digest = hash_new('sha1', page.get_raw_body().encode(config.charset)).hexdigest().upper()
00038         request.write(f.paragraph(1),
00039                       f.rawHTML('%(label)s <tt>%(value)s</tt>' % {
00040                           'label': _("SHA digest of this page's content is:"),
00041                           'value': digest, }),
00042                       f.paragraph(0))
00043 
00044         # show attachments (if allowed)
00045         attachment_info = action.getHandler(request, 'AttachFile', 'info')
00046         if attachment_info:
00047             request.write(attachment_info(pagename, request))
00048 
00049         # show subscribers
00050         subscribers = page.getSubscribers(request, include_self=1, return_users=1)
00051         if subscribers:
00052             request.write(f.paragraph(1))
00053             request.write(f.text(_('The following users subscribed to this page:')))
00054             for lang in subscribers:
00055                 request.write(f.linebreak(), f.text('[%s] ' % lang))
00056                 for user in subscribers[lang]:
00057                     # do NOT disclose email addr, only WikiName
00058                     userhomepage = Page(request, user.name)
00059                     if userhomepage.exists():
00060                         request.write(f.rawHTML(userhomepage.link_to(request) + ' '))
00061                     else:
00062                         request.write(f.text(user.name + ' '))
00063             request.write(f.paragraph(0))
00064 
00065         # show links
00066         links = page.getPageLinks(request)
00067         if links:
00068             request.write(f.paragraph(1))
00069             request.write(f.text(_('This page links to the following pages:')))
00070             request.write(f.linebreak())
00071             for linkedpage in links:
00072                 request.write(f.rawHTML("%s%s " % (Page(request, linkedpage).link_to(request), ",."[linkedpage == links[-1]])))
00073             request.write(f.paragraph(0))
00074 
00075     def history(page, pagename, request):
00076         # show history as default
00077         _ = request.getText
00078         default_count, limit_max_count = request.cfg.history_count
00079         try:
00080             max_count = int(request.values.get('max_count', default_count))
00081         except:
00082             max_count = default_count
00083         max_count = min(max_count, limit_max_count)
00084 
00085         # open log for this page
00086         from MoinMoin.util.dataset import TupleDataset, Column
00087 
00088         history = TupleDataset()
00089         history.columns = [
00090             Column('rev', label='#', align='right'),
00091             Column('mtime', label=_('Date'), align='right'),
00092             Column('size', label=_('Size'), align='right'),
00093             Column('diff', label='<input type="submit" value="%s">' % (_("Diff"))),
00094             Column('editor', label=_('Editor'), hidden=not request.cfg.show_names),
00095             Column('comment', label=_('Comment')),
00096             Column('action', label=_('Action')),
00097             ]
00098 
00099         # generate history list
00100 
00101         def render_action(text, query, **kw):
00102             kw.update(dict(rel='nofollow'))
00103             return page.link_to(request, text, querystr=query, **kw)
00104 
00105         def render_file_action(text, pagename, filename, request, do):
00106             url = AttachFile.getAttachUrl(pagename, filename, request, do=do)
00107             if url:
00108                 f = request.formatter
00109                 link = f.url(1, url) + f.text(text) + f.url(0)
00110                 return link
00111 
00112         may_write = request.user.may.write(pagename)
00113         may_delete = request.user.may.delete(pagename)
00114 
00115         # read in the complete log of this page
00116         log = editlog.EditLog(request, rootpagename=pagename)
00117         count = 0
00118         pgactioncount = 0
00119         for line in log.reverse():
00120             rev = int(line.rev)
00121             actions = []
00122             if line.action in ('SAVE', 'SAVENEW', 'SAVE/REVERT', 'SAVE/RENAME', ):
00123                 size = page.size(rev=rev)
00124                 actions.append(render_action(_('view'), {'action': 'recall', 'rev': '%d' % rev}))
00125                 if pgactioncount == 0:
00126                     rchecked = ' checked="checked"'
00127                     lchecked = ''
00128                 elif pgactioncount == 1:
00129                     lchecked = ' checked="checked"'
00130                     rchecked = ''
00131                 else:
00132                     lchecked = rchecked = ''
00133                 diff = '<input type="radio" name="rev1" value="%d"%s><input type="radio" name="rev2" value="%d"%s>' % (rev, lchecked, rev, rchecked)
00134                 if rev > 1:
00135                     diff += render_action(' ' + _('to previous'), {'action': 'diff', 'rev1': rev-1, 'rev2': rev})
00136                 comment = line.comment
00137                 if not comment:
00138                     if '/REVERT' in line.action:
00139                         comment = _("Revert to revision %(rev)d.") % {'rev': int(line.extra)}
00140                     elif '/RENAME' in line.action:
00141                         comment = _("Renamed from '%(oldpagename)s'.") % {'oldpagename': line.extra}
00142                 pgactioncount += 1
00143             else: # ATT*
00144                 rev = '-'
00145                 diff = '-'
00146 
00147                 filename = wikiutil.url_unquote(line.extra)
00148                 comment = "%s: %s %s" % (line.action, filename, line.comment)
00149                 if AttachFile.exists(request, pagename, filename):
00150                     size = AttachFile.size(request, pagename, filename)
00151                     actions.append(render_file_action(_('view'), pagename, filename, request, do='view'))
00152                     actions.append(render_file_action(_('get'), pagename, filename, request, do='get'))
00153                     if may_delete:
00154                         actions.append(render_file_action(_('del'), pagename, filename, request, do='del'))
00155                     if may_write:
00156                         actions.append(render_file_action(_('edit'), pagename, filename, request, do='modify'))
00157                 else:
00158                     size = 0
00159 
00160             history.addRow((
00161                 rev,
00162                 request.user.getFormattedDateTime(wikiutil.version2timestamp(line.ed_time_usecs)),
00163                 str(size),
00164                 diff,
00165                 line.getEditor(request) or _("N/A"),
00166                 wikiutil.escape(comment) or '&nbsp;',
00167                 "&nbsp;".join(a for a in actions if a),
00168             ))
00169             count += 1
00170             if count >= max_count:
00171                 break
00172 
00173         # print version history
00174         from MoinMoin.widget.browser import DataBrowserWidget
00175 
00176         request.write(unicode(html.H2().append(_('Revision History'))))
00177 
00178         if not count: # there was no entry in logfile
00179             request.write(_('No log entries found.'))
00180             return
00181 
00182         history_table = DataBrowserWidget(request)
00183         history_table.setData(history)
00184 
00185         div = html.DIV(id="page-history")
00186         div.append(html.INPUT(type="hidden", name="action", value="diff"))
00187         div.append(history_table.render(method="GET"))
00188 
00189         form = html.FORM(method="GET", action="")
00190         form.append(div)
00191         request.write(unicode(form))
00192 
00193     # main function
00194     _ = request.getText
00195     page = Page(request, pagename)
00196     title = page.split_title()
00197 
00198     request.setContentLanguage(request.lang)
00199     f = request.formatter
00200 
00201     request.theme.send_title(_('Info for "%s"') % (title, ), page=page)
00202     menu_items = [
00203         (_('Show "%(title)s"') % {'title': _('Revision History')},
00204          {'action': 'info'}),
00205         (_('Show "%(title)s"') % {'title': _('General Page Infos')},
00206          {'action': 'info', 'general': '1'}),
00207         (_('Show "%(title)s"') % {'title': _('Page hits and edits')},
00208          {'action': 'info', 'hitcounts': '1'}),
00209     ]
00210     request.write(f.div(1, id="content")) # start content div
00211     request.write(f.paragraph(1))
00212     for text, querystr in menu_items:
00213         request.write("[%s] " % page.link_to(request, text=text, querystr=querystr, rel='nofollow'))
00214     request.write(f.paragraph(0))
00215 
00216     show_hitcounts = int(request.values.get('hitcounts', 0)) != 0
00217     show_general = int(request.values.get('general', 0)) != 0
00218 
00219     if show_hitcounts:
00220         from MoinMoin.stats import hitcounts
00221         request.write(hitcounts.linkto(pagename, request, 'page=' + wikiutil.url_quote(pagename)))
00222     elif show_general:
00223         general(page, pagename, request)
00224     else:
00225         history(page, pagename, request)
00226 
00227     request.write(f.div(0)) # end content div
00228     request.theme.send_footer(pagename)
00229     request.theme.send_closing_html()
00230