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.You are not allowed to attach a file to this page.