Skip to content

Commit

Permalink
* Add services and scripts to public repos for ease of reddit instal…
Browse files Browse the repository at this point in the history
…lation

 * bring discount up to date
 * fix consistency errors in the self-serve traffic page
  • Loading branch information
jedberg authored and KeyserSosa committed May 18, 2010
1 parent e683889 commit 253c473
Show file tree
Hide file tree
Showing 171 changed files with 1,763 additions and 1,602 deletions.
11 changes: 7 additions & 4 deletions r2/Makefile
Expand Up @@ -50,16 +50,19 @@ RTLCSS = $(CSSTARGETS:.css=-rtl.css) $(MAINCSS:.css=-rtl.css)

MD5S = $(JSTARGETS:=.md5) $(CSSTARGETS:=.md5) $(MAINCSS:=.md5) $(RTLCSS:=.md5)

ifdef PRIVATEREPOS
INIUPDATE = $(wildcard *.update)
INIS = $(INIUPDATE:.update=.ini)

%.ini: %.update
ln -sf `pwd`/$< $(PRIVATEREPOS)/..
make -C $(PRIVATEREPOS)/.. $@
ln -sf $(PRIVATEREPOS)/../$@ .
ifneq (,$(PRIVATEREPOS))
ln -sf `pwd`/$< $(PRIVATEREPOS)/..
make -C $(PRIVATEREPOS)/.. $@
ln -sf $(PRIVATEREPOS)/../$@ .
else
./updateini.py example.ini $< > $@ || rm $@
endif


all: $(JSTARGETS) $(CSSTARGETS) $(MD5S) $(RTLCSS) $(INIS)

.PHONY: js css md5 rtl clean all
Expand Down
4 changes: 4 additions & 0 deletions r2/example.ini
Expand Up @@ -21,6 +21,9 @@ exception_logging = false
log_start = true
# enable/disable logging for amqp/rabbitmq
amqp_logging = false
# emergency measures: makes the site read only
read_only_mode = false

