Edgewall Software

MacroBazaar: LastModifiedVersion.py

File LastModifiedVersion.py, 758 bytes (added by anonymous, 6 years ago)

Macro that prints the last modified version of the wiki page, inspired by the LastModified?.py wiki macro

Line 
1'''
2Trac wiki macro for printing the last modified version of a wiki page.
3'''
4
5import re
6
7def execute(hdf, txt, env):
8  # Title of the wiki page
9  page_name = hdf.getValue ('title', '')
10
11  if page_name:
12    # If page name is set, remove trailing bracket
13    page_name = re.sub (' \(.*$', '', page_name)
14
15  else:
16    # If page name is not set, use start page
17    page_name = 'WikiStart'
18
19  # Set cursor to point to current Trac database
20  db     = env.get_db_cnx ()
21  cursor = db.cursor ()
22
23  # Get latest version number of current wiki page
24  cursor.execute (
25    "SELECT version FROM wiki WHERE name == %s ORDER BY version DESC LIMIT 1",
26    page_name
27  )
28
29  # Print string representation of the latest version number
30  return str (cursor.fetchone () [0])