comparison 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
comparison
equal deleted inserted replaced
5101:d8ccac2f24c5 5102:9ae242080889
11 11
12 from MoinMoin import config, wikiutil, action 12 from MoinMoin import config, wikiutil, action
13 from MoinMoin.Page import Page 13 from MoinMoin.Page import Page
14 from MoinMoin.logfile import editlog 14 from MoinMoin.logfile import editlog
15 from MoinMoin.widget import html 15 from MoinMoin.widget import html
16 from MoinMoin.action import AttachFile
16 17
17 def execute(pagename, request): 18 def execute(pagename, request):
18 """ show misc. infos about a page """ 19 """ show misc. infos about a page """
19 if not request.user.may.read(pagename): 20 if not request.user.may.read(pagename):
20 Page(request, pagename).send_page() 21 Page(request, pagename).send_page()
98 # generate history list 99 # generate history list
99 100
100 def render_action(text, query, **kw): 101 def render_action(text, query, **kw):
101 kw.update(dict(rel='nofollow')) 102 kw.update(dict(rel='nofollow'))
102 return page.link_to(request, text, querystr=query, **kw) 103 return page.link_to(request, text, querystr=query, **kw)
104
105 def render_file_action(text, pagename, filename, request, do):
106 url = AttachFile.getAttachUrl(pagename, filename, request, do=do)
107 if url:
108 f = request.formatter
109 link = f.url(1, url) + f.text(text) + f.url(0)
110 return link
111
112 may_write = request.user.may.write(pagename)
113 may_delete = request.user.may.delete(pagename)
103 114
104 # read in the complete log of this page 115 # read in the complete log of this page
105 log = editlog.EditLog(request, rootpagename=pagename) 116 log = editlog.EditLog(request, rootpagename=pagename)
106 count = 0 117 count = 0
107 pgactioncount = 0 118 pgactioncount = 0
133 rev = '-' 144 rev = '-'
134 diff = '-' 145 diff = '-'
135 146
136 filename = wikiutil.url_unquote(line.extra) 147 filename = wikiutil.url_unquote(line.extra)
137 comment = "%s: %s %s" % (line.action, filename, line.comment) 148 comment = "%s: %s %s" % (line.action, filename, line.comment)
138 size = 0 149 if AttachFile.exists(request, pagename, filename):
139 if line.action != 'ATTDEL': 150 size = AttachFile.size(request, pagename, filename)
140 from MoinMoin.action import AttachFile 151 actions.append(render_file_action(_('view'), pagename, filename, request, do='view'))
141 if AttachFile.exists(request, pagename, filename): 152 actions.append(render_file_action(_('get'), pagename, filename, request, do='get'))
142 size = AttachFile.size(request, pagename, filename) 153 if may_delete:
143 if line.action == 'ATTNEW': 154 actions.append(render_file_action(_('del'), pagename, filename, request, do='del'))
144 actions.append(render_action(_('view'), {'action': 'AttachFile', 'do': 'view', 'target': '%s' % filename})) 155 if may_write:
145 elif line.action == 'ATTDRW': 156 actions.append(render_file_action(_('edit'), pagename, filename, request, do='modify'))
146 if filename.endswith('.tdraw'): 157 else:
147 action = 'twikidraw' 158 size = 0
148 target = filename[:-6]
149 elif filename.endswith('.adraw'):
150 action = 'anywikidraw'
151 target = filename[:-6]
152 actions.append(render_action(_('edit'), dict(action=action, target=target)))
153
154 actions.append(render_action(_('get'), {'action': 'AttachFile', 'do': 'get', 'target': '%s' % filename}))
155 if request.user.may.delete(pagename):
156 actions.append(render_action(_('del'), {'action': 'AttachFile', 'do': 'del', 'target': '%s' % filename}))
157 159
158 history.addRow(( 160 history.addRow((
159 rev, 161 rev,
160 request.user.getFormattedDateTime(wikiutil.version2timestamp(line.ed_time_usecs)), 162 request.user.getFormattedDateTime(wikiutil.version2timestamp(line.ed_time_usecs)),
161 str(size), 163 str(size),
162 diff, 164 diff,
163 line.getEditor(request) or _("N/A"), 165 line.getEditor(request) or _("N/A"),
164 wikiutil.escape(comment) or '&nbsp;', 166 wikiutil.escape(comment) or '&nbsp;',
165 "&nbsp;".join(actions), 167 "&nbsp;".join(a for a in actions if a),
166 )) 168 ))
167 count += 1 169 count += 1
168 if count >= max_count: 170 if count >= max_count:
169 break 171 break
170 172