| 1 | """ |
|---|
| 2 | Creates a link to search in trac for the given words, by building a link to Trac's inbuilt |
|---|
| 3 | search facility. |
|---|
| 4 | |
|---|
| 5 | Examples: |
|---|
| 6 | [[TracSearch(keyword)]] |
|---|
| 7 | [[TracSearch(keyword,wiki)]] |
|---|
| 8 | [[TracSearch(keyword1 keyword2,changeset,ticket)]] |
|---|
| 9 | """ |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | from StringIO import StringIO |
|---|
| 13 | |
|---|
| 14 | def execute(hdf, args, env): |
|---|
| 15 | default_include = ['wiki', 'changeset', 'ticket'] |
|---|
| 16 | buf = StringIO() |
|---|
| 17 | |
|---|
| 18 | if args: |
|---|
| 19 | args = args.split(',') |
|---|
| 20 | term = args[0] |
|---|
| 21 | if len(args) > 1: |
|---|
| 22 | include = args[1:] |
|---|
| 23 | else: |
|---|
| 24 | include = default_include |
|---|
| 25 | |
|---|
| 26 | objects = [] |
|---|
| 27 | if 'wiki' in include: |
|---|
| 28 | objects.append('Wiki pages') |
|---|
| 29 | if 'changeset' in include: |
|---|
| 30 | objects.append('Changeset messages') |
|---|
| 31 | if 'ticket' in include: |
|---|
| 32 | objects.append('Tickets') |
|---|
| 33 | |
|---|
| 34 | object_list = ", ".join(objects) |
|---|
| 35 | |
|---|
| 36 | url = env.href.search(query=term, include=include) |
|---|
| 37 | |
|---|
| 38 | buf.write("<a href='%(url)s'>%(objects)s containing '%(term)s'</a>\n" % |
|---|
| 39 | dict(objects=object_list, term=term, url=url)) |
|---|
| 40 | else: |
|---|
| 41 | buf.write("<p style='font-weight:bold; color:red;'>[[Search()]] macro requires a search term</p>\n") |
|---|
| 42 | |
|---|
| 43 | return buf.getvalue() |
|---|