annotate MoinMoin/macro/EmbedObject.py @ 2788:e857c1c3eca1

EmbedObject: msg strings corrected for new macro syntax and external url call parameter renamed
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Fri, 31 Aug 2007 12:57:40 +0200
parents 1cb372eb7935
children e757ebc436e7
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
2784
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
9 <<EmbedObject(attachment[,width=width][,height=height][,alt=Embedded mimetpye/xy])>>
879
49d164e275f3 EmbedObject macro (backport to 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
10
2784
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
11 @copyright: 2006-2007 MoinMoin:ReimarBauer,
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
1607
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
21 class EmbedObject:
879
49d164e275f3 EmbedObject macro (backport to 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
22
1607
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
23 def __init__(self, macro, args):
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
24 self._ = macro.request.getText
1607
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
25 self.macro = macro
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
26 self.request = macro.request
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
27 self.formatter = macro.formatter
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
28 self.args = args
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
29 self.width = ""
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
30 self.height = ""
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
31 self.alt = ""
1607
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
32 self.play = "false"
2784
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
33 self.stop = "true"
1607
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
34 self.loop = "false"
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
35 self.quality = "high"
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
36 self.op = "true"
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
37 self.repeat = "false"
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
38 self.autostart = "false"
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
39 self.align = "center"
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
40 self.hidden = "false"
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
41 self.menu = "true"
2784
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
42 self.wmode = "transparent"
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
43 self.target = None
2784
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
44 self.align = "middle"
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
45 self.url_mimetype = None
1607
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
46
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
47 if args:
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
48 args = args.split(',')
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
49 args = [arg.strip() for arg in args]
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
50 else:
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
51 args = []
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
52
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
53 kw_count = 0
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
54 argc = len(args)
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
55 if args:
e308a0e74069 EmbedObject: alt tag code from Oliver Siemoneit added and some optimisations
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1872
diff changeset
56 for arg in self.args.split(','):
e308a0e74069 EmbedObject: alt tag code from Oliver Siemoneit added and some optimisations
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1872
diff changeset
57 if '=' in arg:
e308a0e74069 EmbedObject: alt tag code from Oliver Siemoneit added and some optimisations
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1872
diff changeset
58 kw_count += 1
e308a0e74069 EmbedObject: alt tag code from Oliver Siemoneit added and some optimisations
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1872
diff changeset
59 key, value = arg.split('=')
e308a0e74069 EmbedObject: alt tag code from Oliver Siemoneit added and some optimisations
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1872
diff changeset
60 setattr(self, key, wikiutil.escape(value.strip(), quote=1))
e308a0e74069 EmbedObject: alt tag code from Oliver Siemoneit added and some optimisations
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1872
diff changeset
61 argc -= kw_count
1607
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
62 self.target = args[0]
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
63
2784
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
64 def _is_URL(self, text):
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
65 """ Answer true if text is an URL.
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
66 The method used here is pretty dumb. Improvements are welcome.
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
67 """
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
68 return '://' in text
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
69
1981
6c58db46c2ed EmbedObject:minor optimisation
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1978
diff changeset
70 def embed(self, mt, url):
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
71 _ = self._
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
72
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
73 if not mt:
2293
bb76818db210 i18n fixes, mostly _('aa'%xx) -> _('aa')%xx
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
74 return _("Not supported mimetype of file: %s") % self.target
1952
8ab85e3711dc AttachFile:send_viewfile extended for mimetypes presentable by EmbedObject
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1920
diff changeset
75
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1983
diff changeset
76 mime_type = "%s/%s" % (mt.major, mt.minor, )
1983
c563b49b8b03 EmbedObject:removed mimetype application/x-shockwave-flash from defaults
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1981
diff changeset
77 dangerous = mime_type in self.request.cfg.mimetypes_xss_protect
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1983
diff changeset
78
1983
c563b49b8b03 EmbedObject:removed mimetype application/x-shockwave-flash from defaults
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1981
diff changeset
79 if not mime_type in self.request.cfg.mimetypes_embed or dangerous:
c563b49b8b03 EmbedObject:removed mimetype application/x-shockwave-flash from defaults
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1981
diff changeset
80 kw = {'src': url}
2293
bb76818db210 i18n fixes, mostly _('aa'%xx) -> _('aa')%xx
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
81 return "%s: %s%s%s" % (self.macro.formatter.text(_('Embedding of object by choosen formatter not possible')),
1983
c563b49b8b03 EmbedObject:removed mimetype application/x-shockwave-flash from defaults
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1981
diff changeset
82 self.macro.formatter.url(1, kw['src']),
c563b49b8b03 EmbedObject:removed mimetype application/x-shockwave-flash from defaults
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1981
diff changeset
83 self.macro.formatter.text(self.target),
c563b49b8b03 EmbedObject:removed mimetype application/x-shockwave-flash from defaults
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1981
diff changeset
84 self.macro.formatter.url(0))
1607
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
85
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
86 if self.alt is "":
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
87 self.alt = "%(text)s %(mime_type)s" % {
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1983
diff changeset
88 'text': _("Embedded"),
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
89 'mime_type': mime_type,
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
90 }
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
91
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
92 if mt.major == 'video':
1607
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
93 return '''
2784
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
94 <object data="%(url)s" type="%(type)s" width="%(width)s" height="%(height)s" align="%(align)s" standby="%(alt)s" stop="%(stop)s">
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
95 <param name="wmode" value="%(wmode)s" valuetype="data">
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
96 <param name="movie" value="%(url)s" valuetype="data">
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
97 <param name="play" value="%(play)s" valuetype="data">
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
98 <param name="stop" value="%(stop)s" valuetype="data">
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
99 <param name="repeat" value="%(repeat)s" valuetype="data">
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
100 <param name="autostart" value="%(autostart)s" valuetype="data">
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
101 <param name="op" value="%(op)s" valuetype="data">
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
102 <param name="menu" value="%(menu)s" valuetype="data">
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
103 %(alt)s
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
104 </object>''' % {
1607
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
105 "width": self.width,
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
106 "height": self.height,
1981
6c58db46c2ed EmbedObject:minor optimisation
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1978
diff changeset
107 "url": url,
2784
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
108 "play": self.play,
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
109 "stop": self.stop,
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
110 "align": self.align,
1607
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
111 "repeat": self.repeat,
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
112 "autostart": self.autostart,
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
113 "op": self.op,
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
114 "type": mime_type,
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
115 "menu": self.menu,
2784
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
116 "wmode": self.wmode,
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
117 "alt": self.alt,
879
49d164e275f3 EmbedObject macro (backport to 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
118 }
1607
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
119
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
120 if mt.major in ['image', 'chemical', 'x-world']:
1607
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
121 return '''
2784
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
122 <object data="%(url)s" width="%(width)s" height="%(height)s" type="%(type)s" align="%(align)s">
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
123 <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
124 <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
125 </object>''' % {
1607
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
126 "width": self.width,
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
127 "height": self.height,
1981
6c58db46c2ed EmbedObject:minor optimisation
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1978
diff changeset
128 "url": url,
2784
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
129 "align": self.align,
1607
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
130 "type": mime_type,
2784
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
131 "major": mt.major,
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
132 "alt": self.alt,
879
49d164e275f3 EmbedObject macro (backport to 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
133 }
1607
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
134
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
135 if mt.major == 'audio':
1607
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
136 return '''
2784
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
137 <object data="%(url)s" width="%(width)s" height="%(height)s" type="%(type)s" align="%(align)s">
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
138 <param name="audio" value="%(url)s">
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
139 <param name="repeat" value="%(repeat)s">
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
140 <param name="autostart" value="%(autostart)s">
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
141 <param name="op" value="%(op)s">
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
142 <param name="play" value="%(play)s">
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
143 <param name="stop" value="%(stop)s" valuetype="data">
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
144 <param name="hidden" value="%(hidden)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
145 <p>%(alt)s</p>
1562
e90cb4da25fc added mov, mpg and midi support
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 950
diff changeset
146 </OBJECT>''' % {
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
147 "width": self.width or "60",
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
148 "height": self.height or "20",
1981
6c58db46c2ed EmbedObject:minor optimisation
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1978
diff changeset
149 "url": url,
2784
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
150 "align": self.align,
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
151 "play": self.play,
2784
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
152 "stop": self.stop,
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
153 "repeat": self.repeat,
e308a0e74069 EmbedObject: alt tag code from Oliver Siemoneit added and some optimisations
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1872
diff changeset
154 "autostart": self.autostart,
e308a0e74069 EmbedObject: alt tag code from Oliver Siemoneit added and some optimisations
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1872
diff changeset
155 "op": self.op,
e308a0e74069 EmbedObject: alt tag code from Oliver Siemoneit added and some optimisations
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1872
diff changeset
156 "hidden": self.hidden,
e308a0e74069 EmbedObject: alt tag code from Oliver Siemoneit added and some optimisations
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1872
diff changeset
157 "type": mime_type,
e308a0e74069 EmbedObject: alt tag code from Oliver Siemoneit added and some optimisations
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1872
diff changeset
158 "alt": self.alt,
1562
e90cb4da25fc added mov, mpg and midi support
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 950
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
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
161 if mt.major == 'application':
1607
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
162 return '''
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 data="%(url)s" width="%(width)s" height="%(height)s" type="%(type)s" align="%(align)s">
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="wmode" value="%(wmode)s" valuetype="data">
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
165 <param name="autostart" value="%(autostart)s">
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
166 <param name="play" value="%(play)s">
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
167 <param name="loop" value="%(loop)s">
2785
ff1886a5defa EmbedObject:PEP8 fixes
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2784
diff changeset
168 <param name="menu" value="%(menu)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
169 <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
170 </object>''' % {
1607
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
171 "width": self.width,
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
172 "height": self.height,
1981
6c58db46c2ed EmbedObject:minor optimisation
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1978
diff changeset
173 "url": url,
2784
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
174 "align": self.align,
1607
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
175 "autostart": self.autostart,
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
176 "play": self.play,
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
177 "loop": self.loop,
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
178 "type": mime_type,
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
179 "menu": self.menu,
2784
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
180 "wmode": self.wmode,
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
181 "alt": self.alt,
1562
e90cb4da25fc added mov, mpg and midi support
ReimarBauer <R.Bauer@fz-juelich.de>
parents: 950
diff changeset
182 }
879
49d164e275f3 EmbedObject macro (backport to 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
183
1607
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
184 def render(self):
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
185 _ = self._
e308a0e74069 EmbedObject: alt tag code from Oliver Siemoneit added and some optimisations
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1872
diff changeset
186
e308a0e74069 EmbedObject: alt tag code from Oliver Siemoneit added and some optimisations
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1872
diff changeset
187 if not self.target:
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
188 msg = _('Not enough arguments to EmbedObject macro! Try <<EmbedObject(attachment [,width=width] [,height=height] [,alt=Embedded mimetpye/xy])>>', formatted=False)
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
189 return "%s%s%s" % (self.formatter.sysmsg(1), self.formatter.text(msg), self.formatter.sysmsg(0))
1607
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
190
2784
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
191 if not self._is_URL(self.target):
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
192 pagename, fname = AttachFile.absoluteName(self.target, self.formatter.page.page_name)
1607
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
193
2784
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
194 if not AttachFile.exists(self.request, pagename, fname):
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
195 linktext = _('Upload new attachment "%(filename)s"')
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
196 return wikiutil.link_tag(self.request, ('%s?action=AttachFile&rename=%s' % (
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
197 wikiutil.quoteWikinameURL(pagename),
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
198 wikiutil.url_quote_plus(fname))),
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
199 linktext % {'filename': fname})
1607
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
200
2784
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
201 url = AttachFile.getAttachUrl(pagename, fname, self.request)
1607
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
202
2784
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
203 mt = wikiutil.MimeType(filename=fname)
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
204 else:
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
205 if not self.url_mimetype:
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
206 return _('Not enough arguments to EmbedObject macro! Try <<EmbedObject(url, url_mimetype [,width=width] [,height=height] [,alt=Embedded mimetpye/xy])>>', formatted=False)
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
207 else:
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
208 mt = wikiutil.MimeType() # initialize dict
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
209 mt.major, mt.minor = self.url_mimetype.split('/')
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
210 url = wikiutil.escape(self.target)
2784
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
211
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
212 # XXX Should better use formatter.embed if available?
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
213 return self.macro.formatter.rawHTML(self.embed(mt, url))
1607
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
214
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
215 def execute(macro, args):
9131797454fb updated EmbedObject macro (thanks to Reimar Bauer)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1562
diff changeset
216 return EmbedObject(macro, args).render()
2784
02a8bde864ab EmbedObject: refactored to use only object for valid html 4
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2725
diff changeset
217