| 1 | from StringIO import StringIO |
|---|
| 2 | from trac.util.html import Markup |
|---|
| 3 | from trac.wiki.formatter import Formatter |
|---|
| 4 | from trac.wiki.macros import WikiMacroBase |
|---|
| 5 | |
|---|
| 6 | class WikiIncludeMacro(WikiMacroBase): |
|---|
| 7 | def expand_macro(self, formatter, name, args): |
|---|
| 8 | |
|---|
| 9 | args = args.split('|') |
|---|
| 10 | |
|---|
| 11 | if len(args) < 1 : |
|---|
| 12 | return ''; |
|---|
| 13 | |
|---|
| 14 | target = args[0] |
|---|
| 15 | db = self.env.get_db_cnx() |
|---|
| 16 | |
|---|
| 17 | sql = "SELECT text from wiki where name = '%s' order by version desc limit 1" % target |
|---|
| 18 | cs = db.cursor() |
|---|
| 19 | cs.execute(sql) |
|---|
| 20 | |
|---|
| 21 | row = cs.fetchone() |
|---|
| 22 | |
|---|
| 23 | if row == None: |
|---|
| 24 | return '' |
|---|
| 25 | |
|---|
| 26 | text = row[0] |
|---|
| 27 | |
|---|
| 28 | if len(args) > 1 : |
|---|
| 29 | i = 0 |
|---|
| 30 | for arg in args: |
|---|
| 31 | if i > 0 : |
|---|
| 32 | text = text.replace('{{%d}}' % (i-1), unicode(args[i])) |
|---|
| 33 | i += 1 |
|---|
| 34 | |
|---|
| 35 | out = StringIO() |
|---|
| 36 | Formatter(formatter.env, formatter.context).format(text, out) |
|---|
| 37 | return Markup(out.getvalue()) |
|---|