7
7
http://purl.net/wiki/moinmaster/HelpOnMacros/Include
11
@copyright: 2000-2004 by J�rgen Hermann <jh@web.de>
12
@copyright: 2000-2001 by Richard Jones <richard@bizarsoftware.com.au>
11
@copyright: 2000-2004 Juergen Hermann <jh@web.de>,
12
2000-2001 Richard Jones <richard@bizarsoftware.com.au>
13
13
@license: GNU GPL, see COPYING for details.
16
16
#Dependencies = ["pages"] # included page
17
17
Dependencies = ["time"] # works around MoinMoinBugs/TableOfContentsLacksLinks
19
generates_headings = True
19
21
import re, StringIO
20
22
from MoinMoin import wikiutil
21
23
from MoinMoin.Page import Page
22
from MoinMoin.util import web
24
26
_sysmsg = '<p><strong class="%s">%s</strong></p>'
44
46
for title, _ in title_re.findall(body):
47
while h[level:level+1] == '=': level = level+1
49
while h[level:level+1] == '=':
49
51
title_text = h[level:-level].strip()
50
52
titles.append((title_text, level))
53
def execute(macro, text, args_re=re.compile(_args_re_pattern), title_re=re.compile(_title_re, re.M), called_by_toc=0):
55
def execute(macro, text, args_re=re.compile(_args_re_pattern), title_re=re.compile(_title_re, re.M)):
54
56
request = macro.request
55
57
_ = request.getText
61
63
# parse and check arguments
62
64
args = text and args_re.match(text)
64
return (_sysmsg % ('error', _('Invalid include arguments "%s"!')) % (text,))
66
return (_sysmsg % ('error', _('Invalid include arguments "%s"!')) % (text, ))
66
68
# prepare including page
68
print_mode = macro.form.has_key('action') and macro.form['action'][0] in ("print", "format")
70
print_mode = request.action in ("print", "format")
69
71
this_page = macro.formatter.page
70
72
if not hasattr(this_page, '_macroInclude_pagelist'):
71
73
this_page._macroInclude_pagelist = {}
73
75
# get list of pages to include
74
inc_name = wikiutil.AbsPageName(request, this_page.page_name, args.group('name'))
76
inc_name = wikiutil.AbsPageName(this_page.page_name, args.group('name'))
75
77
pagelist = [inc_name]
76
78
if inc_name.startswith("^"):
101
103
for inc_name in pagelist:
102
104
if not request.user.may.read(inc_name):
104
if this_page._macroInclude_pagelist.has_key(inc_name):
105
result.append(u'<p><strong class="error">Recursive include of "%s" forbidden</strong></p>' % (inc_name,))
106
if inc_name in this_page._macroInclude_pagelist:
107
result.append(u'<p><strong class="error">Recursive include of "%s" forbidden</strong></p>' % (inc_name, ))
171
172
##result.append("*** f=%s t=%s ***" % (from_re, to_re))
172
173
##result.append("*** f=%d t=%d ***" % (from_pos, to_pos))
175
result.append(inc_page.get_raw_body())
178
175
if not hasattr(request, "_Include_backto"):
179
176
request._Include_backto = this_page.page_name
183
180
if args.group('heading') and args.group('hquote'):
184
heading = args.group('htext') or inc_page.split_title(request)
181
heading = args.group('htext') or inc_page.split_title()
186
183
if args.group('level'):
187
184
level = int(args.group('level'))
190
187
macro.formatter.text(heading) +
191
188
macro.formatter.heading(0, level))
194
from MoinMoin import config
195
# this heading id might produce duplicate ids,
196
# if the same page is included multiple times
197
# Encode stuf we feed into sha module.
198
pntt = (inc_name + heading).encode(config.charset)
199
hid = "head-" + sha.new(pntt).hexdigest()
200
request._page_headings.setdefault(pntt, 0)
201
request._page_headings[pntt] += 1
202
if request._page_headings[pntt] > 1:
203
hid += '-%d'%(request._page_headings[pntt],)
205
#macro.formatter.heading(1, level, hid,
206
# icons=edit_icon.replace('<img ', '<img align="right" ')) +
207
macro.formatter.heading(1, level, id=hid) +
208
inc_page.link_to(request, heading, css_class="include-heading-link") +
209
macro.formatter.heading(0, level)
190
url = inc_page.url(request)
192
macro.formatter.heading(1, level, id=heading),
193
macro.formatter.url(1, url, css="include-heading-link"),
194
macro.formatter.text(heading),
195
macro.formatter.url(0),
196
macro.formatter.heading(0, level),
212
199
# set or increment include marker
213
200
this_page._macroInclude_pagelist[inc_name] = \
217
204
strfile = StringIO.StringIO()
218
205
request.redirect(strfile)
220
cid = request.makeUniqueID("Include_%s" % wikiutil.quoteWikinameURL(inc_page.page_name))
221
inc_page.send_page(request, content_only=1, content_id=cid,
207
inc_page.send_page(content_only=True,
223
210
result.append(strfile.getvalue())
225
212
request.redirect()
235
222
if editlink and not (level or print_mode):
237
224
macro.formatter.div(1, css_class="include-link"),
238
inc_page.link_to(request, '[%s]' % (inc_name,), css_class="include-page-link"),
239
inc_page.link_to(request, '[%s]' % (_('edit'),), css_class="include-edit-link", querystr={'action': 'edit', 'backto': request._Include_backto}),
225
inc_page.link_to(request, '[%s]' % (inc_name, ), css_class="include-page-link"),
226
inc_page.link_to(request, '[%s]' % (_('edit'), ), css_class="include-edit-link", querystr={'action': 'edit', 'backto': request._Include_backto}),
240
227
macro.formatter.div(0),
242
229
# XXX page.link_to is wrong now, it escapes the edit_icon html as it escapes normal text