annotate MoinMoin/macro/EmbedObject.py @ 5098:ff588e9e24d6

simplify getAttachUrl: remove upload parameter upload=x didn't influence drawing url generation at all, for file url generation one can just give do='upload_form' if one wants the upload url. URL args for do='upload_form' were streamlined to use target=x instead of rename=x so it is more similar to the other code. Removed test for "tainted" file names in URLs. We must not "taint" file names for URLs. Filenames in URLs need to be url-quoted. If a URL is used in html, it needs to be escaped.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 13 Sep 2009 00:06:04 +0200
parents c538e2b0bba9
children 12d27670e274
rev   line source
879
49d164e275f3 EmbedObject macro (backport to 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
2785
ff1886a5defa EmbedObject:PEP8 fixes
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2784
diff changeset
2 """
879
49d164e275f3 EmbedObject macro (backport to 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
3 MoinMoin - EmbedObject Macro
49d164e275f3 EmbedObject macro (backport to 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
4
2784
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
5 This macro is used to embed an object into a wiki page. Optionally, the
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
6 size of the object can get adjusted. Further keywords are dependent on
2788
e857c1c3eca1 EmbedObject: msg strings corrected for new macro syntax and external url call parameter renamed
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2787
diff changeset
7 the kind of application, see HelpOnMacros/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
8
3022
e757ebc436e7 EmbedObject: refactored to use not empty params, for pdf default width="800" and height="800" added (backport to 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2788
diff changeset
9 <<EmbedObject(attachment[,width=width][,height=height][,alt=alternate Text])>>
879
49d164e275f3 EmbedObject macro (backport to 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
10
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
11 @copyright: 2006-2008 MoinMoin:ReimarBauer,
2784
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
12 2006 TomSi,
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
13 2007 OliverSiemoneit
2785
ff1886a5defa EmbedObject:PEP8 fixes
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2784
diff changeset
14
1918
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1914
diff changeset
15 @license: GNU GPL, see COPYING for details.
879
49d164e275f3 EmbedObject macro (backport to 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
16 """
49d164e275f3 EmbedObject macro (backport to 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
17
49d164e275f3 EmbedObject macro (backport to 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
18 from MoinMoin import wikiutil
49d164e275f3 EmbedObject macro (backport to 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
19 from MoinMoin.action import AttachFile
49d164e275f3 EmbedObject macro (backport to 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
20
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
21 extension_type, extension_name = __name__.split('.')[-2:]
1607
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
22
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
23 def _check_object_value(param, value):
3277
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
24 """ helps to omit useless lines of object values
3261
cbaf672bcea3 fix EmbedObject UnitArgument usage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3260
diff changeset
25
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
26 @param param: definition of object param
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
27 @param value: value of param
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
28 """
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
29 if value:
3277
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
30 return '%(param)s="%(value)s"' % {"param": param, "value": wikiutil.escape(value, True)}
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
31 else:
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
32 return ""
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
33
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
34 def _check_param_value(param, value, valuetype):
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
35 """ helps to ommit useless lines of param values
3277
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
36
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
37 @param param: param name defintion
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
38 @param value: the value
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
39 @param valuetype: the type of the value
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
40 """
3507
792fd08a05b6 macro.EmbedObject: bug fix for missing movie param see MoinMoinBugs/EmbedObjectMissesToEmitParamMovie and emitting param values of "False" too.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3369
diff changeset
41 # Because plugins do have different defaults we have to write "False" too.
792fd08a05b6 macro.EmbedObject: bug fix for missing movie param see MoinMoinBugs/EmbedObjectMissesToEmitParamMovie and emitting param values of "False" too.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3369
diff changeset
42 if isinstance(value, bool):
792fd08a05b6 macro.EmbedObject: bug fix for missing movie param see MoinMoinBugs/EmbedObjectMissesToEmitParamMovie and emitting param values of "False" too.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3369
diff changeset
43 value = str(value)
792fd08a05b6 macro.EmbedObject: bug fix for missing movie param see MoinMoinBugs/EmbedObjectMissesToEmitParamMovie and emitting param values of "False" too.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3369
diff changeset
44
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
45 if value:
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
46 return '''
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
47 <param name="%(param)s" value="%(value)s" valuetype="%(valuetype)s">''' % {"param": param,
3277
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
48 "value": wikiutil.escape(value, True),
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
49 "valuetype": valuetype}
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
50 else:
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
51 return ""
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1983
diff changeset
52
3369
73b64e4085ff macro.EmbedObject: adjusted required_arg removed duplicate msg
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3334
diff changeset
53 def macro_EmbedObject(macro, target=wikiutil.required_arg(unicode), pagename=None,
3517
41bfc5d6e3d3 macro.EmbedObject: use default unit px if None is given
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3507
diff changeset
54 width=wikiutil.UnitArgument(None, float, ['px', 'em', 'pt', 'in', 'mm', '%'], defaultunit='px'),
41bfc5d6e3d3 macro.EmbedObject: use default unit px if None is given
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3507
diff changeset
55 height=wikiutil.UnitArgument(None, float, ['px', 'em', 'pt', 'in', 'mm', '%'], defaultunit='px'),
3277
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
56 alt=u'',
3260
b971703ee4a9 macro.EmbedObject: beautified output, bug fix for quality param
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3253
diff changeset
57 play=False, stop=True, loop=False, quality=(u'high', u'low', u'medium'),
b971703ee4a9 macro.EmbedObject: beautified output, bug fix for quality param
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3253
diff changeset
58 op=True, repeat=False, autostart=False, align=(u'middle', u'top', u'bottom'), hidden=False,
3266
f62792cb2d24 macro.EmbedObject: adjusted to changes of argument parser, escaped output.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3261
diff changeset
59 menu=True, wmode=u'transparent', url_mimetype=None):
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
60 """ This macro is used to embed an object into a wiki page """
3261
cbaf672bcea3 fix EmbedObject UnitArgument usage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3260
diff changeset
61 # Join unit arguments with their units
3266
f62792cb2d24 macro.EmbedObject: adjusted to changes of argument parser, escaped output.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3261
diff changeset
62 if width:
f62792cb2d24 macro.EmbedObject: adjusted to changes of argument parser, escaped output.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3261
diff changeset
63 if width[1] == 'px':
f62792cb2d24 macro.EmbedObject: adjusted to changes of argument parser, escaped output.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3261
diff changeset
64 width = '%dpx' % int(width[0])
f62792cb2d24 macro.EmbedObject: adjusted to changes of argument parser, escaped output.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3261
diff changeset
65 else:
f62792cb2d24 macro.EmbedObject: adjusted to changes of argument parser, escaped output.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3261
diff changeset
66 width = '%g%s' % width
3261
cbaf672bcea3 fix EmbedObject UnitArgument usage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3260
diff changeset
67
3266
f62792cb2d24 macro.EmbedObject: adjusted to changes of argument parser, escaped output.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3261
diff changeset
68 if height:
f62792cb2d24 macro.EmbedObject: adjusted to changes of argument parser, escaped output.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3261
diff changeset
69 if height[1] == 'px':
f62792cb2d24 macro.EmbedObject: adjusted to changes of argument parser, escaped output.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3261
diff changeset
70 height = '%dpx' % int(height[0])
f62792cb2d24 macro.EmbedObject: adjusted to changes of argument parser, escaped output.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3261
diff changeset
71 else:
f62792cb2d24 macro.EmbedObject: adjusted to changes of argument parser, escaped output.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3261
diff changeset
72 height = '%g%s' % height
3261
cbaf672bcea3 fix EmbedObject UnitArgument usage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3260
diff changeset
73
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
74 request = macro.request
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
75 _ = macro.request.getText
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
76 fmt = macro.formatter
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
77
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
78 # AttachFile calls always with pagename. Users can call the macro from a different page as the attachment is saved.
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
79 if not pagename:
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
80 pagename = fmt.page.page_name
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
81
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
82 if not wikiutil.is_URL(target):
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
83 pagename, fname = AttachFile.absoluteName(target, pagename)
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
84
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
85 if not AttachFile.exists(request, pagename, fname):
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
86 linktext = _('Upload new attachment "%(filename)s"') % {'filename': fname}
5098
ff588e9e24d6 simplify getAttachUrl: remove upload parameter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4734
diff changeset
87 target = AttachFile.getAttachUrl(pagename, fname, request, do='upload_form')
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
88 return (fmt.url(1, target) +
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
89 fmt.text(linktext) +
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
90 fmt.url(0))
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
91
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
92 url = AttachFile.getAttachUrl(pagename, fname, request)
3253
ba0707fe183d EmbedObject: fixed some variable names, and escaping of target in AttachFile
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3250
diff changeset
93 mt = wikiutil.MimeType(filename=fname)
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
94 else:
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
95 if not url_mimetype:
3277
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
96 return fmt.text(_('%(extension_name)s %(extension_type)s: Required argument %(argument_name)s missing.') % {
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
97 "extension_name": extension_name,
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
98 "extension_type": extension_type,
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
99 "argument_name": "url_mimetype",
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
100 })
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
101 else:
3277
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
102 url = target
3253
ba0707fe183d EmbedObject: fixed some variable names, and escaping of target in AttachFile
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3250
diff changeset
103 mt = wikiutil.MimeType() # initialize dict
3277
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
104 try:
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
105 mt.major, mt.minor = url_mimetype.split('/')
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
106 except ValueError:
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
107 return fmt.text(_('%(extension_name)s %(extension_type)s: Invalid %(argument_name)s=%(argument_value)s!') % {
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
108 "extension_name": extension_name,
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
109 "extension_type": extension_type,
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
110 "argument_name": "url_mimetype",
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
111 "argument_value": str(url_mimetype),
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
112 })
3294
e342c92094f4 fix some PEP8 test failures
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3277
diff changeset
113
3253
ba0707fe183d EmbedObject: fixed some variable names, and escaping of target in AttachFile
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3250
diff changeset
114 mime_type = "%s/%s" % (mt.major, mt.minor, )
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
115 dangerous = mime_type in request.cfg.mimetypes_xss_protect
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
116
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
117 if not mime_type in request.cfg.mimetypes_embed or dangerous:
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
118 return "%s: %s%s%s" % (fmt.text(
3277
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
119 _("Current configuration does not allow embedding of the file %(file)s because of its mimetype %(mimetype)s.") % {
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
120 "mimetype": mime_type,
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
121 "file": target}),
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
122 fmt.url(1, url),
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
123 fmt.text(target),
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
124 fmt.url(0))
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
125
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
126 if not alt:
3277
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
127 alt = "%(text)s %(mime_type)s" % {'text': _("Embedded"), 'mime_type': mime_type}
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
128
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
129 embed_src = ''
3253
ba0707fe183d EmbedObject: fixed some variable names, and escaping of target in AttachFile
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3250
diff changeset
130 if mt.major == 'video':
3266
f62792cb2d24 macro.EmbedObject: adjusted to changes of argument parser, escaped output.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3261
diff changeset
131 if not width and not height:
f62792cb2d24 macro.EmbedObject: adjusted to changes of argument parser, escaped output.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3261
diff changeset
132 width = '400px'
f62792cb2d24 macro.EmbedObject: adjusted to changes of argument parser, escaped output.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3261
diff changeset
133 height = '400px'
f62792cb2d24 macro.EmbedObject: adjusted to changes of argument parser, escaped output.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3261
diff changeset
134
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
135 embed_src = '''
3022
e757ebc436e7 EmbedObject: refactored to use not empty params, for pdf default width="800" and height="800" added (backport to 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2788
diff changeset
136 <object %(ob_data)s %(ob_type)s %(ob_width)s %(ob_height)s %(ob_align)s %(ob_standby)s %(ob_stop)s>
3260
b971703ee4a9 macro.EmbedObject: beautified output, bug fix for quality param
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3253
diff changeset
137 %(wmode)s%(movie)s%(play)s%(stop)s%(repeat)s%(autostart)s%(op)s%(menu)s
3022
e757ebc436e7 EmbedObject: refactored to use not empty params, for pdf default width="800" and height="800" added (backport to 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2788
diff changeset
138 <p>%(alt)s</p>
2784
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
139 </object>''' % {
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
140 "ob_data": _check_object_value("data", url),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
141 "ob_type": _check_object_value("type", mime_type),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
142 "ob_width": _check_object_value("width", width),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
143 "ob_height": _check_object_value("height", height),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
144 "ob_align": _check_object_value("align", align),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
145 "ob_standby": _check_object_value("standby", alt),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
146 "ob_stop": _check_object_value("stop", stop),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
147 "wmode": _check_param_value("wmode", wmode, "data"),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
148 "movie": _check_param_value("movie", url, "data"),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
149 "play": _check_param_value("play", play, "data"),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
150 "stop": _check_param_value("stop", stop, "data"),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
151 "repeat": _check_param_value("repeat", repeat, "data"),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
152 "autostart": _check_param_value("autostart", autostart, "data"),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
153 "op": _check_param_value("op", op, "data"),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
154 "menu": _check_param_value("menu", menu, "data"),
3266
f62792cb2d24 macro.EmbedObject: adjusted to changes of argument parser, escaped output.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3261
diff changeset
155 "alt": wikiutil.escape(alt),
879
49d164e275f3 EmbedObject macro (backport to 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
156 }
1607
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
157
3307
f4212fb5ecb0 EmbedObject: fixed bug for image mimetype and configured when to call EmbedObject
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3294
diff changeset
158 elif mt.major in ['image', 'chemical', 'x-world']:
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
159 embed_src = '''
3022
e757ebc436e7 EmbedObject: refactored to use not empty params, for pdf default width="800" and height="800" added (backport to 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2788
diff changeset
160 <object %(ob_data)s %(ob_type)s %(ob_width)s %(ob_height)s %(ob_align)s>
3334
3f61d2b76e23 macro.EmbedObject: fixed typo
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3307
diff changeset
161 %(name)s
1876
e308a0e74069 EmbedObject: alt tag code from Oliver Siemoneit added and some optimisations
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1872
diff changeset
162 <p>%(alt)s</p>
2784
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
163 </object>''' % {
3307
f4212fb5ecb0 EmbedObject: fixed bug for image mimetype and configured when to call EmbedObject
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3294
diff changeset
164 "mime_type": mime_type,
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
165 "ob_data": _check_object_value("data", url),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
166 "ob_width": _check_object_value("width", width),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
167 "ob_height": _check_object_value("height", height),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
168 "ob_type": _check_object_value("type", mime_type),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
169 "ob_align": _check_object_value("align", align),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
170 "name": _check_param_value("name", url, "data"),
3266
f62792cb2d24 macro.EmbedObject: adjusted to changes of argument parser, escaped output.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3261
diff changeset
171 "alt": wikiutil.escape(alt),
879
49d164e275f3 EmbedObject macro (backport to 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
172 }
1607
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
173
3307
f4212fb5ecb0 EmbedObject: fixed bug for image mimetype and configured when to call EmbedObject
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3294
diff changeset
174 elif mt.major == 'audio':
3266
f62792cb2d24 macro.EmbedObject: adjusted to changes of argument parser, escaped output.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3261
diff changeset
175 if not width and not height:
f62792cb2d24 macro.EmbedObject: adjusted to changes of argument parser, escaped output.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3261
diff changeset
176 width = '400px'
f62792cb2d24 macro.EmbedObject: adjusted to changes of argument parser, escaped output.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3261
diff changeset
177 height = '100px'
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
178 embed_src = '''
3022
e757ebc436e7 EmbedObject: refactored to use not empty params, for pdf default width="800" and height="800" added (backport to 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2788
diff changeset
179 <object %(ob_data)s %(ob_type)s %(ob_width)s %(ob_height)s %(ob_align)s>
3260
b971703ee4a9 macro.EmbedObject: beautified output, bug fix for quality param
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3253
diff changeset
180 %(audio)s%(repeat)s%(autostart)s%(op)s%(play)s%(stop)s%(hidden)s<p>%(alt)s</p>
3022
e757ebc436e7 EmbedObject: refactored to use not empty params, for pdf default width="800" and height="800" added (backport to 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2788
diff changeset
181 </object>''' % {
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
182 "ob_data": _check_object_value("data", url),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
183 "ob_width": _check_object_value("width", width or "60"),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
184 "ob_height": _check_object_value("height", height or "20"),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
185 "ob_type": _check_object_value("type", mime_type),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
186 "ob_align": _check_object_value("align", align),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
187 "audio": _check_param_value("audio", url, "data"),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
188 "repeat": _check_param_value("repeat", repeat, "data"),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
189 "autostart": _check_param_value("autostart", autostart, "data"),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
190 "op": _check_param_value("op", op, "data"),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
191 "play": _check_param_value("play", play, "data"),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
192 "stop": _check_param_value("stop", stop, "data"),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
193 "hidden": _check_param_value("hidden", hidden, "data"),
3266
f62792cb2d24 macro.EmbedObject: adjusted to changes of argument parser, escaped output.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3261
diff changeset
194 "alt": wikiutil.escape(alt),
1562
e90cb4da25fc added mov, mpg and midi support
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 950
diff changeset
195 }
1607
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
196
3307
f4212fb5ecb0 EmbedObject: fixed bug for image mimetype and configured when to call EmbedObject
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3294
diff changeset
197 elif mt.major == 'application':
4734
c538e2b0bba9 macro.EmbedObject: changed default width value for pdf files to 100%.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3517
diff changeset
198 # workaround for the acroread browser plugin not knowing the size to embed
c538e2b0bba9 macro.EmbedObject: changed default width value for pdf files to 100%.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3517
diff changeset
199 # we use a width of 100% for the case that there is no width given.
c538e2b0bba9 macro.EmbedObject: changed default width value for pdf files to 100%.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3517
diff changeset
200 # A height of 100% gives a fullscreen pdf file view without embedding it into the wikicontent.
3253
ba0707fe183d EmbedObject: fixed some variable names, and escaping of target in AttachFile
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3250
diff changeset
201 if mt.minor == 'pdf':
4734
c538e2b0bba9 macro.EmbedObject: changed default width value for pdf files to 100%.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3517
diff changeset
202 width = width or '100%'
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
203 height = height or '800px'
3022
e757ebc436e7 EmbedObject: refactored to use not empty params, for pdf default width="800" and height="800" added (backport to 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2788
diff changeset
204
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
205 embed_src = '''
3507
792fd08a05b6 macro.EmbedObject: bug fix for missing movie param see MoinMoinBugs/EmbedObjectMissesToEmitParamMovie and emitting param values of "False" too.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3369
diff changeset
206 <object %(ob_data)s %(ob_type)s %(ob_width)s %(ob_height)s %(ob_align)s>
792fd08a05b6 macro.EmbedObject: bug fix for missing movie param see MoinMoinBugs/EmbedObjectMissesToEmitParamMovie and emitting param values of "False" too.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3369
diff changeset
207 %(movie)s%(quality)s%(wmode)s%(autostart)s%(play)s%(loop)s%(menu)s<p>%(alt)s</p>
2784
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
208 </object>''' % {
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
209 "ob_data": _check_object_value("data", url),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
210 "ob_width": _check_object_value("width", width),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
211 "ob_height": _check_object_value("height", height),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
212 "ob_type": _check_object_value("type", mime_type),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
213 "ob_align": _check_object_value("align", align),
3507
792fd08a05b6 macro.EmbedObject: bug fix for missing movie param see MoinMoinBugs/EmbedObjectMissesToEmitParamMovie and emitting param values of "False" too.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3369
diff changeset
214 "movie": _check_param_value("movie", url, "data"),
3260
b971703ee4a9 macro.EmbedObject: beautified output, bug fix for quality param
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3253
diff changeset
215 "quality": _check_param_value("quality", quality, "data"),
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
216 "wmode": _check_param_value("wmode", wmode, "data"),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
217 "autostart": _check_param_value("autostart", autostart, "data"),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
218 "play": _check_param_value("play", play, "data"),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
219 "loop": _check_param_value("loop", loop, "data"),
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
220 "menu": _check_param_value("menu", menu, "data"),
3266
f62792cb2d24 macro.EmbedObject: adjusted to changes of argument parser, escaped output.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3261
diff changeset
221 "alt": wikiutil.escape(alt),
1562
e90cb4da25fc added mov, mpg and midi support
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 950
diff changeset
222 }
879
49d164e275f3 EmbedObject macro (backport to 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
223
3277
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
224 return fmt.rawHTML(embed_src)