| 1 | """ |
|---|
| 2 | Inserts a link to the "parent" wiki entry. |
|---|
| 3 | |
|---|
| 4 | This only applies to wikis that have a "/" in their name indicating heirarchy. |
|---|
| 5 | |
|---|
| 6 | e.g. an entry named Java/Introduction will have a parent of Java. All other wiki entries have a parent of WikiStart. |
|---|
| 7 | """ |
|---|
| 8 | |
|---|
| 9 | import re |
|---|
| 10 | from StringIO import StringIO |
|---|
| 11 | |
|---|
| 12 | def 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() |
|---|