Attachment 'IncludePage.py'

Download

   1 """
   2     MoinMoin - IncludePage Macro
   3 
   4     You can use this macro to include a page through an <iframe>.
   5 
   6     Usage:
   7     <<IncludePage(FrontPage, 800, 600)>>
   8     <<IncludePage(MoinMoin:FrontPage, 800, 600)>>
   9     <<IncludePage(http://moinmo.in, 90%, 30%)>>
  10 
  11     You need to specify at least the page to inline and the width and the height of the iframe.
  12 
  13     Optionally you can customize ouput by using the following parameters:
  14     align=left/rigth: Aligns the frame to the left or right, text will float around [Default: no align and float]
  15     scrolling=yes/no: Turn on/off scrolling bars [Default: auto]
  16     marginwith=0: Set margin with [Default: 0]
  17     marginheight=0: Set margin height [Default: 0]
  18     frameborder=0: Set frameboarder [Default: 0]
  19     longdesc="Your text..": Give a sensible description for screenreader users [Default:""]
  20     
  21     Warning:
  22     Using <iframe> is not compliant with HTML strict standard. Therefore a common
  23     markup validation service will display an "invalid html" error message for a
  24     wiki page using this macro.
  25 
  26     @copyright: 2008 Oliver Siemoneit
  27     @license: GNU GPL, see COPYING for details.
  28 """
  29 
  30 from MoinMoin import wikiutil
  31 from MoinMoin.Page import Page
  32 
  33 def _is_url(text):
  34     return '://' in text
  35 
  36 def _is_interwiki(text):
  37     return ':' in text
  38 
  39 def execute(macro, text):
  40     request = macro.request
  41     formatter = macro.formatter
  42     _ = request.getText
  43 
  44     # Check for macro call without parameters
  45     if text is None: 
  46        text = u''
  47 
  48     try:
  49         # Parse given arguments
  50         params, named_params, trailing = wikiutil.parse_quoted_separated(text)
  51         # Unpack parameters
  52         src, width, height = params
  53     except (ValueError, TypeError), err:
  54         return macro.format_error(err)
  55 
  56     # Prepare URL
  57     src = wikiutil.escape(src)
  58     if _is_url(src):
  59         pass
  60     elif _is_interwiki(src):
  61         wiki, page = wikiutil.split_interwiki(src)
  62         wikitag, wikiurl, wikitail, err = wikiutil.resolve_interwiki(request, wiki, page)
  63         src = wikiutil.join_wiki(wikiurl, wikitail)
  64     else:
  65         src = Page(request, src).url(request)
  66     
  67     # Escape other parameters and set defaults
  68     width = wikiutil.escape(width)
  69     height = wikiutil.escape(height)
  70     align = wikiutil.escape(named_params.get("align", ""))
  71     scrolling = wikiutil.escape(named_params.get("scrolling", "auto"))
  72     marginheight= wikiutil.escape(named_params.get("marginheight","0"))
  73     marginwidth = wikiutil.escape(named_params.get("marginwidth", "0"))
  74     frameborder = wikiutil.escape(named_params.get("frameborder","0"))
  75     longdesc = wikiutil.escape(named_params.get("longdesc",""))
  76   
  77     # Output stuff
  78     result = """
  79 <iframe src="%(src)s" width="%(width)s" height="%(height)s" align="%(align)s" scrolling="%(scrolling)s" marginheight="%(marginheight)s" marginwidth="%(marginwidth)s" frameborder="%(frameborder)s" longdesc="%(longdesc)s">
  80     <p>%(error_msg)s <a href="%(src)s">%(src)s</a> </p>
  81 </iframe>
  82 """ % { 'src': src,
  83                  'width': width,
  84                  'height': height,
  85                  'align': align,
  86                  'scrolling': scrolling,
  87                  'marginheight': marginheight,
  88                  'marginwidth': marginwidth,
  89                  'frameborder': frameborder,
  90                  'longdesc': longdesc,
  91                  'error_msg': _("Your browser cannot display inlined frames. You can call the inlined page through the following link:") }
  92     
  93     return formatter.rawHTML(result)
  94 
  95     

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2008-05-29 20:30:35, 3.4 KB) [[attachment:IncludePage.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.