Edgewall Software

MacroBazaar: ParentWiki.py

File ParentWiki.py, 770 bytes (added by Muness Alrubaie <muness@…>, 7 years ago)
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
11
12def execute(hdf, args, env):
13    db = env.get_db_cnx()
14    cursor = db.cursor()
15
16    buf = StringIO()
17
18    prefix = None
19    if args:
20        prefix = args.replace('\'', '\'\'')
21    else :
22        prefix = hdf.getValue('wiki.page_name', '') + '/'
23
24
25    parent = 'WikiStart'
26
27    m = re.search("(\S+)/(\S+)$", prefix)
28    if m:
29        parent = m.group(1)
30
31    buf.write('<a href="%s">' % env.href.wiki(parent))
32    buf.write(parent)
33    buf.write('</a>\n')
34
35    return buf.getvalue()