" %
- 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
- ${unsafe(_ws("%(app)s requests to connect with your reddit account.")
- % dict(app=app_link(thing.client)))}
+ ${_wsf("%(app)s requests to connect with your reddit account.",
+ app=unsafe(app_link(thing.client)))}
- ${unsafe(
- _ws("%(app)s will not be able to access your reddit password.")
- % dict(app=app_name))}
+ ${_wsf("%(app)s will not be able to access your reddit password.", app=app_name)}
- ${unsafe(_ws("links %(submitted_by)s the user %(who)s") % dict(submitted_by = where2(), who = text_input("who")))}
+ ${_wsf("links %(submitted_by)s the user %(who)s", submitted_by=unsafe(where2()), who=unsafe(text_input("who")))}
- ${unsafe(_ws("links from the domain %(domain)s") % dict(domain = text_input("domain")))}
+ ${_wsf("links from the domain %(domain)s", domain=unsafe(text_input("domain")))}
@@ -178,10 +178,10 @@ function update() {
%def>
- ${unsafe(_ws("sort links by %(what)s") % dict(what = what()))}
+ ${_wsf("sort links by %(what)s", what=unsafe(what()))}
- ${unsafe(_ws("date range includes %(when)s") % dict(when = when()))}
+ ${_wsf("date range includes %(when)s", when=unsafe(when()))}