Back to index

moin  1.9.0~rc2
Functions
MoinMoin.macro.EmbedObject Namespace Reference

Functions

def _check_object_value
def _check_param_value
def macro_EmbedObject

Function Documentation

def MoinMoin.macro.EmbedObject._check_object_value (   param,
  value 
) [private]
helps to omit useless lines of object values

@param param: definition of object param
@param value: value of param

Definition at line 23 of file EmbedObject.py.

00023 
00024 def _check_object_value(param, value):
00025     """ helps to omit useless lines of object values
00026 
00027     @param param: definition of object param
00028     @param value: value of param
00029     """
00030     if value:
00031         return '%(param)s="%(value)s"' % {"param": param, "value": wikiutil.escape(value, True)}
00032     else:
00033         return ""

Here is the caller graph for this function:

def MoinMoin.macro.EmbedObject._check_param_value (   param,
  value,
  valuetype 
) [private]
helps to ommit useless lines of param values

@param param: param name defintion
@param value: the value
@param valuetype: the type of the value

Definition at line 34 of file EmbedObject.py.

00034 
00035 def _check_param_value(param, value, valuetype):
00036     """ helps to ommit useless lines of param values
00037 
00038     @param param: param name defintion
00039     @param value: the value
00040     @param valuetype: the type of the value
00041     """
00042     # Because plugins do have different defaults we have to write "False" too.
00043     if isinstance(value, bool):
00044         value = str(value)
00045 
00046     if value:
00047         return '''
00048 <param name="%(param)s" value="%(value)s" valuetype="%(valuetype)s">''' % {"param": param,
00049                                                                            "value": wikiutil.escape(value, True),
00050                                                                            "valuetype": valuetype}
00051     else:
00052         return ""

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.macro.EmbedObject.macro_EmbedObject (   macro,
  target = wikiutil.required_arg(unicode),
  pagename = None,
  width = wikiutil.UnitArgument(None, float,
  px,
  em,
  pt,
  in,
  mm,
  defaultunit = 'px',
  height = wikiutil.UnitArgument(None, float,
  px,
  em,
  pt,
  in,
  mm,
  defaultunit = 'px',
  alt = u'',
  play = False,
  stop = True,
  loop = False,
  quality = (u'high', u'low',
  u,
  medium,
  op = True,
  repeat = False,
  autostart = False,
  align = (u'middle', u'top',
  u,
  bottom,
  hidden = False,
  menu = True,
  wmode = u'transparent',
  url_mimetype = None 
)
This macro is used to embed an object into a wiki page 

Definition at line 59 of file EmbedObject.py.

00059 
00060                       menu=True, wmode=u'transparent', url_mimetype=None):
00061     """ This macro is used to embed an object into a wiki page """
00062     # Join unit arguments with their units
00063     if width:
00064         if width[1] == 'px':
00065             width = '%dpx' % int(width[0])
00066         else:
00067             width = '%g%s' % width
00068 
00069     if height:
00070         if height[1] == 'px':
00071             height = '%dpx' % int(height[0])
00072         else:
00073             height = '%g%s' % height
00074 
00075     request = macro.request
00076     _ = macro.request.getText
00077     fmt = macro.formatter
00078 
00079     # AttachFile calls always with pagename. Users can call the macro from a different page as the attachment is saved.
00080     if not pagename:
00081         pagename = fmt.page.page_name
00082 
00083     if not wikiutil.is_URL(target):
00084         pagename, fname = AttachFile.absoluteName(target, pagename)
00085 
00086         if not AttachFile.exists(request, pagename, fname):
00087             linktext = _('Upload new attachment "%(filename)s"') % {'filename': fname}
00088             target = AttachFile.getAttachUrl(pagename, fname, request, do='upload_form')
00089             return (fmt.url(1, target) +
00090                     fmt.text(linktext) +
00091                     fmt.url(0))
00092 
00093         url = AttachFile.getAttachUrl(pagename, fname, request)
00094         mt = wikiutil.MimeType(filename=fname)
00095     else:
00096         if not url_mimetype:
00097             return fmt.text(_('%(extension_name)s %(extension_type)s: Required argument %(argument_name)s missing.') % {
00098                 "extension_name": extension_name,
00099                 "extension_type": extension_type,
00100                 "argument_name": "url_mimetype",
00101             })
00102         else:
00103             url = target
00104             mt = wikiutil.MimeType() # initialize dict
00105             try:
00106                 mt.major, mt.minor = url_mimetype.split('/')
00107             except ValueError:
00108                 return fmt.text(_('%(extension_name)s %(extension_type)s: Invalid %(argument_name)s=%(argument_value)s!') % {
00109                    "extension_name": extension_name,
00110                    "extension_type": extension_type,
00111                    "argument_name": "url_mimetype",
00112                    "argument_value": str(url_mimetype),
00113                 })
00114 
00115     mime_type = "%s/%s" % (mt.major, mt.minor, )
00116     dangerous = mime_type in request.cfg.mimetypes_xss_protect
00117 
00118     if not mime_type in request.cfg.mimetypes_embed or dangerous:
00119         return "%s: %s%s%s" % (fmt.text(
00120                 _("Current configuration does not allow embedding of the file %(file)s because of its mimetype %(mimetype)s.") % {
00121                     "mimetype": mime_type,
00122                     "file": target}),
00123                 fmt.url(1, url),
00124                 fmt.text(target),
00125                 fmt.url(0))
00126 
00127     if not alt:
00128         alt = "%(text)s %(mime_type)s" % {'text': _("Embedded"), 'mime_type': mime_type}
00129 
00130     embed_src = ''
00131     if mt.major == 'video':
00132         if not width and not height:
00133             width = '400px'
00134             height = '400px'
00135 
00136         embed_src = '''
00137 <object %(ob_data)s %(ob_type)s %(ob_width)s %(ob_height)s %(ob_align)s %(ob_standby)s %(ob_stop)s>
00138 %(wmode)s%(movie)s%(play)s%(stop)s%(repeat)s%(autostart)s%(op)s%(menu)s
00139 <p>%(alt)s</p>
00140 </object>''' % {
00141     "ob_data": _check_object_value("data", url),
00142     "ob_type": _check_object_value("type", mime_type),
00143     "ob_width": _check_object_value("width", width),
00144     "ob_height": _check_object_value("height", height),
00145     "ob_align": _check_object_value("align", align),
00146     "ob_standby": _check_object_value("standby", alt),
00147     "ob_stop": _check_object_value("stop", stop),
00148     "wmode": _check_param_value("wmode", wmode, "data"),
00149     "movie": _check_param_value("movie", url, "data"),
00150     "play": _check_param_value("play", play, "data"),
00151     "stop": _check_param_value("stop", stop, "data"),
00152     "repeat": _check_param_value("repeat", repeat, "data"),
00153     "autostart": _check_param_value("autostart", autostart, "data"),
00154     "op": _check_param_value("op", op, "data"),
00155     "menu": _check_param_value("menu", menu, "data"),
00156     "alt": wikiutil.escape(alt),
00157 }
00158 
00159     elif mt.major in ['image', 'chemical', 'x-world']:
00160         embed_src = '''
00161 <object %(ob_data)s %(ob_type)s  %(ob_width)s %(ob_height)s %(ob_align)s>
00162 %(name)s
00163 <p>%(alt)s</p>
00164 </object>''' % {
00165     "mime_type": mime_type,
00166     "ob_data": _check_object_value("data", url),
00167     "ob_width": _check_object_value("width", width),
00168     "ob_height": _check_object_value("height", height),
00169     "ob_type": _check_object_value("type", mime_type),
00170     "ob_align": _check_object_value("align", align),
00171     "name": _check_param_value("name", url, "data"),
00172     "alt": wikiutil.escape(alt),
00173 }
00174 
00175     elif mt.major == 'audio':
00176         if not width and not height:
00177             width = '400px'
00178             height = '100px'
00179         embed_src = '''
00180 <object %(ob_data)s %(ob_type)s  %(ob_width)s %(ob_height)s %(ob_align)s>
00181 %(audio)s%(repeat)s%(autostart)s%(op)s%(play)s%(stop)s%(hidden)s<p>%(alt)s</p>
00182 </object>''' % {
00183     "ob_data": _check_object_value("data", url),
00184     "ob_width": _check_object_value("width", width or "60"),
00185     "ob_height": _check_object_value("height", height or "20"),
00186     "ob_type": _check_object_value("type", mime_type),
00187     "ob_align": _check_object_value("align", align),
00188     "audio": _check_param_value("audio", url, "data"),
00189     "repeat": _check_param_value("repeat", repeat, "data"),
00190     "autostart": _check_param_value("autostart", autostart, "data"),
00191     "op": _check_param_value("op", op, "data"),
00192     "play": _check_param_value("play", play, "data"),
00193     "stop": _check_param_value("stop", stop, "data"),
00194     "hidden": _check_param_value("hidden", hidden, "data"),
00195     "alt": wikiutil.escape(alt),
00196 }
00197 
00198     elif mt.major == 'application':
00199         # workaround for the acroread browser plugin not knowing the size to embed
00200         # we use a width of 100% for the case that there is no width given.
00201         # A height of 100% gives a fullscreen pdf file view without embedding it into the wikicontent.
00202         if mt.minor == 'pdf':
00203             width = width or '100%'
00204             height = height or '800px'
00205             embed_src = '''
00206 <object %(ob_data)s %(ob_type)s %(ob_width)s %(ob_height)s %(ob_align)s>
00207 <p>%(alt)s</p>
00208 </object>''' % {
00209     "ob_data": _check_object_value("data", url),
00210     "ob_width": _check_object_value("width", width),
00211     "ob_height": _check_object_value("height", height),
00212     "ob_type": _check_object_value("type", mime_type),
00213     "ob_align": _check_object_value("align", align),
00214     "alt": wikiutil.escape(alt),
00215 }
00216         else:
00217             embed_src = '''
00218 <object %(ob_data)s %(ob_type)s %(ob_width)s %(ob_height)s %(ob_align)s>
00219 %(movie)s%(quality)s%(wmode)s%(autostart)s%(play)s%(loop)s%(menu)s<p>%(alt)s</p>
00220 </object>''' % {
00221     "ob_data": _check_object_value("data", url),
00222     "ob_width": _check_object_value("width", width),
00223     "ob_height": _check_object_value("height", height),
00224     "ob_type": _check_object_value("type", mime_type),
00225     "ob_align": _check_object_value("align", align),
00226     "movie": _check_param_value("movie", url, "data"),
00227     "quality": _check_param_value("quality", quality, "data"),
00228     "wmode": _check_param_value("wmode", wmode, "data"),
00229     "autostart": _check_param_value("autostart", autostart, "data"),
00230     "play": _check_param_value("play", play, "data"),
00231     "loop": _check_param_value("loop", loop, "data"),
00232     "menu": _check_param_value("menu", menu, "data"),
00233     "alt": wikiutil.escape(alt),
00234 }
00235 
00236     return fmt.rawHTML(embed_src)

Here is the call graph for this function:

Here is the caller graph for this function: