Back to index

moin  1.9.0~rc2
Functions
MoinMoin.action.info Namespace Reference

Functions

def execute

Function Documentation

def MoinMoin.action.info.execute (   pagename,
  request 
)
show misc. infos about a page 

Definition at line 18 of file info.py.

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