Attachment 'SimpleInclude.py'

Download

   1 # -*- coding: iso-8859-1 -*-
   2 """
   3     MoinMoin - SimpleInclude Macro
   4     Version 0.1
   5 
   6     Includes the specified page in the current page
   7     [[SimpleInclude(pagename)]]
   8 
   9     @copyright: 2007 by Kenneth Bull
  10     @license: GNU GPL, see COPYING for details.
  11 
  12 """
  13 
  14 import StringIO
  15 from MoinMoin.Page import Page
  16 from MoinMoin import wikiutil
  17 
  18 def getPageContent(request, formatter, pagename):
  19     _ = request.getText
  20 
  21     inc_name = wikiutil.AbsPageName(request, formatter.page.page_name, pagename)
  22     this_page = formatter.page
  23 
  24     if not hasattr(this_page, '_macroInclude_pagelist'):
  25         this_page._macroInclude_pagelist = {}
  26 
  27     if this_page._macroInclude_pagelist.has_key(inc_name):
  28         return '<p><strong class="error">Recursive include of "%s" forbidden</strong></p>' % inc_name
  29 
  30     fmt = formatter.__class__(request, is_included=True)
  31     fmt._base_depth = formatter._base_depth
  32     inc_page = Page(request, inc_name, formatter=fmt)
  33 
  34     # set or increment include marker
  35     this_page._macroInclude_pagelist[inc_name] = \
  36         this_page._macroInclude_pagelist.get(inc_name, 0) + 1
  37 
  38     inc_page._macroInclude_pagelist = this_page._macroInclude_pagelist
  39 
  40     if not hasattr(request, "_Include_backto"):
  41         request._Include_backto = this_page.page_name
  42 
  43     # output the included page
  44     strfile = StringIO.StringIO()
  45     request.redirect(strfile)
  46     try:
  47         cid = request.makeUniqueID("Include_%s" % wikiutil.quoteWikinameURL(inc_page.page_name))
  48         inc_page.send_page(request, content_only=1, content_id=cid,
  49                            omit_footnotes=True)
  50     finally:
  51         request.redirect()
  52 
  53     # decrement or remove include marker
  54     if this_page._macroInclude_pagelist[inc_name] > 1:
  55         this_page._macroInclude_pagelist[inc_name] = \
  56             this_page._macroInclude_pagelist[inc_name] - 1
  57     else:
  58         del this_page._macroInclude_pagelist[inc_name]
  59 
  60     # return include text
  61     return strfile.getvalue()
  62 
  63 def getEditLink(request, formatter, pagename):
  64     _ = request.getText
  65     inc_name = wikiutil.AbsPageName(request, formatter.page.page_name, pagename)
  66     fmt = formatter.__class__(request, is_included=True)
  67     fmt._base_depth = formatter._base_depth
  68     inc_page = Page(request, inc_name, formatter=fmt)
  69     return "".join([formatter.div(1, css_class="include-link"),
  70                     inc_page.link_to(request, '[%s]' % (inc_name), css_class="include-page-link"),
  71                     inc_page.link_to(request, '[%s]' % (_('edit'),), css_class="include-edit-link", querystr={'action': 'edit', 'backto': request._Include_backto}),
  72                     formatter.div(0)])
  73 
  74 def execute(macro, args):
  75 #    print_mode = macro.form.has_key('action') and macro.form['action'][0] in ("print", "format")
  76     result = getPageContent(macro.request, macro.formatter, args)
  77     result += getEditLink(macro.request, macro.formatter, args)
  78     return 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] (2007-08-27 06:16:11, 0.5 KB) [[attachment:Clear.py]]
  • [get | view] (2007-08-28 23:30:49, 6.8 KB) [[attachment:Editor.py]]
  • [get | view] (2007-08-31 16:21:54, 6.5 KB) [[attachment:ImageBrowser.inc]]
  • [get | view] (2007-08-17 18:41:06, 23.6 KB) [[attachment:ImageBrowser.zip]]
  • [get | view] (2007-08-27 06:15:30, 12.1 KB) [[attachment:ImageBrowserContent.py]]
  • [get | view] (2007-08-17 20:07:21, 51.1 KB) [[attachment:ImageBrowserContent.zip]]
  • [get | view] (2007-08-27 22:38:27, 51.5 KB) [[attachment:ImageBrowserContent_0-2.zip]]
  • [get | view] (2007-08-28 19:24:15, 51.5 KB) [[attachment:ImageBrowserContent_0-3.zip]]
  • [get | view] (2007-08-30 21:15:21, 51.5 KB) [[attachment:ImageBrowserContent_0-4.zip]]
  • [get | view] (2007-08-30 22:05:48, 3.5 KB) [[attachment:ImageBrowserGenerator.zip]]
  • [get | view] (2007-08-17 18:41:18, 28.6 KB) [[attachment:ImageBrowserNoLoad.zip]]
  • [get | view] (2007-08-10 22:00:23, 23.1 KB) [[attachment:MacroMarket-ImageBrowser.zip]]
  • [get | view] (2007-08-14 18:43:08, 23.4 KB) [[attachment:MacroMarket-ImageBrowserNoLoad.zip]]
  • [get | view] (2007-08-28 23:30:19, 2.9 KB) [[attachment:SimpleInclude.py]]
  • [get | view] (2007-08-28 23:30:27, 0.2 KB) [[attachment:Test.py]]
  • [get | view] (2007-08-28 23:29:51, 0.9 KB) [[attachment:Thumbnail.py]]
  • [get | view] (2007-08-28 23:29:31, 5.2 KB) [[attachment:Thumbnail_action.py]]
  • [get | view] (2007-08-17 18:26:12, 160.3 KB) [[attachment:imagebrowser.png]]
  • [get | view] (2007-08-17 17:13:09, 39.0 KB) [[attachment:imagebrowsercontent.png]]
  • [get | view] (2007-08-17 17:55:36, 37.2 KB) [[attachment:imagebrowsercontent_closed.png]]
  • [get | view] (2007-08-22 16:42:34, 491.5 KB) [[attachment:imgbrwsr_images.zip]]
  • [get | view] (2007-08-28 23:28:39, 3.8 KB) [[attachment:imgbrwsrgen.py]]
 All files | Selected Files: delete move to page copy to page

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