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, 2012 Le Quoc Viet
  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 macro_IncludePage(macro, src=str, width=str, height=str, **kwargs):
  40     request = macro.request
  41     formatter = macro.formatter
  42     _ = request.getText
  43     named_params = dict(kwargs)
  44     
  45     # Prepare URL
  46     src = wikiutil.escape(src)
  47     if _is_url(src):
  48         pass
  49     elif _is_interwiki(src):
  50         wiki, page = wikiutil.split_interwiki(src)
  51         wikitag, wikiurl, wikitail, err = wikiutil.resolve_interwiki(request, wiki, page)
  52         src = wikiutil.join_wiki(wikiurl, wikitail)
  53     else:
  54         src = Page(request, src).url(request)
  55     
  56     # Escape other parameters and set defaults
  57     width = wikiutil.escape(width)
  58     height = wikiutil.escape(height)
  59     align = wikiutil.escape(named_params.get("align", ""))
  60     scrolling = wikiutil.escape(named_params.get("scrolling", "auto"))
  61     marginheight= wikiutil.escape(named_params.get("marginheight","0"))
  62     marginwidth = wikiutil.escape(named_params.get("marginwidth", "0"))
  63     frameborder = wikiutil.escape(named_params.get("frameborder","0"))
  64     longdesc = wikiutil.escape(named_params.get("longdesc",""))
  65     
  66     # Output stuff
  67     result = """
  68 <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">
  69     <p>%(error_msg)s <a href="%(src)s">%(src)s</a> </p>
  70 </iframe>
  71 """ % { 'src': src,
  72                  'width': width,
  73                  'height': height,
  74                  'align': align,
  75                  'scrolling': scrolling,
  76                  'marginheight': marginheight,
  77                  'marginwidth': marginwidth,
  78                  'frameborder': frameborder,
  79                  'longdesc': longdesc,
  80                  'error_msg': _("Your browser cannot display inlined frames. You can call the inlined page through the following link:") }
  81     
  82     return formatter.rawHTML(result)

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] (2012-11-13 08:14:41, 3.2 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.