| | 79 | |
|---|
| | 80 | class TagsWikiFilter(Component): |
|---|
| | 81 | |
|---|
| | 82 | implements(IStreamFilter, IRequestFilter) |
|---|
| | 83 | |
|---|
| | 84 | # IStreamFilter methods |
|---|
| | 85 | def match_stream(self, req, stream, method): |
|---|
| | 86 | return req.path_info.startswith('/wiki') and \ |
|---|
| | 87 | req.args.get('action') == 'edit' and \ |
|---|
| | 88 | method == 'xhtml' |
|---|
| | 89 | |
|---|
| | 90 | def process_stream(self, req, stream, method): |
|---|
| | 91 | page_name = req.path_info[6:] or 'WikiStart' |
|---|
| | 92 | stage = 1 |
|---|
| | 93 | elm = tag.div([tag.label('Tag under: (', |
|---|
| | 94 | tag.a('view all tags', href=req.href.tags()), |
|---|
| | 95 | ')', |
|---|
| | 96 | for_='tags'), |
|---|
| | 97 | tag.br(), |
|---|
| | 98 | tag.input(title='Comma separated list of tags', |
|---|
| | 99 | type='text', |
|---|
| | 100 | id='tags', |
|---|
| | 101 | size='30', |
|---|
| | 102 | name='tags', |
|---|
| | 103 | value=', '.join(TagEngine(self.env).tagspace.wiki.get_tags([page_name])) |
|---|
| | 104 | ), |
|---|
| | 105 | ], class_='field') |
|---|
| | 106 | |
|---|
| | 107 | for kind, data, pos in stream: |
|---|
| | 108 | yield kind, data, pos |
|---|
| | 109 | if stage == 1 and \ |
|---|
| | 110 | kind is START and \ |
|---|
| | 111 | data[0].localname == 'input' and \ |
|---|
| | 112 | data[1].get('id') == 'comment': |
|---|
| | 113 | stage = 2 |
|---|
| | 114 | elif stage == 2 and \ |
|---|
| | 115 | kind is END and \ |
|---|
| | 116 | data.localname == 'div': |
|---|
| | 117 | for e in elm.generate(): |
|---|
| | 118 | yield e |
|---|
| | 119 | stage = None |
|---|
| | 120 | |
|---|
| | 121 | # IRequestFilter methods |
|---|
| | 122 | def pre_process_request(self, req, handler): |
|---|
| | 123 | |
|---|