diff --git a/r2/r2/controllers/post.py b/r2/r2/controllers/post.py index 3e7fb5d4c..64a1d2933 100644 --- a/r2/r2/controllers/post.py +++ b/r2/r2/controllers/post.py @@ -83,6 +83,7 @@ class PostController(ApiController): pref_lang = VLang('lang'), pref_media = VOneOf('media', ('on', 'off', 'subreddit')), pref_compress = VBoolean('compress'), + pref_domain_details = VBoolean('domain_details'), pref_min_link_score = VInt('min_link_score', -100, 100), pref_min_comment_score = VInt('min_comment_score', -100, 100), pref_num_comments = VInt('num_comments', 1, g.max_comments, diff --git a/r2/r2/models/account.py b/r2/r2/models/account.py index e609691a9..a249fba3e 100644 --- a/r2/r2/models/account.py +++ b/r2/r2/models/account.py @@ -74,6 +74,7 @@ class Account(Thing): pref_content_langs = (g.lang,), pref_over_18 = False, pref_compress = False, + pref_domain_details = False, pref_organic = True, pref_no_profanity = True, pref_label_nsfw = True, diff --git a/r2/r2/models/link.py b/r2/r2/models/link.py index 11dd59357..43c8a0b61 100755 --- a/r2/r2/models/link.py +++ b/r2/r2/models/link.py @@ -26,13 +26,14 @@ from r2.lib.db.operators import desc from r2.lib.utils import ( base_url, domain, + strip_www, timesince, title_to_url, tup, UrlParser, ) from account import Account, DeletedUser -from subreddit import Subreddit, DomainSR +from subreddit import DefaultSR, DomainSR, Subreddit from printable import Printable from r2.config import cache, extensions from r2.lib.memoize import memoize @@ -473,6 +474,38 @@ class Link(Thing, Printable): if g.shortdomain: item.shortlink = g.shortdomain + '/' + item._id36 + item.domain_str = None + if c.user.pref_domain_details: + urlparser = UrlParser(item.url) + if not item.is_self and urlparser.is_reddit_url(): + url_subreddit = urlparser.get_subreddit() + if (url_subreddit and + not isinstance(url_subreddit, DefaultSR)): + item.domain_str = ('{0}/r/{1}' + .format(item.domain, + url_subreddit.name)) + elif item.media_object: + try: + author_url = item.media_object['oembed']['author_url'] + if domain(author_url) == item.domain: + urlparser = UrlParser(author_url) + item.domain_str = strip_www(urlparser.hostname) + item.domain_str += urlparser.path + except KeyError: + pass + + if not item.domain_str: + try: + author = item.media_object['oembed']['author_name'] + author = _force_unicode(author) + item.domain_str = (_force_unicode('{0}: {1}') + .format(item.domain, author)) + except KeyError: + pass + + if not item.domain_str: + item.domain_str = item.domain + # do we hide the score? if user_is_admin: item.hide_score = False diff --git a/r2/r2/public/static/css/reddit.less b/r2/r2/public/static/css/reddit.less index 5a0f12919..aef63976d 100755 --- a/r2/r2/public/static/css/reddit.less +++ b/r2/r2/public/static/css/reddit.less @@ -730,9 +730,17 @@ ul.flat-vert {text-align: left;} margin-left: 3px; opacity: 1; } -.domain { color: #888; font-size:x-small; } -.domain a { color: #888 } -.domain a:hover { text-decoration: underline } +.domain { color: #888; font-size:x-small; white-space: nowrap; } +.domain a { + color: #888; + display: inline-block; + overflow: hidden; + white-space: nowrap; + text-overflow: ellipsis; + vertical-align: middle; + max-width: 19em; +} +.domain a:hover { text-decoration: underline; max-width: none; } .spam .domain, .spam .domain a { color: black; diff --git a/r2/r2/templates/link.compact b/r2/r2/templates/link.compact index 455f4f0a7..2d678417c 100644 --- a/r2/r2/templates/link.compact +++ b/r2/r2/templates/link.compact @@ -92,7 +92,7 @@ %if thing.is_self: (self) %else: - (${thing.domain}) + (${thing.domain_str}) %endif %if thing.nsfw: diff --git a/r2/r2/templates/link.html b/r2/r2/templates/link.html index 52d1ff0f4..be1c7bc81 100755 --- a/r2/r2/templates/link.html +++ b/r2/r2/templates/link.html @@ -199,7 +199,7 @@ ${parent.thing_data_attributes(what)} data-ups="${what.upvotes}" data-downs="${w <%def name="domain()"> - (${plain_link(thing.domain, thing.domain_path, _sr_path = False)}) + (${thing.domain_str}) %if c.user_is_admin: d diff --git a/r2/r2/templates/prefoptions.html b/r2/r2/templates/prefoptions.html index ee0c30f36..6618412e0 100644 --- a/r2/r2/templates/prefoptions.html +++ b/r2/r2/templates/prefoptions.html @@ -146,6 +146,12 @@

${checkbox(_("show me links I've recently viewed"), "clickgadget")}

${checkbox(_("compress the link display"), "compress")}

+

${checkbox(_("show additional details in the domain text when available"), "domain_details")} + + + ${_("(such as the source subreddit or the content author's url/name)")} + +

${checkbox(_("don't show links after I've liked them"), "hide_ups")} ${_("(except my own)")}