# -- SECRETS! <-- update these first! --
# global secret
SECRET = abcdefghijklmnopqrstuvwxyz0123456789
Expand Down Expand Up @@ -191,6 +194,7 @@ tracking_secret = abcdefghijklmnopqrstuvwxyz0123456789
# (secure) payment domain
payment_domain = http://pay.localhost/
ad_domain = http://localhost
sponsors =
# authorize.net credentials
authorizenetname =
authorizenetkey =
Expand Down
54 changes: 32 additions & 22 deletions r2/r2/controllers/api.py
Expand Up @@ -192,7 +192,6 @@ def POST_compose(self, form, jquery, to, subject, body, ip):
ip = ValidIP(),
sr = VSubmitSR('sr'),
url = VUrl(['url', 'sr']),
banmsg = VOkayDomain('url'),
title = VTitle('title'),
save = VBoolean('save'),
selftext = VMarkdown('text'),
Expand Down Expand Up @@ -229,17 +228,23 @@ def POST_submit(self, form, jquery, url, selftext, kind, title,
if not should_ratelimit:
c.errors.remove((errors.RATELIMIT, 'ratelimit'))

banmsg = None

if kind == 'link':
check_domain = True

# check for no url, or clear that error field on return
if form.has_errors("url", errors.NO_URL, errors.BAD_URL):
pass
elif form.has_errors("url", errors.ALREADY_SUB):
check_domain = False
form.redirect(url[0].already_submitted_link)
# check for title, otherwise look it up and return it
elif form.has_errors("title", errors.NO_TEXT):
pass

banmsg = is_banned_domain(url)
if check_domain:
banmsg = is_banned_domain(url)

# Uncomment if we want to let spammers know we're on to them
# if banmsg:
Expand All @@ -248,7 +253,6 @@ def POST_submit(self, form, jquery, url, selftext, kind, title,

else:
form.has_errors('text', errors.TOO_LONG)
banmsg = None

if form.has_errors("title", errors.TOO_LONG, errors.NO_TEXT):
pass
Expand All @@ -261,21 +265,24 @@ def POST_submit(self, form, jquery, url, selftext, kind, title,

if should_ratelimit:
filled_quota = c.user.quota_full('link')
if filled_quota is not None and not c.user._spam:
log_text ("over-quota",
"%s just went over their per-%s quota" %
(c.user.name, filled_quota), "info")
if filled_quota is not None:
if c.user._spam:
msg = strings.generic_quota_msg
else:
log_text ("over-quota",
"%s just went over their per-%s quota" %
(c.user.name, filled_quota), "info")

compose_link = ("/message/compose?to=%23" + sr.name +
"&subject=Exemption+request")
compose_link = ("/message/compose?to=%23" + sr.name +
"&subject=Exemption+request")

verify_link = "/verify?reason=submit"
verify_link = "/verify?reason=submit"

if c.user.email_verified:
msg = strings.verified_quota_msg % dict(link=compose_link)
else:
msg = strings.unverified_quota_msg % dict(link1=verify_link,
link2=compose_link)
if c.user.email_verified:
msg = strings.verified_quota_msg % dict(link=compose_link)
else:
msg = strings.unverified_quota_msg % dict(link1=verify_link,
link2=compose_link)

md = safemarkdown(msg)
form.set_html(".status", md)
Expand Down Expand Up @@ -481,9 +488,6 @@ def POST_unfriend(self, nuser, iuser, container, type):
if type in ("moderator", "contributor"):
Subreddit.special_reddits(victim, type, _update=True)

if type in ("moderator", "contributor"):
Subreddit.special_reddits(iuser or nuser, type, _update=True)



@validatedForm(VUser(),
Expand Down Expand Up @@ -909,6 +913,9 @@ def POST_vote(self, dir, thing, ip, vote_type):
g.log.debug("POST_vote: ignoring old vote on %s" % thing._fullname)
store = False

if getattr(c.user, "suspicious", False):
g.log.info("%s cast a %d vote on %s", c.user.name, dir, thing._fullname)

dir = (True if dir > 0
else False if dir < 0
else None)
Expand Down Expand Up @@ -1132,7 +1139,6 @@ def POST_upload_sr_img(self, file, header, sponsor, name, form_id):
over_18 = VBoolean('over_18'),
allow_top = VBoolean('allow_top'),
show_media = VBoolean('show_media'),
use_whitelist = VBoolean('use_whitelist'),
type = VOneOf('type', ('public', 'private', 'restricted')),
ip = ValidIP(),
sponsor_text =VLength('sponsorship-text', max_length = 500),
Expand Down Expand Up @@ -1520,15 +1526,20 @@ def POST_subscribe(self, action, sr):
# Anyone can leave.
if action != 'sub' or sr.can_comment(c.user):
self._subscribe(sr, action == 'sub')

def _subscribe(self, sr, sub):
Subreddit.subscribe_defaults(c.user)

sub_key = "subscription-%s-%s" % (c.user.name, sr.name)

if sub:
if sr.add_subscriber(c.user):
if not g.cache.add(sub_key, True):
g.log.warning("Double-subscribe for %s?" % sub_key)
elif sr.add_subscriber(c.user):
sr._incr('_ups', 1)
else:
if sr.remove_subscriber(c.user):
g.cache.delete(sub_key)
sr._incr('_ups', -1)
changed(sr)

Expand All @@ -1538,7 +1549,6 @@ def _subscribe(self, sr, sub):
def POST_disable_lang(self, tr):
if tr:
tr._is_enabled = False


@noresponse(VAdmin(),
tr = VTranslation("id"))
Expand Down
5 changes: 4 additions & 1 deletion r2/r2/controllers/front.py
Expand Up @@ -523,7 +523,10 @@ def _search(self, query_obj, num, after, reverse, count=0):
try:
res = listing.listing()
except SolrError, e:
errmsg = "SolrError: %r %r" % (e, query_obj)
try:
errmsg = "SolrError: %r %r" % (e, query_obj)
except UnicodeEncodeError:
errmsg = "SolrError involving unicode"

if (str(e) == 'None'):
# Production error logs only get non-None errors
Expand Down
22 changes: 18 additions & 4 deletions r2/r2/controllers/listingcontroller.py
Expand Up @@ -238,6 +238,13 @@ def spotlight(self):
spotlight_links, pos = promote.insert_promoted(spotlight_links, pos)
trial = populate_spotlight()

# Need to do this again, because if there was a duplicate removed,
# pos might be pointing outside the list.
if not spotlight_links:
pos = 0
elif pos != 0:
pos = pos % len(spotlight_links)

if trial:
spotlight_links.insert(pos, trial._fullname)

Expand Down Expand Up @@ -268,9 +275,16 @@ def wrap(item):
num = organic.organic_length,
skip = True, keep_fn = keep_fn)

try:
vislink = spotlight_links[pos]
except IndexError:
g.log.error("spotlight_links = %r" % spotlight_links)
g.log.error("pos = %d" % pos)
raise

s = SpotlightListing(b,
spotlight_links = spotlight_links,
visible_link = spotlight_links[pos],
visible_link = vislink,
max_num = self.listing_obj.max_num,
max_score = self.listing_obj.max_score).listing()

Expand Down Expand Up @@ -367,10 +381,10 @@ def keep(item):
return keep

def query(self):
res = None
if self.sort == 'rising':
return get_rising(c.site)
else:
return c.site.get_links('new', 'all')
res = get_rising(c.site)
return res or c.site.get_links('new', 'all')

@validate(sort = VMenu('controller', NewMenu))
def GET_listing(self, sort, **env):
Expand Down
2 changes: 1 addition & 1 deletion r2/r2/controllers/post.py
Expand Up @@ -36,7 +36,7 @@ def api_wrapper(self, kw):
def set_options(self, all_langs, pref_lang, **kw):
if c.errors.errors:
print "fucker"
raise "broken"
return

if all_langs == 'all':
langs = 'all'
Expand Down
5 changes: 5 additions & 0 deletions r2/r2/controllers/validator/validator.py
Expand Up @@ -782,6 +782,9 @@ def run(self, url, sr = None):
if not url:
return self.error(errors.NO_URL)
url = utils.sanitize_url(url)
if not url:
return self.error(errors.BAD_URL)

if url == 'self':
if self.allow_self:
return url
Expand Down Expand Up @@ -996,6 +999,8 @@ def ratelimit(self, rate_user = False, rate_ip = False, prefix = "rate_",
to_set = {}
if seconds is None:
seconds = g.RATELIMIT*60
if not seconds:
return
expire_time = datetime.now(g.tz) + timedelta(seconds = seconds)
if rate_user and c.user_is_loggedin:
to_set['user' + str(c.user._id36)] = expire_time
Expand Down

0 comments on commit 253c473

Please sign in to comment.