mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-29 00:38:11 -05:00
Domain area: add new user pref to show extra info
If enabled, shows additional info in the domain text when it's available. Initially, this includes the source subreddit for internal reddit links, and anywhere that the media_author_url or media_author_name info is available through embed.ly (such as YouTube channels, Twitter authors, etc.)
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -92,7 +92,7 @@
|
||||
%if thing.is_self:
|
||||
(self)
|
||||
%else:
|
||||
(<a href="${thing.domain_path}">${thing.domain}</a>)
|
||||
(<a href="${thing.domain_path}.compact">${thing.domain_str}</a>)
|
||||
%endif
|
||||
</span>
|
||||
%if thing.nsfw:
|
||||
|
||||
@@ -199,7 +199,7 @@ ${parent.thing_data_attributes(what)} data-ups="${what.upvotes}" data-downs="${w
|
||||
|
||||
<%def name="domain()">
|
||||
<span class="domain">
|
||||
(${plain_link(thing.domain, thing.domain_path, _sr_path = False)})
|
||||
(<a href="${thing.domain_path}">${thing.domain_str}</a>)
|
||||
%if c.user_is_admin:
|
||||
 
|
||||
<a class="adminbox" href="/admin/domain/${thing.domain}">d</a>
|
||||
|
||||
@@ -146,6 +146,12 @@
|
||||
|
||||
<p>${checkbox(_("show me links I've recently viewed"), "clickgadget")}</p>
|
||||
<p>${checkbox(_("compress the link display"), "compress")}</p>
|
||||
<p>${checkbox(_("show additional details in the domain text when available"), "domain_details")}
|
||||
 
|
||||
<span class="little gray">
|
||||
${_("(such as the source subreddit or the content author's url/name)")}
|
||||
</span>
|
||||
</p>
|
||||
<p>${checkbox(_("don't show links after I've liked them"), "hide_ups")}
|
||||
 
|
||||
<span class="little gray">${_("(except my own)")}</span>
|
||||
|
||||
Reference in New Issue
Block a user