source: trac/trunk/wiki-macros/SubWiki.2.py @ 2696

Revision 2591, 1.7 KB checked in by moschny, 8 years ago (diff)

Adding conf and wiki-macros directories

Line 
1"""
2Inserts an alphabetic list of sub-wiki pages into the output.
3A sub-wiki page is a page that is is deeper in the hierachy than the current page.  e.g. if the current page is People, the this will return a list of all wiki entries that start with "People/"
4
5Accepts a prefix string as parameter: if provided, only pages with names that
6start with the prefix are included in the resulting list. If this parameter is
7omitted, all pages are listed.
8
9This now takes the 2nd line (or whatever you decide in the line_number below) and grabs that line, and returns it as a description.  This is useful for us.
10
11"""
12
13from StringIO import StringIO
14
15def execute(hdf, args, env):
16    line_number = 2
17    db = env.get_db_cnx()
18    cursor = db.cursor()
19    cs = db.cursor()
20
21    prefix = None
22    if args:
23        prefix = args.replace('\'', '\'\'')
24    else :
25        prefix = hdf.getValue('wiki.page_name', '') + '/'
26
27    sql = 'SELECT DISTINCT name FROM wiki '
28    if prefix:
29        sql += 'WHERE name LIKE \'%s%%\' ' % prefix
30    sql += 'ORDER BY name'
31    cursor.execute(sql)
32
33    buf = StringIO()
34    buf.write('<ul>')
35    while 1:
36        row = cursor.fetchone()
37        if row == None:
38            break
39        name = row[0]
40        sql = 'SELECT name,text from wiki where name = \'%s\' order by version desc limit 1' % name
41        cs.execute(sql)
42        while 1:
43                csrow = cs.fetchone()
44                if csrow == None:
45                        break
46                name = csrow[0]
47                desc = csrow[1]
48                try:
49                        desc = desc.split('\n')
50                        desc = desc[line_number]
51                except IndexError:
52                        desc = ''
53                buf.write('<li><a href="%s">' % env.href.wiki(name))
54                buf.write(name)
55                buf.write('</a>&nbsp; &nbsp;')
56                buf.write(desc)
57                buf.write('</li>\n')
58    buf.write('</ul>')
59
60    return buf.getvalue()
61
Note: See TracBrowser for help on using the repository browser.