diff options
-rw-r--r-- | setup.py | 2 | ||||
-rw-r--r-- | wikinfo/__init__.py | 2 | ||||
-rw-r--r-- | wikinfo/wikinfo.py | 69 |
3 files changed, 37 insertions, 36 deletions
@@ -5,7 +5,7 @@ from setuptools import setup setup( name = 'Wikinfo', - version = '0.1', + version = '2.1', packages = ['wikinfo'], package_data = { }, diff --git a/wikinfo/__init__.py b/wikinfo/__init__.py index ad24a8f..e69de29 100644 --- a/wikinfo/__init__.py +++ b/wikinfo/__init__.py @@ -1,2 +0,0 @@ -# Wikinfo plugin v2.0 -from wikinfo import * diff --git a/wikinfo/wikinfo.py b/wikinfo/wikinfo.py index d1efb41..7e9dcc7 100644 --- a/wikinfo/wikinfo.py +++ b/wikinfo/wikinfo.py @@ -1,4 +1,4 @@ -# -*- coding: iso8859-1 -*-
+# -*- coding: iso-8859-1 -*-
#
# Copyright (C) 2005 Jani Tiainen
#
@@ -17,6 +17,8 @@ # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# Author: Jani Tiainen <redetin@luukku.com>
+#
+# Updated for Trac 0.11 by Johan Risberg <gannis@users.sourceforge.net>
from __future__ import generators
import imp
@@ -37,9 +39,9 @@ from trac.wiki.api import IWikiMacroProvider, WikiSystem class WikinfoMacro(Component):
"""
Output different information by keyword.
-
+
Currently supported infos:
-
+
author - Author of first version
version - Latest version of page
changed_by - Page last changed by
@@ -47,81 +49,82 @@ class WikinfoMacro(Component): changed_ts - Page last changed timestamp
"""
implements(IWikiMacroProvider)
-
+
# IWikiMacroProvider methods
def get_macros(self):
yield 'Wikinfo'
-
+
def get_macro_description(self, name):
return inspect.getdoc(WikinfoMacro)
-
- def render_macro(self, req, name, content):
+
+ def expand_macro(self, formatter, name, content):
if content:
keywords = [arg.strip() for arg in content.split(',')]
-
+
buf = StringIO()
-
+
for nfo in keywords:
- try:
- getattr(self, '_do_%s' % nfo)(req, name, content, buf)
+ try:
+ getattr(self, '_do_%s' % nfo)(formatter.resource.id, name, content, buf)
except AttributeError:
buf.write('INVALID: %s' % nfo)
-
+
return buf.getvalue()
# Private methods
- def _do_author(self, req, name, content, buf):
+ def _do_author(self, page, name, content, buf):
db = self.env.get_db_cnx()
cursor = db.cursor()
- sql = "SELECT author, version FROM wiki where name = '%s' order by version limit 1" % req.hdf['wiki.page_name']
+ sql = "SELECT author, version FROM wiki where name = '%s' order by version limit 1" % page
cursor.execute(sql)
-
+
row = cursor.fetchone()
-
+
buf.write(row[0])
-
- def _do_version(self, req, name, content, buf):
+
+
+ def _do_version(self, page, name, content, buf):
db = self.env.get_db_cnx()
cursor = db.cursor()
- sql = "SELECT max(version) FROM wiki where name = '%s'" % req.hdf['wiki.page_name']
+ sql = "SELECT max(version) FROM wiki where name = '%s'" % page
cursor.execute(sql)
-
+
row = cursor.fetchone()
-
+
buf.write(str(row[0]))
- def _do_changed_by(self, req, name, content, buf):
+ def _do_changed_by(self, page, name, content, buf):
db = self.env.get_db_cnx()
cursor = db.cursor()
- sql = "SELECT author, version FROM wiki where name = '%s' order by version desc limit 1" % req.hdf['wiki.page_name']
+ sql = "SELECT author, version FROM wiki where name = '%s' order by version desc limit 1" % page
cursor.execute(sql)
-
+
row = cursor.fetchone()
-
+
buf.write(row[0])
- def _do_changed_ts(self, req, name, content, buf):
+ def _do_changed_ts(self, page, name, content, buf):
db = self.env.get_db_cnx()
cursor = db.cursor()
- sql = "SELECT time, version FROM wiki where name = '%s' order by version desc limit 1" % req.hdf['wiki.page_name']
+ sql = "SELECT time, version FROM wiki where name = '%s' order by version desc limit 1" % page
cursor.execute(sql)
-
+
row = cursor.fetchone()
-
+
buf.write(time.strftime('%x', time.localtime(row[0])))
- def _do_comment(self, req, name, content, buf):
+ def _do_comment(self, page, name, content, buf):
db = self.env.get_db_cnx()
cursor = db.cursor()
- sql = "SELECT comment, version FROM wiki where name = '%s' order by version desc limit 1" % req.hdf['wiki.page_name']
+ sql = "SELECT comment, version FROM wiki where name = '%s' order by version desc limit 1" % page
cursor.execute(sql)
-
+
row = cursor.fetchone()
-
+
buf.write(row[0])
|