diff --git a/r2/r2/controllers/api.py b/r2/r2/controllers/api.py index 23b158fd6..58f1aa9c2 100644 --- a/r2/r2/controllers/api.py +++ b/r2/r2/controllers/api.py @@ -82,6 +82,7 @@ from r2.lib.menus import CommentSortMenu from r2.lib.captcha import get_iden from r2.lib.strings import strings from r2.lib.filters import _force_unicode, websafe_json, websafe, spaceCompress +from r2.lib.template_helpers import format_html from r2.lib.db import queries from r2.lib.db.queries import changed from r2.lib import media @@ -1858,9 +1859,9 @@ class ApiController(RedditController): else: emails, users = emails jquery.things(link._fullname).set_text(".share", _("shared")) - shareform.html("
" - "

%s

" % - websafe(_("your link has been shared."))) + shareform.html(format_html("
" + "

%s

", + _("your link has been shared."))) if getattr(link, "promoted", None) and link.disable_comments: message = message + "\n\n" if message else "" @@ -3679,9 +3680,10 @@ class ApiController(RedditController): # TODO: move this to a template if flair_template: - flair = '%s' % ( - ' '.join('linkflair-' + c for c in css_class.split()), - websafe(text)) + classes = ' '.join('linkflair-' + c for c in css_class.split()) + flair = format_html('%s', + classes, text) + if site.link_flair_position == 'left': jquery(title_path).before(flair) elif site.link_flair_position == 'right': diff --git a/r2/r2/controllers/promotecontroller.py b/r2/r2/controllers/promotecontroller.py index 76c31ab11..87c241e2f 100644 --- a/r2/r2/controllers/promotecontroller.py +++ b/r2/r2/controllers/promotecontroller.py @@ -39,6 +39,7 @@ from r2.lib.base import abort from r2.lib.db import queries from r2.lib.errors import errors from r2.lib.filters import websafe +from r2.lib.template_helpers import format_html from r2.lib.media import force_thumbnail, thumbnail_url, _scrape_media from r2.lib.memoize import memoize from r2.lib.menus import NamedButton, NavButton, NavMenu, QueryButton @@ -554,7 +555,7 @@ class PromoteApiController(ApiController): if promote.is_promo(link): text = PromotionLog.add(link, note) form.find(".notes").children(":last").after( - "

" + websafe(text) + "

") + format_html("

%s

", text)) @validatedForm( VSponsorAdmin(), diff --git a/r2/r2/models/link.py b/r2/r2/models/link.py index af9c460ba..849fd6265 100644 --- a/r2/r2/models/link.py +++ b/r2/r2/models/link.py @@ -368,7 +368,7 @@ class Link(Thing, Printable): from r2.lib.count import incr_counts from r2.lib import media from r2.lib.utils import timeago - from r2.lib.template_helpers import get_domain, _ws, unsafe + from r2.lib.template_helpers import get_domain, unsafe, format_html from r2.models.report import Report from r2.models.subreddit import FakeSubreddit from r2.lib.wrapped import CachedVariable @@ -655,16 +655,16 @@ class Link(Thing, Printable): taglinetext = '' if item.different_sr: - author_text = (" " + _ws("by %(author)s to %(reddit)s") + - "") + author_text = format_html(" %s", + _("by %(author)s to %(reddit)s")) else: - author_text = " " + _ws("by %(author)s") + "" + author_text = format_html(" %s", + _("by %(author)s")) if item.editted: if item.score_fmt in (Score.points, Score.safepoints): - taglinetext = ("" + - _ws("%(score)s submitted %(when)s " - "%(lastedited)s") + - "") + taglinetext = format_html("%s", + _("%(score)s submitted %(when)s " + "%(lastedited)s")) taglinetext = unsafe(taglinetext + author_text) elif item.different_sr: taglinetext = _("submitted %(when)s %(lastedited)s " @@ -674,9 +674,8 @@ class Link(Thing, Printable): "by %(author)s") else: if item.score_fmt in (Score.points, Score.safepoints): - taglinetext = ("" + - _ws("%(score)s submitted %(when)s") + - "") + taglinetext = format_html("%s", + _("%(score)s submitted %(when)s")) taglinetext = unsafe(taglinetext + author_text) elif item.different_sr: taglinetext = _("submitted %(when)s by %(author)s " diff --git a/r2/r2/templates/base.htmllite b/r2/r2/templates/base.htmllite index 43a3982a1..4c391c165 100644 --- a/r2/r2/templates/base.htmllite +++ b/r2/r2/templates/base.htmllite @@ -24,7 +24,7 @@ <%! from pylons.i18n import _ - from r2.lib.template_helpers import get_domain, style_line, _ws + from r2.lib.template_helpers import get_domain, style_line, format_html, _ws from r2.models.subreddit import FakeSubreddit, DefaultSR %> @@ -49,16 +49,16 @@ ${optionalstyle("border:none")} /> <% - style = capture(optionalstyle, "text-decoration:none;color:#336699") + style = unsafe(capture(optionalstyle, "text-decoration:none;color:#336699")) name = c.site.name if not isinstance(c.site, FakeSubreddit): name += ".%s" % g.domain if c.link_target: - link = ('%s' % - (style, get_domain(), c.link_target, name)) + link = format_html('%s', + style, get_domain(), c.link_target, name) else: - link = ('%s' % - (style, get_domain(), name)) + link = format_html('%s', + style, get_domain(), name) %> ${self.titlebar(link)} diff --git a/r2/r2/templates/comment.compact b/r2/r2/templates/comment.compact index 8eda0c90e..c130a32e3 100644 --- a/r2/r2/templates/comment.compact +++ b/r2/r2/templates/comment.compact @@ -22,7 +22,7 @@ <%! from r2.lib.pages import WrappedUser - from r2.lib.template_helpers import add_sr, _ws + from r2.lib.template_helpers import add_sr, _wsf %> <%namespace file="printable.compact" import="delete_report_buttons"/> <%namespace file="printable.html" import="arrow, score, thing_css_rowclass"/> @@ -67,7 +67,7 @@ %endif ## thing.timesince is a cache stub - ${unsafe(_ws("%(timeago)s") % dict(timeago=thing.timesince))} + ${_wsf("%(timeago)s", timeago=thing.timesince)} % if thing.gilded_message: % if thing.gildings > 1: diff --git a/r2/r2/templates/exploreitemlisting.html b/r2/r2/templates/exploreitemlisting.html index ff66630b5..980eb1b51 100644 --- a/r2/r2/templates/exploreitemlisting.html +++ b/r2/r2/templates/exploreitemlisting.html @@ -21,7 +21,7 @@ ############################################################################### <%! - from r2.lib.template_helpers import _ws + from r2.lib.template_helpers import format_html %> <%namespace file="utils.html" import="plain_link" /> <% @@ -63,7 +63,7 @@ %endfor %else: @@ -74,7 +74,7 @@ %endif diff --git a/r2/r2/templates/frametoolbar.html b/r2/r2/templates/frametoolbar.html index 59c124b3b..90efef708 100644 --- a/r2/r2/templates/frametoolbar.html +++ b/r2/r2/templates/frametoolbar.html @@ -21,7 +21,7 @@ ############################################################################### <%! - from r2.lib.template_helpers import static, get_domain, add_sr, _ws + from r2.lib.template_helpers import static, get_domain, add_sr, format_html from r2.lib.strings import Score %> @@ -188,21 +188,21 @@ %if thing.saved: ${state_button("unsave", _("unsave"), - "return change_state(this, 'unsave');", "%s" % _ws("unsaved"), + "return change_state(this, 'unsave');", format_html("%s", _("unsaved")), a_class="clickable")} %else: ${state_button("save", _("save"), - "return change_state(this, 'save');", "%s" % _ws("saved"), + "return change_state(this, 'save');", format_html("%s", _("saved")), a_class="clickable")} %endif %if thing.hidden: ${state_button("unhide", _("unhide"), - "return change_state(this, 'unhide');", "%s" % _ws("unhidden"), + "return change_state(this, 'unhide');", format_html("%s", _("unhidden")), a_class="clickable")} %else: ${state_button("hide", _("hide"), - "return change_state(this, 'hide');", "%s" % _ws("hide"), + "return change_state(this, 'hide');", format_html("%s", _("hide")), a_class="clickable")} %endif diff --git a/r2/r2/templates/listing.html b/r2/r2/templates/listing.html index 87b37ad6b..d731241f4 100644 --- a/r2/r2/templates/listing.html +++ b/r2/r2/templates/listing.html @@ -21,7 +21,7 @@ ############################################################################### <%! - from r2.lib.template_helpers import _ws + from r2.lib.template_helpers import format_html from r2.models import Sub %> <%namespace file="utils.html" import="plain_link" /> @@ -39,13 +39,13 @@ -

${unsafe(_ws('%(count)s subreddits in this multi:') % dict(count='%d ' % len(thing.srs)))}

+ <% sr_count = format_html('%s ', len(thing.srs)) %> +

${_wsf('%(count)s subreddits in this multi:', count=sr_count)}