Edgewall Software

MacroBazaar: UserChanges.py

File UserChanges.py, 1.3 KB (added by datrac@…, 8 years ago)

Displays the recently changed pages of a specific user.

Line 
1import time
2from StringIO import StringIO
3
4def execute(hdf, args, env):
5    db = env.get_db_cnx()
6    cursor = db.cursor()
7
8    author = limit = None
9    if args:
10        argv = [arg.strip() for arg in args.split(',')]
11        if len(argv) > 0:
12            author = argv[0].replace('\'', '\'\'')
13            if len(argv) > 1:
14                limit = int(argv[1])
15
16    sql = 'SELECT name, max(time) FROM wiki '
17    if author:
18        sql += 'WHERE author LIKE \'%s%%\' ' % author
19    sql += 'GROUP BY name ORDER BY max(time) DESC'
20    if limit:
21        sql += ' LIMIT %d' % limit
22    cursor.execute(sql)
23
24    buf = StringIO()
25    #debug
26    #buf.write('%s<br>' % sql);
27    if author == None:
28        author = 'all users'
29    buf.write('<h2>Recent Changes for %s</h2>' % author)
30    prevtime = None
31    while 1:
32        row = cursor.fetchone()
33        if row == None:
34            break
35        t = time.strftime('%x', time.localtime(int(row[1])))
36        if not t == prevtime:
37            if prevtime:
38                buf.write('</ul>')
39            buf.write('<h3>%s</h3><ul>' % t)
40            prevtime = t
41        buf.write('<li><a href="%s">%s</a></li>\n' % (env.href.wiki(row[0]),
42                                                      row[0]))
43    if prevtime:
44        buf.write('</ul>')
45
46    return buf.getvalue()