annotate MoinMoin/macro/EmbedObject.py @ 3277:e79c742eaca7

EmbedObject macro: misc. fixes / cleanups
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 17 Mar 2008 00:00:28 +0100
parents 753f234085c2
children e342c92094f4
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 """
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
41 if value:
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
42 return '''
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
43 <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
44 "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
45 "valuetype": valuetype}
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
46 else:
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
47 return ""
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1983
diff changeset
48
3277
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
49 def macro_EmbedObject(macro, target=None, pagename=None,
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
50 width=wikiutil.UnitArgument(None, float, ['px', 'em', 'mm', '%']),
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
51 height=wikiutil.UnitArgument(None, float, ['px', 'em', 'mm', '%']),
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
52 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
53 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
54 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
55 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
56 """ 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
57 # 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
58 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
59 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
60 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
61 else:
f62792cb2d24 macro.EmbedObject: adjusted to changes of argument parser, escaped output.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3261
diff changeset
62 width = '%g%s' % width
3261
cbaf672bcea3 fix EmbedObject UnitArgument usage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3260
diff changeset
63
3266
f62792cb2d24 macro.EmbedObject: adjusted to changes of argument parser, escaped output.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3261
diff changeset
64 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
65 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
66 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
67 else:
f62792cb2d24 macro.EmbedObject: adjusted to changes of argument parser, escaped output.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3261
diff changeset
68 height = '%g%s' % height
3261
cbaf672bcea3 fix EmbedObject UnitArgument usage
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3260
diff changeset
69
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
70 request = macro.request
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
71 _ = macro.request.getText
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
72 fmt = macro.formatter
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
73
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
74 # 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
75 if not pagename:
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
76 pagename = fmt.page.page_name
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 if not target:
3277
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
79 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
80 "extension_name": extension_name,
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
81 "extension_type": extension_type,
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
82 "argument_name": "target",
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
83 })
3250
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 wikiutil.is_URL(target):
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
86 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
87
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
88 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
89 linktext = _('Upload new attachment "%(filename)s"') % {'filename': fname}
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
90 target = AttachFile.getAttachUrl(pagename, fname, request, upload=True)
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
91 return (fmt.url(1, target) +
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
92 fmt.text(linktext) +
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
93 fmt.url(0))
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
94
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
95 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
96 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
97 else:
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
98 if not url_mimetype:
3277
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
99 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
100 "extension_name": extension_name,
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
101 "extension_type": extension_type,
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
102 "argument_name": "url_mimetype",
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
103 })
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
104 else:
3277
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
105 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
106 mt = wikiutil.MimeType() # initialize dict
3277
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
107 try:
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
108 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
109 except ValueError:
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
110 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
111 "extension_name": extension_name,
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
112 "extension_type": extension_type,
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
113 "argument_name": "url_mimetype",
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
114 "argument_value": str(url_mimetype),
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
115 })
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
116
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
117 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
118 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
119
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
120 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
121 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
122 _("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
123 "mimetype": mime_type,
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
124 "file": target}),
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
125 fmt.url(1, url),
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
126 fmt.text(target),
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
127 fmt.url(0))
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
128
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
129 if not alt:
3277
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
130 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
131
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
132 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
133 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
134 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
135 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
136 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
137
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
138 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
139 <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
140 %(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
141 <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
142 </object>''' % {
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
143 "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
144 "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
145 "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
146 "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
147 "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
148 "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
149 "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
150 "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
151 "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
152 "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
153 "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
154 "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
155 "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
156 "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
157 "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
158 "alt": wikiutil.escape(alt),
879
49d164e275f3 EmbedObject macro (backport to 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
159 }
1607
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
160
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
161 if 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
162 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
163 <object %(ob_data)s %(ob_type)s %(ob_width)s %(ob_height)s %(ob_align)s>
2784
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
164 <param name="%(major)s" value="%(url)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
165 <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
166 </object>''' % {
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
167 "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
168 "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
169 "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
170 "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
171 "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
172 "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
173 "alt": wikiutil.escape(alt),
879
49d164e275f3 EmbedObject macro (backport to 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
174 }
1607
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
175
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
176 if 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
177 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
178 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
179 height = '100px'
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
180 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
181 <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
182 %(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
183 </object>''' % {
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
184 "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
185 "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
186 "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
187 "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
188 "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
189 "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
190 "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
191 "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
192 "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
193 "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
194 "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
195 "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
196 "alt": wikiutil.escape(alt),
1562
e90cb4da25fc added mov, mpg and midi support
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 950
diff changeset
197 }
1607
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
198
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
199 if mt.major == 'application':
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
200 # workaround for the acroread not knowing the size to embed
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':
3250
0f582c5d2b9f EmbedObject refactored for new arg parser
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3149
diff changeset
202 width = width or '800px'
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 = '''
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
206 <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
207 %(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),
3260
b971703ee4a9 macro.EmbedObject: beautified output, bug fix for quality param
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3253
diff changeset
214 "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
215 "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
216 "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
217 "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
218 "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
219 "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
220 "alt": wikiutil.escape(alt),
1562
e90cb4da25fc added mov, mpg and midi support
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 950
diff changeset
221 }
879
49d164e275f3 EmbedObject macro (backport to 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
222
3277
e79c742eaca7 EmbedObject macro: misc. fixes / cleanups
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3268
diff changeset
223 return fmt.rawHTML(embed_src)