From 0ddc28e3eb4d6c7f6aad82ccc86f6f46497e545d Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Thu, 17 Feb 2011 19:28:19 +0100 Subject: port to trac-0.11 --- setup.py | 2 +- wikinfo/__init__.py | 2 -- wikinfo/wikinfo.py | 69 ++++++++++++++++++++++++++++------------------------- 3 files changed, 37 insertions(+), 36 deletions(-) diff --git a/setup.py b/setup.py index 923d1b5..79a18ca 100644 --- a/setup.py +++ b/setup.py @@ -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 +# +# Updated for Trac 0.11 by Johan Risberg 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]) -- cgit v1.2.3