annotate MoinMoin/action/AttachFile.py @ 1988:dbf2b7426385

fixed some pylint warnings
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 10 Apr 2007 00:13:49 +0200
parents 07aff6369476
children 6d6379c9a1c9
rev   line source
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
2 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
3 MoinMoin - AttachFile action
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
4
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
5 This action lets a page have multiple attachment files.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
6 It creates a folder <data>/pages/<pagename>/attachments
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
7 and keeps everything in there.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
8
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
9 Form values: action=Attachment
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
10 1. with no 'do' key: returns file upload form
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
11 2. do=attach: accept file upload and saves the file in
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
12 ../attachment/pagename/
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
13 3. /pagename/fname?action=Attachment&do=get[&mimetype=type]:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
14 return contents of the attachment file with the name fname.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
15 4. /pathname/fname, do=view[&mimetype=type]:create a page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
16 to view the content of the file
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
17
1911
0b2ad3099fcf AttachFile.size to reduce code duplication, fixed docstring
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1910
diff changeset
18 To insert an attachment into the page, use the "attachment:" pseudo schema.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
19
1911
0b2ad3099fcf AttachFile.size to reduce code duplication, fixed docstring
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1910
diff changeset
20 @copyright: 2001 by Ken Sugino (sugino@mediaone.net),
1918
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1911
diff changeset
21 2001-2004 by Juergen Hermann <jh@web.de>,
1911
0b2ad3099fcf AttachFile.size to reduce code duplication, fixed docstring
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1910
diff changeset
22 2005 MoinMoin:AlexanderSchremmer,
0b2ad3099fcf AttachFile.size to reduce code duplication, fixed docstring
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1910
diff changeset
23 2005 DiegoOngaro at ETSZONE (diego@etszone.com),
1952
8ab85e3711dc AttachFile:send_viewfile extended for mimetypes presentable by EmbedObject
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1920
diff changeset
24 2005-2007 MoinMoin:ReimarBauer,
1911
0b2ad3099fcf AttachFile.size to reduce code duplication, fixed docstring
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1910
diff changeset
25 2007 MoinMoin:ThomasWaldmann
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
26 @license: GNU GPL, see COPYING for details.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
27 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
28
1952
8ab85e3711dc AttachFile:send_viewfile extended for mimetypes presentable by EmbedObject
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1920
diff changeset
29 import os, time, zipfile, mimetypes
1791
6dd2e29acffe Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1777
diff changeset
30 from MoinMoin import config, wikiutil, packages
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
31 from MoinMoin.Page import Page
1115
a349adcabffe 304 response support for attached files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1068
diff changeset
32 from MoinMoin.util import filesys, timefuncs
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
33
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
34 action_name = __name__.split('.')[-1]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
35
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
36 def htdocs_access(request):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
37 return isinstance(request.cfg.attachments, type({}))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
38
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
39
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
40 #############################################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
41 ### External interface - these are called from the core code
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
42 #############################################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
43
691
f18b06c790d4 Refactored adding attachments.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 623
diff changeset
44 class AttachmentAlreadyExists(Exception):
f18b06c790d4 Refactored adding attachments.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 623
diff changeset
45 pass
f18b06c790d4 Refactored adding attachments.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 623
diff changeset
46
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
47 def getBasePath(request):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
48 """ Get base path where page dirs for attachments are stored.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
49 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
50 if htdocs_access(request):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
51 return request.cfg.attachments['dir']
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
52 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
53 return request.rootpage.getPagePath('pages')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
54
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
55
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
56 def getAttachDir(request, pagename, create=0):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
57 """ Get directory where attachments for page `pagename` are stored.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
58 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
59 if htdocs_access(request):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
60 # direct file access via webserver, from public htdocs area
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
61 pagename = wikiutil.quoteWikinameFS(pagename)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
62 attach_dir = os.path.join(request.cfg.attachments['dir'], pagename, "attachments")
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
63 if create and not os.path.isdir(attach_dir):
1428
8a89649ab5f0 remove util.filesys.make[dD]irs - not needed any more due to os.umask() use
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1419
diff changeset
64 os.makedirs(attach_dir)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
65 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
66 # send file via CGI, from page storage area
1904
82667e81b928 Fix crash in AttachFile when called by xmlrpc and request.page is None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1891
diff changeset
67 if request.page and pagename == request.page.page_name:
1952
8ab85e3711dc AttachFile:send_viewfile extended for mimetypes presentable by EmbedObject
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1920
diff changeset
68 page = request.page # reusing existing page obj is faster
1813
dca96e7c8199 reuse existing page object
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1798
diff changeset
69 else:
dca96e7c8199 reuse existing page object
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1798
diff changeset
70 page = Page(request, pagename)
dca96e7c8199 reuse existing page object
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1798
diff changeset
71 attach_dir = page.getPagePath("attachments", check_create=create)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
72
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
73 return attach_dir
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
74
143
11df1156d432 fixed MoinMoinBugs/BrokenAttachmentPaths
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 118
diff changeset
75 def absoluteName(url, pagename):
281
8155e50e94ca fixed crash with non-ASCII attachment filename
Thomas Waldmann <tw@waldmann-edv.de>
parents: 280
diff changeset
76 """ Get (pagename, filename) of an attachment: link
8155e50e94ca fixed crash with non-ASCII attachment filename
Thomas Waldmann <tw@waldmann-edv.de>
parents: 280
diff changeset
77 @param url: PageName/filename.ext or filename.ext (unicode)
8155e50e94ca fixed crash with non-ASCII attachment filename
Thomas Waldmann <tw@waldmann-edv.de>
parents: 280
diff changeset
78 @param pagename: name of the currently processed page (unicode)
8155e50e94ca fixed crash with non-ASCII attachment filename
Thomas Waldmann <tw@waldmann-edv.de>
parents: 280
diff changeset
79 @rtype: tuple of unicode
8155e50e94ca fixed crash with non-ASCII attachment filename
Thomas Waldmann <tw@waldmann-edv.de>
parents: 280
diff changeset
80 @return: PageName, filename.ext
143
11df1156d432 fixed MoinMoinBugs/BrokenAttachmentPaths
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 118
diff changeset
81 """
281
8155e50e94ca fixed crash with non-ASCII attachment filename
Thomas Waldmann <tw@waldmann-edv.de>
parents: 280
diff changeset
82 pieces = url.split(u'/')
8155e50e94ca fixed crash with non-ASCII attachment filename
Thomas Waldmann <tw@waldmann-edv.de>
parents: 280
diff changeset
83 if len(pieces) == 1:
143
11df1156d432 fixed MoinMoinBugs/BrokenAttachmentPaths
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 118
diff changeset
84 return pagename, pieces[0]
11df1156d432 fixed MoinMoinBugs/BrokenAttachmentPaths
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 118
diff changeset
85 else:
145
b11bb396654e make Attachment fix run with Py 2.3
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 143
diff changeset
86 return u"/".join(pieces[:-1]), pieces[-1]
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
87
1611
435e0748d573 getAttachUrl gets an optional parameter for do='get' or do='view'
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1610
diff changeset
88 def getAttachUrl(pagename, filename, request, addts=0, escaped=0, do='get'):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
89 """ Get URL that points to attachment `filename` of page `pagename`.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
90
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
91 If 'addts' is true, a timestamp with the file's modification time
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
92 is added, so that browsers reload a changed file.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
93 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
94 if htdocs_access(request):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
95 # direct file access via webserver
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
96 timestamp = ''
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
97 if addts:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
98 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
99 timestamp = '?ts=%s' % os.path.getmtime(
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
100 getFilename(request, pagename, filename))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
101 except IOError:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
102 pass
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
103
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
104 url = "%s/%s/attachments/%s%s" % (
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
105 request.cfg.attachments['url'], wikiutil.quoteWikinameFS(pagename),
101
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 80
diff changeset
106 wikiutil.url_quote(filename), timestamp)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
107 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
108 # send file via CGI
1611
435e0748d573 getAttachUrl gets an optional parameter for do='get' or do='view'
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1610
diff changeset
109 if do not in ['get', 'view']:
435e0748d573 getAttachUrl gets an optional parameter for do='get' or do='view'
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1610
diff changeset
110 do = 'get'
435e0748d573 getAttachUrl gets an optional parameter for do='get' or do='view'
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1610
diff changeset
111
435e0748d573 getAttachUrl gets an optional parameter for do='get' or do='view'
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1610
diff changeset
112 url = "%s/%s?action=%s&do=%s&target=%s" % (
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
113 request.getScriptname(), wikiutil.quoteWikinameURL(pagename),
1611
435e0748d573 getAttachUrl gets an optional parameter for do='get' or do='view'
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1610
diff changeset
114 action_name, do, wikiutil.url_quote_plus(filename))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
115 if escaped:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
116 url = wikiutil.escape(url)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
117 return url
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
118
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
119 def getIndicator(request, pagename):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
120 """ Get an attachment indicator for a page (linked clip image) or
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
121 an empty string if not attachments exist.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
122 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
123 _ = request.getText
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
124 attach_dir = getAttachDir(request, pagename)
1920
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
125 if not os.path.exists(attach_dir):
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
126 return ''
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
127
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
128 files = os.listdir(attach_dir)
1920
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
129 if not files:
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
130 return ''
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
131
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
132 attach_count = _('[%d attachments]') % len(files)
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
133 attach_icon = request.theme.make_icon('attach', vars={'attach_count': attach_count})
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
134 attach_link = wikiutil.link_tag(request,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
135 "%s?action=AttachFile" % wikiutil.quoteWikinameURL(pagename),
869
0152984f76ee use rel nofollow for action links
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 802
diff changeset
136 attach_icon,
0152984f76ee use rel nofollow for action links
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 802
diff changeset
137 request.formatter, rel='nofollow')
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
138
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
139 return attach_link
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
140
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
141
281
8155e50e94ca fixed crash with non-ASCII attachment filename
Thomas Waldmann <tw@waldmann-edv.de>
parents: 280
diff changeset
142 def getFilename(request, pagename, filename):
8155e50e94ca fixed crash with non-ASCII attachment filename
Thomas Waldmann <tw@waldmann-edv.de>
parents: 280
diff changeset
143 """ make complete pathfilename of file "name" attached to some page "pagename"
8155e50e94ca fixed crash with non-ASCII attachment filename
Thomas Waldmann <tw@waldmann-edv.de>
parents: 280
diff changeset
144 @param request: request object
8155e50e94ca fixed crash with non-ASCII attachment filename
Thomas Waldmann <tw@waldmann-edv.de>
parents: 280
diff changeset
145 @param pagename: name of page where the file is attached to (unicode)
8155e50e94ca fixed crash with non-ASCII attachment filename
Thomas Waldmann <tw@waldmann-edv.de>
parents: 280
diff changeset
146 @param filename: filename of attached file (unicode)
8155e50e94ca fixed crash with non-ASCII attachment filename
Thomas Waldmann <tw@waldmann-edv.de>
parents: 280
diff changeset
147 @rtype: string (in config.charset encoding)
8155e50e94ca fixed crash with non-ASCII attachment filename
Thomas Waldmann <tw@waldmann-edv.de>
parents: 280
diff changeset
148 @return: complete path/filename of attached file
8155e50e94ca fixed crash with non-ASCII attachment filename
Thomas Waldmann <tw@waldmann-edv.de>
parents: 280
diff changeset
149 """
1911
0b2ad3099fcf AttachFile.size to reduce code duplication, fixed docstring
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1910
diff changeset
150 if isinstance(filename, unicode):
0b2ad3099fcf AttachFile.size to reduce code duplication, fixed docstring
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1910
diff changeset
151 filename = filename.encode(config.charset)
0b2ad3099fcf AttachFile.size to reduce code duplication, fixed docstring
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1910
diff changeset
152 return os.path.join(getAttachDir(request, pagename), filename)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
153
1910
5c3dffe2abf1 new function AttachFile.exists to reduce code duplication
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1904
diff changeset
154 def exists(request, pagename, filename):
5c3dffe2abf1 new function AttachFile.exists to reduce code duplication
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1904
diff changeset
155 """ check if page <pagename> has a file <filename> attached """
5c3dffe2abf1 new function AttachFile.exists to reduce code duplication
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1904
diff changeset
156 fpath = getFilename(request, pagename, filename)
5c3dffe2abf1 new function AttachFile.exists to reduce code duplication
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1904
diff changeset
157 return os.path.exists(fpath)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
158
1911
0b2ad3099fcf AttachFile.size to reduce code duplication, fixed docstring
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1910
diff changeset
159 def size(request, pagename, filename):
0b2ad3099fcf AttachFile.size to reduce code duplication, fixed docstring
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1910
diff changeset
160 """ return file size of file attachment """
0b2ad3099fcf AttachFile.size to reduce code duplication, fixed docstring
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1910
diff changeset
161 fpath = getFilename(request, pagename, filename)
0b2ad3099fcf AttachFile.size to reduce code duplication, fixed docstring
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1910
diff changeset
162 return os.path.getsize(fpath)
0b2ad3099fcf AttachFile.size to reduce code duplication, fixed docstring
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1910
diff changeset
163
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
164 def info(pagename, request):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
165 """ Generate snippet with info on the attachment for page `pagename`.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
166 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
167 _ = request.getText
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
168
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
169 attach_dir = getAttachDir(request, pagename)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
170 files = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
171 if os.path.isdir(attach_dir):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
172 files = os.listdir(attach_dir)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
173 page = Page(request, pagename)
1816
4a31739bc6e1 Page.url(): removed escaping support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1813
diff changeset
174 link = page.url(request, {'action': 'AttachFile'})
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
175 attach_info = _('There are <a href="%(link)s">%(count)s attachment(s)</a> stored for this page.', formatted=False) % {
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
176 'count': len(files),
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
177 'link': wikiutil.escape(link)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
178 }
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
179 return "\n<p>\n%s\n</p>\n" % attach_info
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
180
1791
6dd2e29acffe Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1777
diff changeset
181 def add_attachment(request, pagename, target, filecontent, overwrite=0):
691
f18b06c790d4 Refactored adding attachments.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 623
diff changeset
182 # replace illegal chars
1797
25c93ded258b AttachFile: getText of add_attachment fixed, Load:only PageEditor restricts uploading of pages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1796
diff changeset
183
25c93ded258b AttachFile: getText of add_attachment fixed, Load:only PageEditor restricts uploading of pages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1796
diff changeset
184 _ = request.getText
25c93ded258b AttachFile: getText of add_attachment fixed, Load:only PageEditor restricts uploading of pages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1796
diff changeset
185
691
f18b06c790d4 Refactored adding attachments.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 623
diff changeset
186 target = wikiutil.taintfilename(target)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
187
691
f18b06c790d4 Refactored adding attachments.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 623
diff changeset
188 # set mimetype from extension, or from given mimetype
802
7b2e550c9660 merge moin/1.6
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 801 691
diff changeset
189 #type, encoding = wikiutil.guess_type(target)
691
f18b06c790d4 Refactored adding attachments.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 623
diff changeset
190 #if not type:
f18b06c790d4 Refactored adding attachments.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 623
diff changeset
191 # ext = None
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1866
diff changeset
192 # if 'mime' in request.form:
802
7b2e550c9660 merge moin/1.6
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 801 691
diff changeset
193 # ext = wikiutil.guess_extension(request.form['mime'][0])
691
f18b06c790d4 Refactored adding attachments.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 623
diff changeset
194 # if not ext:
802
7b2e550c9660 merge moin/1.6
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 801 691
diff changeset
195 # type, encoding = wikiutil.guess_type(filename)
691
f18b06c790d4 Refactored adding attachments.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 623
diff changeset
196 # if type:
802
7b2e550c9660 merge moin/1.6
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 801 691
diff changeset
197 # ext = wikiutil.guess_extension(type)
691
f18b06c790d4 Refactored adding attachments.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 623
diff changeset
198 # else:
f18b06c790d4 Refactored adding attachments.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 623
diff changeset
199 # ext = ''
f18b06c790d4 Refactored adding attachments.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 623
diff changeset
200 # target = target + ext
f18b06c790d4 Refactored adding attachments.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 623
diff changeset
201
f18b06c790d4 Refactored adding attachments.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 623
diff changeset
202 # get directory, and possibly create it
f18b06c790d4 Refactored adding attachments.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 623
diff changeset
203 attach_dir = getAttachDir(request, pagename, create=1)
f18b06c790d4 Refactored adding attachments.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 623
diff changeset
204 # save file
f18b06c790d4 Refactored adding attachments.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 623
diff changeset
205 fpath = os.path.join(attach_dir, target).encode(config.charset)
1765
6e438de156d9 AttachFile: allow overwriting files when user chooses that option (ported from 1.5-802)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1662
diff changeset
206 exists = os.path.exists(fpath)
6e438de156d9 AttachFile: allow overwriting files when user chooses that option (ported from 1.5-802)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1662
diff changeset
207 if exists and not overwrite:
1791
6dd2e29acffe Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1777
diff changeset
208 msg = _("Attachment '%(target)s' already exists.") % { 'target': target, }
691
f18b06c790d4 Refactored adding attachments.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 623
diff changeset
209 else:
1765
6e438de156d9 AttachFile: allow overwriting files when user chooses that option (ported from 1.5-802)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1662
diff changeset
210 if exists:
6e438de156d9 AttachFile: allow overwriting files when user chooses that option (ported from 1.5-802)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1662
diff changeset
211 try:
6e438de156d9 AttachFile: allow overwriting files when user chooses that option (ported from 1.5-802)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1662
diff changeset
212 os.remove(fpath)
6e438de156d9 AttachFile: allow overwriting files when user chooses that option (ported from 1.5-802)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1662
diff changeset
213 except:
6e438de156d9 AttachFile: allow overwriting files when user chooses that option (ported from 1.5-802)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1662
diff changeset
214 pass
691
f18b06c790d4 Refactored adding attachments.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 623
diff changeset
215 stream = open(fpath, 'wb')
f18b06c790d4 Refactored adding attachments.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 623
diff changeset
216 try:
f18b06c790d4 Refactored adding attachments.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 623
diff changeset
217 stream.write(filecontent)
f18b06c790d4 Refactored adding attachments.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 623
diff changeset
218 finally:
f18b06c790d4 Refactored adding attachments.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 623
diff changeset
219 stream.close()
f18b06c790d4 Refactored adding attachments.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 623
diff changeset
220
f18b06c790d4 Refactored adding attachments.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 623
diff changeset
221 _addLogEntry(request, 'ATTNEW', pagename, target)
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
222
1473
b5864c9492fb ensure new attachments trigger an index update, doc update for MoinMoin.search.Xapian
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1318
diff changeset
223 if request.cfg.xapian_search:
b5864c9492fb ensure new attachments trigger an index update, doc update for MoinMoin.search.Xapian
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1318
diff changeset
224 from MoinMoin.search.Xapian import Index
b5864c9492fb ensure new attachments trigger an index update, doc update for MoinMoin.search.Xapian
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1318
diff changeset
225 index = Index(request)
b5864c9492fb ensure new attachments trigger an index update, doc update for MoinMoin.search.Xapian
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1318
diff changeset
226 if index.exists():
b5864c9492fb ensure new attachments trigger an index update, doc update for MoinMoin.search.Xapian
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1318
diff changeset
227 index.update_page(pagename)
b5864c9492fb ensure new attachments trigger an index update, doc update for MoinMoin.search.Xapian
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1318
diff changeset
228
691
f18b06c790d4 Refactored adding attachments.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 623
diff changeset
229 return target
802
7b2e550c9660 merge moin/1.6
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 801 691
diff changeset
230
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
231
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
232 #############################################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
233 ### Internal helpers
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
234 #############################################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
235
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
236 def _addLogEntry(request, action, pagename, filename):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
237 """ Add an entry to the edit log on uploads and deletes.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
238
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
239 `action` should be "ATTNEW" or "ATTDEL"
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
240 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
241 from MoinMoin.logfile import editlog
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
242 t = wikiutil.timestamp2version(time.time())
101
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 80
diff changeset
243 fname = wikiutil.url_quote(filename, want_unicode=True)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
244
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
245 # Write to global log
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
246 log = editlog.EditLog(request)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
247 log.add(request, t, 99999999, action, pagename, request.remote_addr, fname)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
248
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
249 # Write to local log
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
250 log = editlog.EditLog(request, rootpagename=pagename)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
251 log.add(request, t, 99999999, action, pagename, request.remote_addr, fname)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
252
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
253
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
254 def _access_file(pagename, request):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
255 """ Check form parameter `target` and return a tuple of
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
256 `(filename, filepath)` for an existing attachment.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
257
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
258 Return `(None, None)` if an error occurs.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
259 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
260 _ = request.getText
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
261
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
262 error = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
263 if not request.form.get('target', [''])[0]:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
264 error = _("Filename of attachment not specified!")
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
265 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
266 filename = wikiutil.taintfilename(request.form['target'][0])
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
267 fpath = getFilename(request, pagename, filename)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
268
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
269 if os.path.isfile(fpath):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
270 return (filename, fpath)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
271 error = _("Attachment '%(filename)s' does not exist!") % {'filename': filename}
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
272
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
273 error_msg(pagename, request, error)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
274 return (None, None)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
275
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
276
1653
5b15b6e010cf AttachList can list files of given mimetype now (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1635
diff changeset
277 def _build_filelist(request, pagename, showheader, readonly, mime_type='*'):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
278 _ = request.getText
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
279
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
280 # access directory
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
281 attach_dir = getAttachDir(request, pagename)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
282 files = _get_files(request, pagename)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
283
1653
5b15b6e010cf AttachList can list files of given mimetype now (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1635
diff changeset
284 if mime_type != '*':
5b15b6e010cf AttachList can list files of given mimetype now (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1635
diff changeset
285 files = [fname for fname in files if mime_type == mimetypes.guess_type(fname)[0]]
5b15b6e010cf AttachList can list files of given mimetype now (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1635
diff changeset
286
1920
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
287 html = ""
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
288 if files:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
289 if showheader:
1920
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
290 html += _(
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
291 "To refer to attachments on a page, use '''{{{attachment:filename}}}''', \n"
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
292 "as shown below in the list of files. \n"
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
293 "Do '''NOT''' use the URL of the {{{[get]}}} link, \n"
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
294 "since this is subject to change and can break easily."
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
295 )
1920
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
296 html += "<ul>"
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
297
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
298 label_del = _("del")
1608
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
299 label_move = _("move")
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
300 label_get = _("get")
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
301 label_edit = _("edit")
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
302 label_view = _("view")
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
303 label_unzip = _("unzip")
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
304 label_install = _("install")
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
305
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
306 for file in files:
1985
eb5328be394e AttachFile:destinguish between zip and other fileformats using zip archives
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1967
diff changeset
307 mt = wikiutil.MimeType(filename=file)
1864
2b24220424fa AttachFile: also show file mtime in attachment list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1833
diff changeset
308 st = os.stat(os.path.join(attach_dir, file).encode(config.charset))
2b24220424fa AttachFile: also show file mtime in attachment list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1833
diff changeset
309 fsize = "%.1f" % (float(st.st_size) / 1024)
2b24220424fa AttachFile: also show file mtime in attachment list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1833
diff changeset
310 fmtime = request.user.getFormattedDateTime(st.st_mtime)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
311 baseurl = request.getScriptname()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
312 action = action_name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
313 urlpagename = wikiutil.quoteWikinameURL(pagename)
101
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 80
diff changeset
314 urlfile = wikiutil.url_quote_plus(file)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
315
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
316 base, ext = os.path.splitext(file)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
317 get_url = getAttachUrl(pagename, file, request, escaped=1)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
318 parmdict = {'baseurl': baseurl, 'urlpagename': urlpagename, 'action': action,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
319 'urlfile': urlfile, 'label_del': label_del,
1608
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
320 'label_move': label_move,
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
321 'base': base, 'label_edit': label_edit,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
322 'label_view': label_view,
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
323 'label_unzip': label_unzip,
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
324 'label_install': label_install,
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
325 'get_url': get_url, 'label_get': label_get,
375
6f8d4ca0ef6e show attachment: samples with %20 in attachment list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 373
diff changeset
326 'file': wikiutil.escape(file).replace(' ', '%20'),
6f8d4ca0ef6e show attachment: samples with %20 in attachment list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 373
diff changeset
327 'fsize': fsize,
1864
2b24220424fa AttachFile: also show file mtime in attachment list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1833
diff changeset
328 'fmtime': fmtime,
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
329 'pagename': pagename}
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
330
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
331 del_link = ''
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
332 if request.user.may.delete(pagename) and not readonly:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
333 del_link = '<a href="%(baseurl)s/%(urlpagename)s' \
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
334 '?action=%(action)s&amp;do=del&amp;target=%(urlfile)s">%(label_del)s</a>&nbsp;| ' % parmdict
1608
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
335 if request.user.may.delete(pagename) and not readonly:
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
336 move_link = '<a href="%(baseurl)s/%(urlpagename)s' \
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
337 '?action=%(action)s&amp;do=move&amp;target=%(urlfile)s">%(label_move)s</a>&nbsp;| ' % parmdict
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
338 else:
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
339 move_link = ''
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
340 if ext == '.draw':
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
341 viewlink = '<a href="%(baseurl)s/%(urlpagename)s?action=%(action)s&amp;drawing=%(base)s">%(label_edit)s</a>' % parmdict
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
342 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
343 viewlink = '<a href="%(baseurl)s/%(urlpagename)s?action=%(action)s&amp;do=view&amp;target=%(urlfile)s">%(label_view)s</a>' % parmdict
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
344
1985
eb5328be394e AttachFile:destinguish between zip and other fileformats using zip archives
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1967
diff changeset
345 if (packages.ZipPackage(request, os.path.join(attach_dir, file).encode(config.charset)).isPackage() and mt.minor == 'zip' and
448
45924beef130 user.isSuperUser() check, require cfg.superuser being a list or tuple
Thomas Waldmann <tw@waldmann-edv.de>
parents: 391
diff changeset
346 request.user.isSuperUser()):
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
347 viewlink += ' | <a href="%(baseurl)s/%(urlpagename)s?action=%(action)s&amp;do=install&amp;target=%(urlfile)s">%(label_install)s</a>' % parmdict
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
348 elif (zipfile.is_zipfile(os.path.join(attach_dir, file).encode(config.charset)) and
1985
eb5328be394e AttachFile:destinguish between zip and other fileformats using zip archives
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1967
diff changeset
349 mt.minor == 'zip' and request.user.may.read(pagename) and request.user.may.delete(pagename)
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
350 and request.user.may.write(pagename)):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
351 viewlink += ' | <a href="%(baseurl)s/%(urlpagename)s?action=%(action)s&amp;do=unzip&amp;target=%(urlfile)s">%(label_unzip)s</a>' % parmdict
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
352
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
353
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
354 parmdict['viewlink'] = viewlink
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
355 parmdict['del_link'] = del_link
1608
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
356 parmdict['move_link'] = move_link
1920
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
357 html += ('<li>[%(del_link)s%(move_link)s'
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
358 '<a href="%(get_url)s">%(label_get)s</a>&nbsp;| %(viewlink)s]'
1864
2b24220424fa AttachFile: also show file mtime in attachment list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1833
diff changeset
359 ' (%(fmtime)s, %(fsize)s KB) attachment:<strong>%(file)s</strong></li>') % parmdict
1920
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
360 html += "</ul>"
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
361 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
362 if showheader:
1920
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
363 html += '<p>%s</p>' % (_("No attachments stored for %(pagename)s") % {'pagename': wikiutil.escape(pagename)})
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
364
1920
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
365 return html
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
366
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
367
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
368 def _get_files(request, pagename):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
369 attach_dir = getAttachDir(request, pagename)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
370 if os.path.isdir(attach_dir):
1866
0194beaf511e reduce reduce, filter and map usage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1864
diff changeset
371 files = [fn.decode(config.charset) for fn in os.listdir(attach_dir)]
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
372 files.sort()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
373 return files
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
374 return []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
375
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
376
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
377 def _get_filelist(request, pagename):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
378 return _build_filelist(request, pagename, 1, 0)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
379
280
015c945277ec "Winzip compat ?patch" - Allow a .zip file to have a directory in it if it is the only one. Thanks Diego Ongaro.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 145
diff changeset
380 def _subdir_exception(zf):
015c945277ec "Winzip compat ?patch" - Allow a .zip file to have a directory in it if it is the only one. Thanks Diego Ongaro.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 145
diff changeset
381 """
015c945277ec "Winzip compat ?patch" - Allow a .zip file to have a directory in it if it is the only one. Thanks Diego Ongaro.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 145
diff changeset
382 Checks for the existance of one common subdirectory shared among
015c945277ec "Winzip compat ?patch" - Allow a .zip file to have a directory in it if it is the only one. Thanks Diego Ongaro.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 145
diff changeset
383 all files in the zip file. If this is the case, returns a dict of
015c945277ec "Winzip compat ?patch" - Allow a .zip file to have a directory in it if it is the only one. Thanks Diego Ongaro.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 145
diff changeset
384 original names to modified names so that such files can be unpacked
015c945277ec "Winzip compat ?patch" - Allow a .zip file to have a directory in it if it is the only one. Thanks Diego Ongaro.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 145
diff changeset
385 as the user would expect.
015c945277ec "Winzip compat ?patch" - Allow a .zip file to have a directory in it if it is the only one. Thanks Diego Ongaro.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 145
diff changeset
386 """
015c945277ec "Winzip compat ?patch" - Allow a .zip file to have a directory in it if it is the only one. Thanks Diego Ongaro.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 145
diff changeset
387
015c945277ec "Winzip compat ?patch" - Allow a .zip file to have a directory in it if it is the only one. Thanks Diego Ongaro.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 145
diff changeset
388 b = zf.namelist()
015c945277ec "Winzip compat ?patch" - Allow a .zip file to have a directory in it if it is the only one. Thanks Diego Ongaro.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 145
diff changeset
389 if not '/' in b[0]:
015c945277ec "Winzip compat ?patch" - Allow a .zip file to have a directory in it if it is the only one. Thanks Diego Ongaro.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 145
diff changeset
390 return False #No directory
015c945277ec "Winzip compat ?patch" - Allow a .zip file to have a directory in it if it is the only one. Thanks Diego Ongaro.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 145
diff changeset
391 slashoffset = b[0].index('/')
015c945277ec "Winzip compat ?patch" - Allow a .zip file to have a directory in it if it is the only one. Thanks Diego Ongaro.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 145
diff changeset
392 directory = b[0][:slashoffset]
015c945277ec "Winzip compat ?patch" - Allow a .zip file to have a directory in it if it is the only one. Thanks Diego Ongaro.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 145
diff changeset
393 for origname in b:
015c945277ec "Winzip compat ?patch" - Allow a .zip file to have a directory in it if it is the only one. Thanks Diego Ongaro.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 145
diff changeset
394 if origname.rfind('/') != slashoffset or origname[:slashoffset] != directory:
015c945277ec "Winzip compat ?patch" - Allow a .zip file to have a directory in it if it is the only one. Thanks Diego Ongaro.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 145
diff changeset
395 return False #Multiple directories or different directory
015c945277ec "Winzip compat ?patch" - Allow a .zip file to have a directory in it if it is the only one. Thanks Diego Ongaro.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 145
diff changeset
396 names = {}
015c945277ec "Winzip compat ?patch" - Allow a .zip file to have a directory in it if it is the only one. Thanks Diego Ongaro.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 145
diff changeset
397 for origname in b:
015c945277ec "Winzip compat ?patch" - Allow a .zip file to have a directory in it if it is the only one. Thanks Diego Ongaro.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 145
diff changeset
398 names[origname] = origname[slashoffset+1:]
015c945277ec "Winzip compat ?patch" - Allow a .zip file to have a directory in it if it is the only one. Thanks Diego Ongaro.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 145
diff changeset
399 return names #Returns dict of {origname: safename}
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
400
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
401 def error_msg(pagename, request, msg):
1777
ed44b93599b5 remove unneeded request param from page.send_page()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1766
diff changeset
402 Page(request, pagename).send_page(msg=msg)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
403
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
404
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
405 #############################################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
406 ### Create parts of the Web interface
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
407 #############################################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
408
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
409 def send_link_rel(request, pagename):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
410 files = _get_files(request, pagename)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
411 if len(files) > 0 and not htdocs_access(request):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
412 scriptName = request.getScriptname()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
413 pagename_quoted = wikiutil.quoteWikinameURL(pagename)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
414
1986
3475126f78c6 fix some builtin names used as attribute names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1967
diff changeset
415 for fname in files:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
416 url = "%s/%s?action=%s&do=view&target=%s" % (
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
417 scriptName, pagename_quoted,
1986
3475126f78c6 fix some builtin names used as attribute names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1967
diff changeset
418 action_name, wikiutil.url_quote_plus(fname))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
419
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
420 request.write(u'<link rel="Appendix" title="%s" href="%s">\n' % (
1986
3475126f78c6 fix some builtin names used as attribute names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1967
diff changeset
421 wikiutil.escape(fname), wikiutil.escape(url)))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
422
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
423
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
424 def send_hotdraw(pagename, request):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
425 _ = request.getText
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
426
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
427 now = time.time()
1318
760002b5ffa3 use url_prefix_static = '/moin_static160' instead of url_prefix = '/wiki' to avoid user confusion and stale caches
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1317
diff changeset
428 pubpath = request.cfg.url_prefix_static + "/applets/TWikiDrawPlugin"
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
429 basename = request.form['drawing'][0]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
430 drawpath = getAttachUrl(pagename, basename + '.draw', request, escaped=1)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
431 pngpath = getAttachUrl(pagename, basename + '.png', request, escaped=1)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
432 querystr = {'action': 'AttachFile', 'ts': now}
102
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
433 querystr = wikiutil.escape(wikiutil.makeQueryString(querystr))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
434 pagelink = '%s/%s?%s' % (request.getScriptname(), wikiutil.quoteWikinameURL(pagename), querystr)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
435 helplink = Page(request, "HelpOnActions/AttachFile").url(request)
623
088282ae5cf3 move twikidraw saving stuff from request to AttachFile, ok for CGI, needs tests for Twisted and WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
436 querystr = {'action': 'AttachFile', 'do': 'savedrawing'}
088282ae5cf3 move twikidraw saving stuff from request to AttachFile, ok for CGI, needs tests for Twisted and WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
437 querystr = wikiutil.escape(wikiutil.makeQueryString(querystr))
088282ae5cf3 move twikidraw saving stuff from request to AttachFile, ok for CGI, needs tests for Twisted and WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
438 savelink = '%s/%s?%s' % (request.getScriptname(), wikiutil.quoteWikinameURL(pagename), querystr)
088282ae5cf3 move twikidraw saving stuff from request to AttachFile, ok for CGI, needs tests for Twisted and WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
439 #savelink = Page(request, pagename).url(request) # XXX include target filename param here for twisted
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
440 # request, {'savename': request.form['drawing'][0]+'.draw'}
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
441 #savelink = '/cgi-bin/dumpform.bat'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
442
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
443 if htdocs_access(request):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
444 timestamp = '?ts=%s' % now
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
445 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
446 timestamp = '&amp;ts=%s' % now
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
447
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
448 request.write('<h2>' + _("Edit drawing") + '</h2>')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
449 request.write("""
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
450 <p>
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
451 <img src="%(pngpath)s%(timestamp)s">
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
452 <applet code="CH.ifa.draw.twiki.TWikiDraw.class"
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
453 archive="%(pubpath)s/twikidraw.jar" width="640" height="480">
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
454 <param name="drawpath" value="%(drawpath)s">
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
455 <param name="pngpath" value="%(pngpath)s">
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
456 <param name="savepath" value="%(savelink)s">
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
457 <param name="basename" value="%(basename)s">
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
458 <param name="viewpath" value="%(pagelink)s">
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
459 <param name="helppath" value="%(helplink)s">
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
460 <strong>NOTE:</strong> You need a Java enabled browser to edit the drawing example.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
461 </applet>
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
462 </p>""" % {
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
463 'pngpath': pngpath, 'timestamp': timestamp,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
464 'pubpath': pubpath, 'drawpath': drawpath,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
465 'savelink': savelink, 'pagelink': pagelink, 'helplink': helplink,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
466 'basename': basename
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
467 })
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
468
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
469
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
470 def send_uploadform(pagename, request):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
471 """ Send the HTML code for the list of already stored attachments and
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
472 the file upload form.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
473 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
474 _ = request.getText
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
475
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
476 if not request.user.may.read(pagename):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
477 request.write('<p>%s</p>' % _('You are not allowed to view this page.'))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
478 return
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
479
1635
a41c60e53ddd display upload attachment form at top, avoids lots of scrolling
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1611
diff changeset
480 writeable = request.user.may.write(pagename)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
481
1635
a41c60e53ddd display upload attachment form at top, avoids lots of scrolling
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1611
diff changeset
482 # First send out the upload new attachment form on top of everything else.
a41c60e53ddd display upload attachment form at top, avoids lots of scrolling
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1611
diff changeset
483 # This avoids usability issues if you have to scroll down a lot to upload
a41c60e53ddd display upload attachment form at top, avoids lots of scrolling
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1611
diff changeset
484 # a new file when the page already has lots of attachments:
a41c60e53ddd display upload attachment form at top, avoids lots of scrolling
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1611
diff changeset
485 if writeable:
a41c60e53ddd display upload attachment form at top, avoids lots of scrolling
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1611
diff changeset
486 request.write('<h2>' + _("New Attachment") + '</h2><p>' +
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
487 _("""An upload will never overwrite an existing file. If there is a name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
488 conflict, you have to rename the file that you want to upload.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
489 Otherwise, if "Rename to" is left blank, the original filename will be used.""") + '</p>')
1635
a41c60e53ddd display upload attachment form at top, avoids lots of scrolling
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1611
diff changeset
490 request.write("""
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
491 <form action="%(baseurl)s/%(pagename)s" method="POST" enctype="multipart/form-data">
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
492 <dl>
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
493 <dt>%(upload_label_file)s</dt>
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
494 <dd><input type="file" name="file" size="50"></dd>
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
495 <dt>%(upload_label_rename)s</dt>
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
496 <dd><input type="text" name="rename" size="50" value="%(rename)s"></dd>
1765
6e438de156d9 AttachFile: allow overwriting files when user chooses that option (ported from 1.5-802)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1662
diff changeset
497 <dt>%(upload_label_overwrite)s</dt>
6e438de156d9 AttachFile: allow overwriting files when user chooses that option (ported from 1.5-802)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1662
diff changeset
498 <dd><input type="checkbox" name="overwrite" value="1" %(overwrite_checked)s></dd>
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
499 </dl>
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
500 <p>
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
501 <input type="hidden" name="action" value="%(action_name)s">
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
502 <input type="hidden" name="do" value="upload">
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
503 <input type="submit" value="%(upload_button)s">
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
504 </p>
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
505 </form>
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
506 """ % {
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
507 'baseurl': request.getScriptname(),
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
508 'pagename': wikiutil.quoteWikinameURL(pagename),
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
509 'action_name': action_name,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
510 'upload_label_file': _('File to upload'),
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
511 'upload_label_rename': _('Rename to'),
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
512 'rename': request.form.get('rename', [''])[0],
1765
6e438de156d9 AttachFile: allow overwriting files when user chooses that option (ported from 1.5-802)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1662
diff changeset
513 'upload_label_overwrite': _('Overwrite existing attachment of same name'),
6e438de156d9 AttachFile: allow overwriting files when user chooses that option (ported from 1.5-802)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1662
diff changeset
514 'overwrite_checked': ('', 'checked')[request.form.get('overwrite', ['0'])[0] == '1'],
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
515 'upload_button': _('Upload'),
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
516 })
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
517
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
518 #<dt>%(upload_label_mime)s</dt>
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
519 #<dd><input type="text" name="mime" size="50"></dd>
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
520 # 'upload_label_mime': _('MIME Type (optional)'),
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
521
1635
a41c60e53ddd display upload attachment form at top, avoids lots of scrolling
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1611
diff changeset
522 request.write('<h2>' + _("Attached Files") + '</h2>')
a41c60e53ddd display upload attachment form at top, avoids lots of scrolling
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1611
diff changeset
523 request.write(_get_filelist(request, pagename))
a41c60e53ddd display upload attachment form at top, avoids lots of scrolling
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1611
diff changeset
524
a41c60e53ddd display upload attachment form at top, avoids lots of scrolling
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1611
diff changeset
525 if not writeable:
a41c60e53ddd display upload attachment form at top, avoids lots of scrolling
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1611
diff changeset
526 request.write('<p>%s</p>' % _('You are not allowed to attach a file to this page.'))
a41c60e53ddd display upload attachment form at top, avoids lots of scrolling
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1611
diff changeset
527
a41c60e53ddd display upload attachment form at top, avoids lots of scrolling
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1611
diff changeset
528 if writeable and request.form.get('drawing', [None])[0]:
a41c60e53ddd display upload attachment form at top, avoids lots of scrolling
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1611
diff changeset
529 send_hotdraw(pagename, request)
a41c60e53ddd display upload attachment form at top, avoids lots of scrolling
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1611
diff changeset
530
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
531
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
532 #############################################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
533 ### Web interface for file upload, viewing and deletion
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
534 #############################################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
535
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
536 def execute(pagename, request):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
537 """ Main dispatcher for the 'AttachFile' action.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
538 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
539 _ = request.getText
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
540
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
541 msg = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
542 if action_name in request.cfg.actions_excluded:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
543 msg = _('File attachments are not allowed in this wiki!')
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1866
diff changeset
544 elif 'do' not in request.form:
623
088282ae5cf3 move twikidraw saving stuff from request to AttachFile, ok for CGI, needs tests for Twisted and WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
545 upload_form(pagename, request)
088282ae5cf3 move twikidraw saving stuff from request to AttachFile, ok for CGI, needs tests for Twisted and WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
546 elif request.form['do'][0] == 'savedrawing':
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
547 if request.user.may.write(pagename):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
548 save_drawing(pagename, request)
1068
ecece5db5288 use emit_http_headers
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1006
diff changeset
549 request.emit_http_headers()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
550 request.write("OK")
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
551 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
552 msg = _('You are not allowed to save a drawing on this page.')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
553 elif request.form['do'][0] == 'upload':
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
554 if request.user.may.write(pagename):
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1866
diff changeset
555 if 'file' in request.form:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
556 do_upload(pagename, request)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
557 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
558 # This might happen when trying to upload file names
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
559 # with non-ascii characters on Safari.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
560 msg = _("No file content. Delete non ASCII characters from the file name and try again.")
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
561 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
562 msg = _('You are not allowed to attach a file to this page.')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
563 elif request.form['do'][0] == 'del':
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
564 if request.user.may.delete(pagename):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
565 del_file(pagename, request)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
566 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
567 msg = _('You are not allowed to delete attachments on this page.')
1608
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
568 elif request.form['do'][0] == 'move':
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
569 if request.user.may.delete(pagename):
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
570 send_moveform(pagename, request)
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
571 else:
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
572 msg = _('You are not allowed to move attachments from this page.')
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
573 elif request.form['do'][0] == 'attachment_move':
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1866
diff changeset
574 if 'cancel' in request.form:
1608
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
575 msg = _('Move aborted!')
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
576 error_msg(pagename, request, msg)
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
577 return
1610
48194fc011e5 move attachments: fix ticket calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1609
diff changeset
578 if not wikiutil.checkTicket(request, request.form['ticket'][0]):
1608
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
579 msg = _('Please use the interactive user interface to move attachments!')
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
580 error_msg(pagename, request, msg)
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
581 return
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
582 if request.user.may.delete(pagename):
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
583 attachment_move(pagename, request)
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
584 else:
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
585 msg = _('You are not allowed to move attachments from this page.')
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
586 elif request.form['do'][0] == 'get':
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
587 if request.user.may.read(pagename):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
588 get_file(pagename, request)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
589 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
590 msg = _('You are not allowed to get attachments from this page.')
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
591 elif request.form['do'][0] == 'unzip':
1920
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
592 if request.user.may.delete(pagename) and request.user.may.read(pagename) and request.user.may.write(pagename):
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
593 unzip_file(pagename, request)
1920
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
594 else:
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
595 msg = _('You are not allowed to unzip attachments of this page.')
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
596 elif request.form['do'][0] == 'install':
1920
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
597 if request.user.isSuperUser():
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
598 install_package(pagename, request)
1920
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
599 else:
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
600 msg = _('You are not allowed to install files.')
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
601 elif request.form['do'][0] == 'view':
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
602 if request.user.may.read(pagename):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
603 view_file(pagename, request)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
604 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
605 msg = _('You are not allowed to view attachments of this page.')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
606 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
607 msg = _('Unsupported upload action: %s') % (request.form['do'][0],)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
608
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
609 if msg:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
610 error_msg(pagename, request, msg)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
611
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
612 def upload_form(pagename, request, msg=''):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
613 _ = request.getText
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
614
1068
ecece5db5288 use emit_http_headers
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1006
diff changeset
615 request.emit_http_headers()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
616 # Use user interface language for this generated page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
617 request.setContentLanguage(request.lang)
616
3b08d9413589 move send_title/footer from wikiutil to theme.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 520
diff changeset
618 request.theme.send_title(_('Attachments for "%(pagename)s"') % {'pagename': pagename}, pagename=pagename, msg=msg)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
619 request.write('<div id="content">\n') # start content div
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
620 send_uploadform(pagename, request)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
621 request.write('</div>\n') # end content div
616
3b08d9413589 move send_title/footer from wikiutil to theme.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 520
diff changeset
622 request.theme.send_footer(pagename)
617
cf420addd95c removed MoinMoinNoFooter at many places, added call to theme.send_closing_html() where needed
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 616
diff changeset
623 request.theme.send_closing_html()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
624
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
625 def do_upload(pagename, request):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
626 _ = request.getText
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
627
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
628 # make filename
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
629 filename = None
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1866
diff changeset
630 if 'file__filename__' in request.form:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
631 filename = request.form['file__filename__']
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
632 rename = None
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1866
diff changeset
633 if 'rename' in request.form:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
634 rename = request.form['rename'][0].strip()
1765
6e438de156d9 AttachFile: allow overwriting files when user chooses that option (ported from 1.5-802)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1662
diff changeset
635 overwrite = 0
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1866
diff changeset
636 if 'overwrite' in request.form:
1765
6e438de156d9 AttachFile: allow overwriting files when user chooses that option (ported from 1.5-802)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1662
diff changeset
637 try:
6e438de156d9 AttachFile: allow overwriting files when user chooses that option (ported from 1.5-802)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1662
diff changeset
638 overwrite = int(request.form['overwrite'][0])
6e438de156d9 AttachFile: allow overwriting files when user chooses that option (ported from 1.5-802)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1662
diff changeset
639 except:
6e438de156d9 AttachFile: allow overwriting files when user chooses that option (ported from 1.5-802)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1662
diff changeset
640 pass
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
641
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
642 # if we use twisted, "rename" field is NOT optional, because we
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
643 # can't access the client filename
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
644 if rename:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
645 target = rename
1891
76040d9ab344 AttachFile: clear rename for form after upload
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1868
diff changeset
646 # clear rename its only once wanted
76040d9ab344 AttachFile: clear rename for form after upload
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1868
diff changeset
647 request.form['rename'][0] = u''
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
648 elif filename:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
649 target = filename
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
650 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
651 error_msg(pagename, request, _("Filename of attachment not specified!"))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
652 return
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
653
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
654 # get file content
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
655 filecontent = request.form['file'][0]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
656
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
657 # preprocess the filename
691
f18b06c790d4 Refactored adding attachments.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 623
diff changeset
658 # strip leading drive and path (IE misbehaviour)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
659 if len(target) > 1 and (target[1] == ':' or target[0] == '\\'): # C:.... or \path... or \\server\...
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
660 bsindex = target.rfind('\\')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
661 if bsindex >= 0:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
662 target = target[bsindex+1:]
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
663
691
f18b06c790d4 Refactored adding attachments.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 623
diff changeset
664 # add the attachment
f18b06c790d4 Refactored adding attachments.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 623
diff changeset
665 try:
1791
6dd2e29acffe Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1777
diff changeset
666 add_attachment(request, pagename, target, filecontent, overwrite=overwrite)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
667
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
668 bytes = len(filecontent)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
669 msg = _("Attachment '%(target)s' (remote name '%(filename)s')"
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
670 " with %(bytes)d bytes saved.") % {
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
671 'target': target, 'filename': filename, 'bytes': bytes}
691
f18b06c790d4 Refactored adding attachments.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 623
diff changeset
672 except AttachmentAlreadyExists:
f18b06c790d4 Refactored adding attachments.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 623
diff changeset
673 msg = _("Attachment '%(target)s' (remote name '%(filename)s') already exists.") % {
f18b06c790d4 Refactored adding attachments.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 623
diff changeset
674 'target': target, 'filename': filename}
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
675
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
676 # return attachment list
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
677 upload_form(pagename, request, msg)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
678
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
679
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
680 def save_drawing(pagename, request):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
681
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
682 filename = request.form['filename'][0]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
683 filecontent = request.form['filepath'][0]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
684
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
685 # there should be no difference in filename parsing with or without
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
686 # htdocs_access, cause the filename param is used
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
687 basepath, basename = os.path.split(filename)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
688 basename, ext = os.path.splitext(basename)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
689
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
690 # get directory, and possibly create it
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
691 attach_dir = getAttachDir(request, pagename, create=1)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
692
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
693 if ext == '.draw':
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
694 _addLogEntry(request, 'ATTDRW', pagename, basename + ext)
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
695 filecontent = filecontent.replace("\r", "")
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
696
1793
2a4caa295346 Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
697 savepath = os.path.join(attach_dir, basename + ext)
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
698 if ext == '.map' and not filecontent.strip():
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
699 # delete map file if it is empty
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
700 os.unlink(savepath)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
701 else:
1006
509ea9995c9d use config.umask for saved drawing files (backport to 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 889
diff changeset
702 stream = open(savepath, 'wb')
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
703 try:
1006
509ea9995c9d use config.umask for saved drawing files (backport to 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 889
diff changeset
704 stream.write(filecontent)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
705 finally:
1006
509ea9995c9d use config.umask for saved drawing files (backport to 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 889
diff changeset
706 stream.close()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
707
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
708 # touch attachment directory to invalidate cache if new map is saved
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
709 if ext == '.map':
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
710 os.utime(getAttachDir(request, pagename), None)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
711
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
712 def del_file(pagename, request):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
713 _ = request.getText
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
714
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
715 filename, fpath = _access_file(pagename, request)
1920
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
716 if not filename:
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
717 return # error msg already sent in _access_file
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
718
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
719 # delete file
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
720 os.remove(fpath)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
721 _addLogEntry(request, 'ATTDEL', pagename, filename)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
722
1479
b1562b232683 fix for deleting from xapian index
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1473
diff changeset
723 if request.cfg.xapian_search:
b1562b232683 fix for deleting from xapian index
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1473
diff changeset
724 from MoinMoin.search.Xapian import Index
b1562b232683 fix for deleting from xapian index
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1473
diff changeset
725 index = Index(request)
b1562b232683 fix for deleting from xapian index
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1473
diff changeset
726 if index.exists:
b1562b232683 fix for deleting from xapian index
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1473
diff changeset
727 index.remove_item(pagename, filename)
b1562b232683 fix for deleting from xapian index
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1473
diff changeset
728
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
729 upload_form(pagename, request, msg=_("Attachment '%(filename)s' deleted.") % {'filename': filename})
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
730
1608
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
731 def move_file(request, pagename, new_pagename, attachment, new_attachment):
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
732 _ = request.getText
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
733
1609
7f73dafb525d move attachments: remove unneeded imports
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1608
diff changeset
734 newpage = Page(request, new_pagename)
1608
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
735 if newpage.exists(includeDeleted=1) and request.user.may.write(new_pagename) and request.user.may.delete(pagename):
1609
7f73dafb525d move attachments: remove unneeded imports
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1608
diff changeset
736 new_attachment_path = os.path.join(getAttachDir(request, new_pagename,
1608
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
737 create=1), new_attachment).encode(config.charset)
1609
7f73dafb525d move attachments: remove unneeded imports
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1608
diff changeset
738 attachment_path = os.path.join(getAttachDir(request, pagename),
1608
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
739 attachment).encode(config.charset)
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
740
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
741 if os.path.exists(new_attachment_path):
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
742 upload_form(pagename, request, msg=_("Attachment '%(filename)s' already exists.") % {
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
743 'filename': new_attachment})
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
744 return
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
745
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
746 if new_attachment_path != attachment_path:
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
747 # move file
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
748 filesys.rename(attachment_path, new_attachment_path)
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
749 _addLogEntry(request, 'ATTDEL', pagename, attachment)
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
750 _addLogEntry(request, 'ATTNEW', new_pagename, new_attachment)
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
751 upload_form(pagename, request, msg=_("Attachment '%(filename)s' moved to %(page)s.") % {
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
752 'filename': new_attachment,
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
753 'page': new_pagename})
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
754 else:
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
755 upload_form(pagename, request, msg=_("Nothing changed"))
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
756 else:
1920
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
757 upload_form(pagename, request, msg=_("Page %(newpagename)s does not exists or you don't have enough rights.") % {
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
758 'newpagename': new_pagename})
1608
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
759
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
760 def attachment_move(pagename, request):
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
761 _ = request.getText
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1866
diff changeset
762 if 'newpagename' in request.form:
1608
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
763 new_pagename = request.form.get('newpagename')[0]
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
764 else:
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
765 upload_form(pagename, request, msg=_("Move aborted because empty page name"))
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1866
diff changeset
766 if 'newattachmentname' in request.form:
1608
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
767 new_attachment = request.form.get('newattachmentname')[0]
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
768 if new_attachment != wikiutil.taintfilename(new_attachment):
1662
3338af3c3867 update i18n, fix i18n tools
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1653
diff changeset
769 upload_form(pagename, request, msg=_("Please use a valid filename for attachment '%(filename)s'.") % {
1608
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
770 'filename': new_attachment})
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
771 return
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
772 else:
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
773 upload_form(pagename, request, msg=_("Move aborted because empty attachment name"))
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
774
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
775 attachment = request.form.get('oldattachmentname')[0]
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
776 move_file(request, pagename, new_pagename, attachment, new_attachment)
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
777
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
778 def send_moveform(pagename, request):
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
779 _ = request.getText
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
780
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
781 filename, fpath = _access_file(pagename, request)
1920
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
782 if not filename:
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
783 return # error msg already sent in _access_file
1608
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
784
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
785 # move file
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
786 d = {'action': 'AttachFile',
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
787 'do': 'attachment_move',
1610
48194fc011e5 move attachments: fix ticket calls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1609
diff changeset
788 'ticket': wikiutil.createTicket(request),
1608
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
789 'pagename': pagename,
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
790 'attachment_name': filename,
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
791 'move': _('Move'),
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
792 'cancel': _('Cancel'),
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
793 'newname_label': _("New page name"),
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
794 'attachment_label': _("New attachment name"),
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
795 }
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
796 formhtml = '''
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
797 <form method="post" action="">
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
798 <input type="hidden" name="action" value="%(action)s">
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
799 <input type="hidden" name="do" value="%(do)s">
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
800 <input type="hidden" name="ticket" value="%(ticket)s">
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
801 <table>
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
802 <tr>
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
803 <td class="label"><label>%(newname_label)s</label></td>
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
804 <td class="content">
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
805 <input type="text" name="newpagename" value="%(pagename)s">
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
806 </td>
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
807 </tr>
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
808 <tr>
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
809 <td class="label"><label>%(attachment_label)s</label></td>
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
810 <td class="content">
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
811 <input type="text" name="newattachmentname" value="%(attachment_name)s">
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
812 </td>
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
813 </tr>
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
814 <tr>
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
815 <td></td>
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
816 <td class="buttons">
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
817 <input type="hidden" name="oldattachmentname" value="%(attachment_name)s">
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
818 <input type="submit" name="move" value="%(move)s">
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
819 <input type="submit" name="cancel" value="%(cancel)s">
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
820 </td>
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
821 </tr>
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
822 </table>
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
823 </form>''' % d
7a26b4c769f3 attachment move
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 1548
diff changeset
824 thispage = Page(request, pagename)
1777
ed44b93599b5 remove unneeded request param from page.send_page()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1766
diff changeset
825 return thispage.send_page(msg=formhtml)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
826
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
827 def get_file(pagename, request):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
828 import shutil
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
829
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
830 filename, fpath = _access_file(pagename, request)
801
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
831 if not filename:
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
832 return # error msg already sent in _access_file
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
833
1115
a349adcabffe 304 response support for attached files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1068
diff changeset
834 timestamp = timefuncs.formathttpdate(int(os.path.getmtime(fpath)))
a349adcabffe 304 response support for attached files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1068
diff changeset
835 if request.if_modified_since == timestamp:
a349adcabffe 304 response support for attached files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1068
diff changeset
836 request.emit_http_headers(["Status: 304 Not modified"])
a349adcabffe 304 response support for attached files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1068
diff changeset
837 else:
a349adcabffe 304 response support for attached files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1068
diff changeset
838 mt = wikiutil.MimeType(filename=filename)
1548
2eb5117aa7de content-disposition for AttachFile downloads either inline or attachment depending on mimetype in cfg.mimetypes_xss_protect list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1510
diff changeset
839 content_type = mt.content_type()
2eb5117aa7de content-disposition for AttachFile downloads either inline or attachment depending on mimetype in cfg.mimetypes_xss_protect list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1510
diff changeset
840 mime_type = mt.mime_type()
2eb5117aa7de content-disposition for AttachFile downloads either inline or attachment depending on mimetype in cfg.mimetypes_xss_protect list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1510
diff changeset
841
2eb5117aa7de content-disposition for AttachFile downloads either inline or attachment depending on mimetype in cfg.mimetypes_xss_protect list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1510
diff changeset
842 # TODO: fix the encoding here, plain 8 bit is not allowed according to the RFCs
2eb5117aa7de content-disposition for AttachFile downloads either inline or attachment depending on mimetype in cfg.mimetypes_xss_protect list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1510
diff changeset
843 # There is no solution that is compatible to IE except stripping non-ascii chars
2eb5117aa7de content-disposition for AttachFile downloads either inline or attachment depending on mimetype in cfg.mimetypes_xss_protect list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1510
diff changeset
844 filename_enc = filename.encode(config.charset)
2eb5117aa7de content-disposition for AttachFile downloads either inline or attachment depending on mimetype in cfg.mimetypes_xss_protect list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1510
diff changeset
845
2eb5117aa7de content-disposition for AttachFile downloads either inline or attachment depending on mimetype in cfg.mimetypes_xss_protect list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1510
diff changeset
846 # for dangerous files (like .html), when we are in danger of cross-site-scripting attacks,
2eb5117aa7de content-disposition for AttachFile downloads either inline or attachment depending on mimetype in cfg.mimetypes_xss_protect list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1510
diff changeset
847 # we just let the user store them to disk ('attachment').
2eb5117aa7de content-disposition for AttachFile downloads either inline or attachment depending on mimetype in cfg.mimetypes_xss_protect list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1510
diff changeset
848 # For safe files, we directly show them inline (this also works better for IE).
2eb5117aa7de content-disposition for AttachFile downloads either inline or attachment depending on mimetype in cfg.mimetypes_xss_protect list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1510
diff changeset
849 dangerous = mime_type in request.cfg.mimetypes_xss_protect
2eb5117aa7de content-disposition for AttachFile downloads either inline or attachment depending on mimetype in cfg.mimetypes_xss_protect list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1510
diff changeset
850 content_dispo = dangerous and 'attachment' or 'inline'
2eb5117aa7de content-disposition for AttachFile downloads either inline or attachment depending on mimetype in cfg.mimetypes_xss_protect list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1510
diff changeset
851
1115
a349adcabffe 304 response support for attached files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1068
diff changeset
852 request.emit_http_headers([
1548
2eb5117aa7de content-disposition for AttachFile downloads either inline or attachment depending on mimetype in cfg.mimetypes_xss_protect list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1510
diff changeset
853 'Content-Type: %s' % content_type,
1798
cabab80d9597 AttachFile:merged with 1796:57f12932915f, EXIF:bug fixed in test/debug function
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1797
diff changeset
854 'Last-Modified: %s' % timestamp,
1548
2eb5117aa7de content-disposition for AttachFile downloads either inline or attachment depending on mimetype in cfg.mimetypes_xss_protect list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1510
diff changeset
855 'Content-Length: %d' % os.path.getsize(fpath),
2eb5117aa7de content-disposition for AttachFile downloads either inline or attachment depending on mimetype in cfg.mimetypes_xss_protect list
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1510
diff changeset
856 'Content-Disposition: %s; filename="%s"' % (content_dispo, filename_enc),
1115
a349adcabffe 304 response support for attached files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1068
diff changeset
857 ])
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
858
1115
a349adcabffe 304 response support for attached files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1068
diff changeset
859 # send data
a349adcabffe 304 response support for attached files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1068
diff changeset
860 shutil.copyfileobj(open(fpath, 'rb'), request, 8192)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
861
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
862 def install_package(pagename, request):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
863 _ = request.getText
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
864
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
865 target, targetpath = _access_file(pagename, request)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
866 if not target:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
867 return
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
868
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
869 package = packages.ZipPackage(request, targetpath)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
870
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
871 if package.isPackage():
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
872 if package.installPackage():
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
873 msg = _("Attachment '%(filename)s' installed.") % {'filename': wikiutil.escape(target)}
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
874 else:
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
875 msg = _("Installation of '%(filename)s' failed.") % {'filename': wikiutil.escape(target)}
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
876 if package.msg != "":
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
877 msg += "<br><pre>" + wikiutil.escape(package.msg) + "</pre>"
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
878 else:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
879 msg = _('The file %s is not a MoinMoin package file.' % wikiutil.escape(target))
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
880
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
881 upload_form(pagename, request, msg=msg)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
882
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
883 def unzip_file(pagename, request):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
884 _ = request.getText
1419
f7f415cc1332 replace most find() calls by in/index()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1318
diff changeset
885 valid_pathname = lambda name: ('/' not in name) and ('\\' not in name)
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
886
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
887 filename, fpath = _access_file(pagename, request)
116
de898247fbff limit file count when unzipping an attachment
Thomas Waldmann <tw@waldmann-edv.de>
parents: 113
diff changeset
888 if not filename:
de898247fbff limit file count when unzipping an attachment
Thomas Waldmann <tw@waldmann-edv.de>
parents: 113
diff changeset
889 return # error msg already sent in _access_file
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
890
113
7785febd9530 Refactored unzipping settings into multiconfig. Untested.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 103
diff changeset
891 single_file_size = request.cfg.unzip_single_file_size
7785febd9530 Refactored unzipping settings into multiconfig. Untested.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 103
diff changeset
892 attachments_file_space = request.cfg.unzip_attachments_space
117
4775d5ff5f40 attachment unzipper: handle file count quota-like as it was done with size
Thomas Waldmann <tw@waldmann-edv.de>
parents: 116
diff changeset
893 attachments_file_count = request.cfg.unzip_attachments_count
116
de898247fbff limit file count when unzipping an attachment
Thomas Waldmann <tw@waldmann-edv.de>
parents: 113
diff changeset
894
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
895 files = _get_files(request, pagename)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
896
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
897 msg = ""
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
898 if files:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
899 fsize = 0.0
117
4775d5ff5f40 attachment unzipper: handle file count quota-like as it was done with size
Thomas Waldmann <tw@waldmann-edv.de>
parents: 116
diff changeset
900 fcount = 0
1920
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
901 for f in files:
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
902 fsize += float(size(request, pagename, f))
117
4775d5ff5f40 attachment unzipper: handle file count quota-like as it was done with size
Thomas Waldmann <tw@waldmann-edv.de>
parents: 116
diff changeset
903 fcount += 1
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
904
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
905 available_attachments_file_space = attachments_file_space - fsize
117
4775d5ff5f40 attachment unzipper: handle file count quota-like as it was done with size
Thomas Waldmann <tw@waldmann-edv.de>
parents: 116
diff changeset
906 available_attachments_file_count = attachments_file_count - fcount
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
907
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
908 if zipfile.is_zipfile(fpath):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
909 zf = zipfile.ZipFile(fpath)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
910 sum_size_over_all_valid_files = 0.0
116
de898247fbff limit file count when unzipping an attachment
Thomas Waldmann <tw@waldmann-edv.de>
parents: 113
diff changeset
911 count_valid_files = 0
280
015c945277ec "Winzip compat ?patch" - Allow a .zip file to have a directory in it if it is the only one. Thanks Diego Ongaro.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 145
diff changeset
912 namelist = _subdir_exception(zf)
015c945277ec "Winzip compat ?patch" - Allow a .zip file to have a directory in it if it is the only one. Thanks Diego Ongaro.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 145
diff changeset
913 if not namelist: #if it's not handled by _subdir_exception()
015c945277ec "Winzip compat ?patch" - Allow a .zip file to have a directory in it if it is the only one. Thanks Diego Ongaro.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 145
diff changeset
914 #Convert normal zf.namelist() to {origname:finalname} dict
015c945277ec "Winzip compat ?patch" - Allow a .zip file to have a directory in it if it is the only one. Thanks Diego Ongaro.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 145
diff changeset
915 namelist = {}
015c945277ec "Winzip compat ?patch" - Allow a .zip file to have a directory in it if it is the only one. Thanks Diego Ongaro.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 145
diff changeset
916 for name in zf.namelist():
015c945277ec "Winzip compat ?patch" - Allow a .zip file to have a directory in it if it is the only one. Thanks Diego Ongaro.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 145
diff changeset
917 namelist[name] = name
015c945277ec "Winzip compat ?patch" - Allow a .zip file to have a directory in it if it is the only one. Thanks Diego Ongaro.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 145
diff changeset
918 for (origname, finalname) in namelist.iteritems():
015c945277ec "Winzip compat ?patch" - Allow a .zip file to have a directory in it if it is the only one. Thanks Diego Ongaro.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 145
diff changeset
919 if valid_pathname(finalname):
015c945277ec "Winzip compat ?patch" - Allow a .zip file to have a directory in it if it is the only one. Thanks Diego Ongaro.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 145
diff changeset
920 sum_size_over_all_valid_files += zf.getinfo(origname).file_size
116
de898247fbff limit file count when unzipping an attachment
Thomas Waldmann <tw@waldmann-edv.de>
parents: 113
diff changeset
921 count_valid_files += 1
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
922
117
4775d5ff5f40 attachment unzipper: handle file count quota-like as it was done with size
Thomas Waldmann <tw@waldmann-edv.de>
parents: 116
diff changeset
923 if sum_size_over_all_valid_files > available_attachments_file_space:
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
924 msg = _("Attachment '%(filename)s' could not be unzipped because"
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
925 " the resulting files would be too large (%(space)d kB"
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
926 " missing).") % {
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
927 'filename': filename,
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
928 'space': (sum_size_over_all_valid_files -
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
929 available_attachments_file_space) / 1000 }
117
4775d5ff5f40 attachment unzipper: handle file count quota-like as it was done with size
Thomas Waldmann <tw@waldmann-edv.de>
parents: 116
diff changeset
930 elif count_valid_files > available_attachments_file_count:
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
931 msg = _("Attachment '%(filename)s' could not be unzipped because"
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
932 " the resulting files would be too many (%(count)d "
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
933 "missing).") % {
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
934 'filename': filename,
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
935 'count': (count_valid_files -
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
936 available_attachments_file_count) }
117
4775d5ff5f40 attachment unzipper: handle file count quota-like as it was done with size
Thomas Waldmann <tw@waldmann-edv.de>
parents: 116
diff changeset
937 else:
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
938 valid_name = False
373
d9028858980d Repaired zipping, a very small typo broke it.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 281
diff changeset
939 for (origname, finalname) in namelist.iteritems():
280
015c945277ec "Winzip compat ?patch" - Allow a .zip file to have a directory in it if it is the only one. Thanks Diego Ongaro.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 145
diff changeset
940 if valid_pathname(finalname):
015c945277ec "Winzip compat ?patch" - Allow a .zip file to have a directory in it if it is the only one. Thanks Diego Ongaro.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 145
diff changeset
941 zi = zf.getinfo(origname)
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
942 if zi.file_size < single_file_size:
280
015c945277ec "Winzip compat ?patch" - Allow a .zip file to have a directory in it if it is the only one. Thanks Diego Ongaro.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 145
diff changeset
943 new_file = getFilename(request, pagename, finalname)
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
944 if not os.path.exists(new_file):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
945 outfile = open(new_file, 'wb')
280
015c945277ec "Winzip compat ?patch" - Allow a .zip file to have a directory in it if it is the only one. Thanks Diego Ongaro.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 145
diff changeset
946 outfile.write(zf.read(origname))
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
947 outfile.close()
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
948 # it's not allowed to zip a zip file so it is dropped
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
949 if zipfile.is_zipfile(new_file):
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
950 os.unlink(new_file)
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
951 else:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
952 valid_name = True
280
015c945277ec "Winzip compat ?patch" - Allow a .zip file to have a directory in it if it is the only one. Thanks Diego Ongaro.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 145
diff changeset
953 _addLogEntry(request, 'ATTNEW', pagename, finalname)
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
954
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
955 if valid_name:
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
956 msg = _("Attachment '%(filename)s' unzipped.") % {'filename': filename}
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
957 else:
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
958 msg = _("Attachment '%(filename)s' not unzipped because the "
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
959 "files are too big, .zip files only, exist already or "
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
960 "reside in folders.") % {'filename': filename}
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
961 else:
1791
6dd2e29acffe Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1777
diff changeset
962 msg = _('The file %(filename)s is not a .zip file.' % {'filename': filename})
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
963
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
964 upload_form(pagename, request, msg=wikiutil.escape(msg))
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
965
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
966 def send_viewfile(pagename, request):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
967 _ = request.getText
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
968
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
969 filename, fpath = _access_file(pagename, request)
1920
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
970 if not filename:
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
971 return
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
972
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
973 request.write('<h2>' + _("Attachment '%(filename)s'") % {'filename': filename} + '</h2>')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
974
801
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
975 mt = wikiutil.MimeType(filename=filename)
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
976 if mt.major == 'image':
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
977 timestamp = htdocs_access(request) and "?%s" % time.time() or ''
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
978 request.write('<img src="%s%s" alt="%s">' % (
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
979 getAttachUrl(pagename, filename, request, escaped=1), timestamp, wikiutil.escape(filename, 1)))
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
980 return
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
981 elif mt.major == 'text':
1833
af0feb0e3c7b AttachFile: more usage of the formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1832
diff changeset
982 request.write(request.formatter.preformatted(1))
801
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
983 # Try to decode file contents. It may return junk, but we
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
984 # don't have enough information on attachments.
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
985 content = open(fpath, 'r').read()
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
986 content = wikiutil.decodeUnknownInput(content)
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
987 content = wikiutil.escape(content)
1833
af0feb0e3c7b AttachFile: more usage of the formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1832
diff changeset
988 request.write(request.formatter.text(content))
af0feb0e3c7b AttachFile: more usage of the formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1832
diff changeset
989 request.write(request.formatter.preformatted(0))
801
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
990 return
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
991
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
992 package = packages.ZipPackage(request, fpath)
1985
eb5328be394e AttachFile:destinguish between zip and other fileformats using zip archives
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1967
diff changeset
993 if package.isPackage() and mt.minor == 'zip':
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
994 request.write("<pre><b>%s</b>\n%s</pre>" % (_("Package script:"), wikiutil.escape(package.getScript())))
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
995 return
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
996
1985
eb5328be394e AttachFile:destinguish between zip and other fileformats using zip archives
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1967
diff changeset
997 if zipfile.is_zipfile(fpath) and mt.minor == 'zip':
80
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
998 zf = zipfile.ZipFile(fpath, mode='r')
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
999 request.write("<pre>%-46s %19s %12s\n" % (_("File Name"), _("Modified")+" "*5, _("Size")))
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
1000 for zinfo in zf.filelist:
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
1001 date = "%d-%02d-%02d %02d:%02d:%02d" % zinfo.date_time
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
1002 request.write(wikiutil.escape("%-46s %s %12d\n" % (zinfo.filename, date, zinfo.file_size)))
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
1003 request.write("</pre>")
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
1004 return
99f0d19d0285 Integrated MoinMoin:PackageInstaller and zip support.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 33
diff changeset
1005
1952
8ab85e3711dc AttachFile:send_viewfile extended for mimetypes presentable by EmbedObject
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1920
diff changeset
1006 # reuse class tmp from Despam to define macro
8ab85e3711dc AttachFile:send_viewfile extended for mimetypes presentable by EmbedObject
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1920
diff changeset
1007 from MoinMoin.action.Despam import tmp
8ab85e3711dc AttachFile:send_viewfile extended for mimetypes presentable by EmbedObject
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1920
diff changeset
1008 macro = tmp()
8ab85e3711dc AttachFile:send_viewfile extended for mimetypes presentable by EmbedObject
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1920
diff changeset
1009 macro.request = request
8ab85e3711dc AttachFile:send_viewfile extended for mimetypes presentable by EmbedObject
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1920
diff changeset
1010 macro.formatter = request.html_formatter
8ab85e3711dc AttachFile:send_viewfile extended for mimetypes presentable by EmbedObject
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1920
diff changeset
1011
8ab85e3711dc AttachFile:send_viewfile extended for mimetypes presentable by EmbedObject
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1920
diff changeset
1012 # use EmbedObject to view valid mime types
8ab85e3711dc AttachFile:send_viewfile extended for mimetypes presentable by EmbedObject
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1920
diff changeset
1013 from MoinMoin.macro.EmbedObject import EmbedObject
1967
3bc30cdc4555 AttachFile, EmbedObject: code optimisation to use wikiutil.MimeType and refactoring of EmbedObject
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1952
diff changeset
1014 if mt is None:
1952
8ab85e3711dc AttachFile:send_viewfile extended for mimetypes presentable by EmbedObject
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1920
diff changeset
1015 request.write('<p>' + _("Unknown file type, cannot display this attachment inline.") + '</p>')
8ab85e3711dc AttachFile:send_viewfile extended for mimetypes presentable by EmbedObject
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1920
diff changeset
1016 request.write('For using an external program follow this link <a href="%s">%s</a>' % (
8ab85e3711dc AttachFile:send_viewfile extended for mimetypes presentable by EmbedObject
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1920
diff changeset
1017 getAttachUrl(pagename, filename, request, escaped=1), wikiutil.escape(filename)))
8ab85e3711dc AttachFile:send_viewfile extended for mimetypes presentable by EmbedObject
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1920
diff changeset
1018 return
8ab85e3711dc AttachFile:send_viewfile extended for mimetypes presentable by EmbedObject
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1920
diff changeset
1019
8ab85e3711dc AttachFile:send_viewfile extended for mimetypes presentable by EmbedObject
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1920
diff changeset
1020 url = getAttachUrl(pagename, filename, request, escaped=1)
8ab85e3711dc AttachFile:send_viewfile extended for mimetypes presentable by EmbedObject
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1920
diff changeset
1021
1967
3bc30cdc4555 AttachFile, EmbedObject: code optimisation to use wikiutil.MimeType and refactoring of EmbedObject
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1952
diff changeset
1022 request.write(request.formatter.rawHTML(EmbedObject.embed(EmbedObject(macro, wikiutil.escape(filename)), mt, url)))
1952
8ab85e3711dc AttachFile:send_viewfile extended for mimetypes presentable by EmbedObject
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1920
diff changeset
1023 return
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1024
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1025
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1026 def view_file(pagename, request):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1027 _ = request.getText
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1028
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1029 filename, fpath = _access_file(pagename, request)
1920
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
1030 if not filename:
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
1031 return
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1032
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1033 # send header & title
1068
ecece5db5288 use emit_http_headers
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1006
diff changeset
1034 request.emit_http_headers()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1035 # Use user interface language for this generated page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1036 request.setContentLanguage(request.lang)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1037 title = _('attachment:%(filename)s of %(pagename)s', formatted=True) % {
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1038 'filename': filename, 'pagename': pagename}
616
3b08d9413589 move send_title/footer from wikiutil to theme.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 520
diff changeset
1039 request.theme.send_title(title, pagename=pagename)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1040
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1041 # send body
1833
af0feb0e3c7b AttachFile: more usage of the formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1832
diff changeset
1042 request.write(request.formatter.startContent())
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1043 send_viewfile(pagename, request)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1044 send_uploadform(pagename, request)
1833
af0feb0e3c7b AttachFile: more usage of the formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1832
diff changeset
1045 request.write(request.formatter.endContent())
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1046
616
3b08d9413589 move send_title/footer from wikiutil to theme.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 520
diff changeset
1047 request.theme.send_footer(pagename)
617
cf420addd95c removed MoinMoinNoFooter at many places, added call to theme.send_closing_html() where needed
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 616
diff changeset
1048 request.theme.send_closing_html()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1049
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1050 #############################################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1051 ### File attachment administration
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1052 #############################################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1053
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1054 def do_admin_browser(request):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1055 """ Browser for SystemAdmin macro.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1056 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1057 from MoinMoin.util.dataset import TupleDataset, Column
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1058 _ = request.getText
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1059
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1060 data = TupleDataset()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1061 data.columns = [
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1062 Column('page', label=('Page')),
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1063 Column('file', label=('Filename')),
889
ad62767ffd0c pep8 style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 869
diff changeset
1064 Column('size', label=_('Size'), align='right'),
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1065 #Column('action', label=_('Action')),
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1066 ]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1067
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1068 # iterate over pages that might have attachments
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1069 pages = request.rootpage.getPageList()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1070 for pagename in pages:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1071 # check for attachments directory
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1072 page_dir = getAttachDir(request, pagename)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1073 if os.path.isdir(page_dir):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1074 # iterate over files of the page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1075 files = os.listdir(page_dir)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1076 for filename in files:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1077 filepath = os.path.join(page_dir, filename)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1078 data.addRow((
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1079 Page(request, pagename).link_to(request, querystr="action=AttachFile"),
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1080 wikiutil.escape(filename.decode(config.charset)),
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1081 os.path.getsize(filepath),
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1082 # '',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1083 ))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1084
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1085 if data:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1086 from MoinMoin.widget.browser import DataBrowserWidget
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1087
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1088 browser = DataBrowserWidget(request)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1089 browser.setData(data)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1090 return browser.toHTML()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1091
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1092 return ''
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1093