summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2011-02-17 19:28:19 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2011-02-17 19:28:19 +0100
commit0ddc28e3eb4d6c7f6aad82ccc86f6f46497e545d (patch)
treec07925af7a563cc449f71c6a16431f9d9246a5c7
parente25b262598b87cf8136615eb3ddc0a314c46a541 (diff)
downloadwikinfo-0ddc28e3eb4d6c7f6aad82ccc86f6f46497e545d.tar.gz
wikinfo-0ddc28e3eb4d6c7f6aad82ccc86f6f46497e545d.tar.xz
wikinfo-0ddc28e3eb4d6c7f6aad82ccc86f6f46497e545d.zip
port to trac-0.11
-rw-r--r--setup.py2
-rw-r--r--wikinfo/__init__.py2
-rw-r--r--wikinfo/wikinfo.py69
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 <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])