Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

#2429: prevent interpreting tagging comment as wiki in wiki history view

  • Loading branch information...
commit 33babfb150e8aef86dedca63a27c2d3471d10513 1 parent 199856c
@jun66j5 authored
Showing with 33 additions and 19 deletions.
  1. +9 −1 tractags/api.py
  2. +24 −18 tractags/wiki.py
View
10 tractags/api.py
@@ -31,7 +31,6 @@
'ngettext', 'tag_'))
dgettext = None
except ImportError:
- from genshi.builder import tag as tag_
from trac.util.translation import gettext
_ = gettext
N_ = lambda text: text
@@ -43,6 +42,8 @@ def ngettext(singular, plural, num, **kwargs):
string = num == 1 and singular or plural
kwargs.setdefault('num', num)
return safefmt(string, kwargs)
+ def tag_(string, **kwargs):
+ return _tag_kwargs(string, kwargs)
def safefmt(string, kwargs):
if kwargs:
try:
@@ -50,6 +51,13 @@ def safefmt(string, kwargs):
except KeyError:
pass
return string
+ _param_re = re.compile(r"%\((\w+)\)(?:s|[\d]*d|\d*.?\d*[fg])")
+ def _tag_kwargs(trans, kwargs):
+ from genshi.builder import tag
+ trans_elts = _param_re.split(trans)
+ for i in xrange(1, len(trans_elts), 2):
+ trans_elts[i] = kwargs.get(trans_elts[i], '???')
+ return tag(*trans_elts)
from tractags.model import resource_tags, tag_frequency, tag_resource
from tractags.model import tagged_resources
View
42 tractags/wiki.py
@@ -9,7 +9,7 @@
import re
-from genshi.builder import Markup, tag
+from genshi.builder import Fragment, Markup, tag
from genshi.filters.transform import Transformer
from trac.config import BoolOption
@@ -21,10 +21,12 @@
from trac.web.chrome import add_stylesheet
from trac.wiki.api import IWikiChangeListener, IWikiPageManipulator
from trac.wiki.api import IWikiSyntaxProvider
+from trac.wiki.formatter import format_to_oneliner
from trac.wiki.model import WikiPage
from trac.wiki.web_ui import WikiModule
-from tractags.api import Counter, DefaultTagProvider, TagSystem, _, ngettext
+from tractags.api import Counter, DefaultTagProvider, TagSystem, _, ngettext, \
+ tag_
from tractags.macros import TagTemplateProvider
from tractags.model import delete_tags, tag_changes
from tractags.query import Query
@@ -118,22 +120,20 @@ def post_process_request(self, req, template, data, content_type):
new_tags = split_into_tags(tags_history[0][3] or '')
added = new_tags - old_tags
removed = old_tags - new_tags
- # TRANSLATOR: Watch out, keep valid WikiFormatting.
- added_str = added and \
- ngettext("''%(tags)s'' added",
- "''%(tags)s'' added", len(added),
- tags=', '.join(added)) or ''
+ comment = tag(tag.strong(_("Tags")), ' ')
+ if added:
+ comment.append(tag_(ngettext("%(tags)s added",
+ "%(tags)s added",
+ len(added)),
+ tags=tag.em(', '.join(added))))
# TRANSLATOR: How to delimit added and removed tags.
- delim=added and removed and _("; ") or ''
- removed_str = removed and \
- ngettext("''%(tags)s'' removed",
- "''%(tags)s'' removed",
- len(removed),
- tags=', '.join(removed)) or ''
- # TRANSLATOR: Tags change record composition.
- comment = _(
- "'''tags''' %(added)s%(delim)s%(removed)s",
- added=added_str, delim=delim, removed=removed_str)
+ if added and removed:
+ comment.append(_("; "))
+ if removed:
+ comment.append(tag_(ngettext("%(tags)s removed",
+ "%(tags)s removed",
+ len(removed)),
+ tags=tag.em(', '.join(removed))))
history.append({
'version': '*',
'url': req.href(resource.realm, resource.id,
@@ -151,7 +151,8 @@ def post_process_request(self, req, template, data, content_type):
'comment': page_history[i]['comment'],
'ipnr': page_history[i]['ipnr']
})
- data.update(dict(history=history))
+ data.update(dict(history=history,
+ wiki_to_oneliner=self._wiki_to_oneliner))
return (template, data, content_type)
# ITemplateStreamFilter methods
@@ -270,6 +271,11 @@ def _wiki_history(self, req, stream):
xpath = '//a[contains(@href,"%2A")]'
return stream | Transformer(xpath).remove()
+ def _wiki_to_oneliner(self, context, wiki, shorten=None):
+ if isinstance(wiki, Fragment):
+ return wiki
+ return format_to_oneliner(self.env, context, wiki, shorten=shorten)
+
class TagWikiSyntaxProvider(Component):
"""Provide tag:<expr> links."""

2 comments on commit 33babfb

@hasienda

This seems to contain the wanted fix for unwanted line shortening of change displays, very good, thanks.

But watch for 79 chars/line limit in tractags/wiki.py's changed import statement, please.

@jun66j5
Owner

The 28th line have just 79 characters. However other lines exceeded the limitation, verified with pep8 utility. fixed in 51a496c.

Please sign in to comment.
Something went wrong with that request. Please try again.