Edgewall Software

MacroBazaar: ParentWiki.2.py

File ParentWiki.2.py, 806 bytes (added by dexdev@…, 5 years ago)

0.10 patch

Line 
1"""
2Inserts a link to the "parent" wiki entry. 
3
4This only applies to wikis that have a "/" in their name indicating heirarchy. 
5
6e.g. an entry named Java/Introduction will have a parent of Java.  All other wiki entries have a parent of WikiStart.
7"""
8
9import re
10from StringIO import StringIO
11from trac import util
12
13def execute(hdf, args, env):
14    db = env.get_db_cnx()
15    cursor = db.cursor()
16
17    buf = StringIO()
18
19    prefix = None
20    if args:
21        prefix = args.replace('\'', '\'\'')
22    else :
23        prefix = hdf.getValue('wiki.page_name', '') + '/'
24
25
26    parent = 'WikiStart'
27
28    m = re.search("(\S+)/(\S+)$", prefix)
29    if m:
30        parent = m.group(1)
31
32    buf.write('<a href="%s">' % env.href.wiki(util.escape(parent)) )
33    buf.write(parent)
34    buf.write('</a>\n')
35
36    return buf.getvalue()