diff MoinMoin/action/info.py @ 5102:9ae242080889

drawings/attachments: made editing support more generic (details see below) refactored AttachFile.getAttachUrl: * removed drawing param * it detects drawings now from the filename's extension (e.g. .adraw for the anywikidraw container and .tdraw for the twikidraw container) * it returns None now, if the combination of filename (extension) and do=something is not supported AttachFile.get_action looks up the action (module name) for specific combinations of filenames (extension) and do=subaction. info/history and AttachFile filelist action: Less hardcoded drawing support, it now just tries to get a do=modify URL for every file attachment. If that works, there will be an edit link for that attachment. action.anywikidraw and action.twikidraw: * they get the full container filename now and also use them in UI * they call do=modify to invoke the drawing applet multiconfig: removed drawing_action text_moin_wiki parser: use wikiutil.drawing2fname to process the given drawing name. if it looks like fully qualified (e.g. foo.tdraw, foo.adraw, foo.svg, foo.png, ...), then keep it. otherwise (e.g. foo, foo.bar, ...) append .tdraw as default drawing filename extension to be backwards compatible.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 13 Sep 2009 16:01:09 +0200
parents 3aed6e5c26e5
children 61ce73eb13a0
line wrap: on
line diff
--- a/MoinMoin/action/info.py	Sun Sep 13 02:44:37 2009 +0200
+++ b/MoinMoin/action/info.py	Sun Sep 13 16:01:09 2009 +0200
@@ -13,6 +13,7 @@
 from MoinMoin.Page import Page
 from MoinMoin.logfile import editlog
 from MoinMoin.widget import html
+from MoinMoin.action import AttachFile
 
 def execute(pagename, request):
     """ show misc. infos about a page """
@@ -101,6 +102,16 @@
             kw.update(dict(rel='nofollow'))
             return page.link_to(request, text, querystr=query, **kw)
 
+        def render_file_action(text, pagename, filename, request, do):
+            url = AttachFile.getAttachUrl(pagename, filename, request, do=do)
+            if url:
+                f = request.formatter
+                link = f.url(1, url) + f.text(text) + f.url(0)
+                return link
+
+        may_write = request.user.may.write(pagename)
+        may_delete = request.user.may.delete(pagename)
+
         # read in the complete log of this page
         log = editlog.EditLog(request, rootpagename=pagename)
         count = 0
@@ -135,25 +146,16 @@
 
                 filename = wikiutil.url_unquote(line.extra)
                 comment = "%s: %s %s" % (line.action, filename, line.comment)
-                size = 0
-                if line.action != 'ATTDEL':
-                    from MoinMoin.action import AttachFile
-                    if AttachFile.exists(request, pagename, filename):
-                        size = AttachFile.size(request, pagename, filename)
-                    if line.action == 'ATTNEW':
-                        actions.append(render_action(_('view'), {'action': 'AttachFile', 'do': 'view', 'target': '%s' % filename}))
-                    elif line.action == 'ATTDRW':
-                        if filename.endswith('.tdraw'):
-                            action = 'twikidraw'
-                            target = filename[:-6]
-                        elif filename.endswith('.adraw'):
-                            action = 'anywikidraw'
-                            target = filename[:-6]
-                        actions.append(render_action(_('edit'), dict(action=action, target=target)))
-
-                    actions.append(render_action(_('get'), {'action': 'AttachFile', 'do': 'get', 'target': '%s' % filename}))
-                    if request.user.may.delete(pagename):
-                        actions.append(render_action(_('del'), {'action': 'AttachFile', 'do': 'del', 'target': '%s' % filename}))
+                if AttachFile.exists(request, pagename, filename):
+                    size = AttachFile.size(request, pagename, filename)
+                    actions.append(render_file_action(_('view'), pagename, filename, request, do='view'))
+                    actions.append(render_file_action(_('get'), pagename, filename, request, do='get'))
+                    if may_delete:
+                        actions.append(render_file_action(_('del'), pagename, filename, request, do='del'))
+                    if may_write:
+                        actions.append(render_file_action(_('edit'), pagename, filename, request, do='modify'))
+                else:
+                    size = 0
 
             history.addRow((
                 rev,
@@ -162,7 +164,7 @@
                 diff,
                 line.getEditor(request) or _("N/A"),
                 wikiutil.escape(comment) or '&nbsp;',
-                "&nbsp;".join(actions),
+                "&nbsp;".join(a for a in actions if a),
             ))
             count += 1
             if count >= max_count: