Send sup-id headers on 304s, added nofollows to comment permalinks

This commit is contained in:
spez
2009-02-12 14:34:43 -08:00
parent 955e40d3d0
commit 2d86a76962
9 changed files with 33 additions and 58 deletions

View File

@@ -44,7 +44,6 @@ import sys, tempfile, urllib, re, os, sha
#from pylons.middleware import error_mapper
def error_mapper(code, message, environ, global_conf=None, **kw):
if environ.get('pylons.error_call'):
return None
else:
@@ -52,7 +51,7 @@ def error_mapper(code, message, environ, global_conf=None, **kw):
if global_conf is None:
global_conf = {}
codes = [401, 403, 404, 503]
codes = [304, 401, 403, 404, 503]
if not asbool(global_conf.get('debug')):
codes.append(500)
if code in codes:
@@ -62,6 +61,19 @@ def error_mapper(code, message, environ, global_conf=None, **kw):
d['cnameframe'] = 1
if environ.get('REDDIT_NAME'):
d['srname'] = environ.get('REDDIT_NAME')
#preserve x-sup-id when 304ing
if code == 304:
from pylons import c
#check to see if c is useable
try:
c.test
except TypeError:
pass
else:
if c.response.headers.has_key('x-sup-id'):
d['x-sup-id'] = c.response.headers['x-sup-id']
url = '/error/document/?%s' % (urllib.urlencode(d))
return url

View File

@@ -129,6 +129,9 @@ class ErrorController(RedditController):
def GET_document(self):
try:
#no cookies on errors
c.cookies.clear()
code = request.GET.get('code', '')
srname = request.GET.get('srname', '')
if srname:
@@ -144,6 +147,9 @@ class ErrorController(RedditController):
c.response.headers['Retry-After'] = 1
c.response.content = toofast
return c.response
elif code == '304':
c.response.headers['x-sup-id'] = request.GET.get('x-sup-id')
return c.response
elif c.site:
return self.send404()
else:

View File

@@ -386,18 +386,18 @@ class UserController(ListingController):
q = queries.get_overview(self.vuser, 'new', 'all')
elif self.where == 'comments':
self.check_modified(self.vuser, 'commented')
sup.set_sup_header(self.vuser, 'commented')
self.check_modified(self.vuser, 'commented')
q = queries.get_comments(self.vuser, 'new', 'all')
elif self.where == 'submitted':
self.check_modified(self.vuser, 'submitted')
sup.set_sup_header(self.vuser, 'submitted')
self.check_modified(self.vuser, 'submitted')
q = queries.get_submitted(self.vuser, 'new', 'all')
elif self.where in ('liked', 'disliked'):
self.check_modified(self.vuser, self.where)
sup.set_sup_header(self.vuser, self.where)
self.check_modified(self.vuser, self.where)
if self.where == 'liked':
q = queries.get_liked(self.vuser)
else:

View File

@@ -35,6 +35,8 @@ from r2.lib.filters import _force_unicode
import os.path
import random
class SubredditExists(Exception): pass
class Subreddit(Thing, Printable):
_defaults = dict(static_path = g.static_path,
stylesheet = None,

View File

@@ -123,21 +123,20 @@ ${parent.midcol()}
<%def name="buttons()">
<li class="first">
${parent.comment_button("permalink", _("permalink"), 0,
thing.permalink)}
${parent.bylink_button(_("permalink"), thing.permalink)}
</li>
%if thing.deleted:
%if thing.parent_permalink and not c.profilepage:
<li>
${bylink_button("parent", _("parent"), thing.parent_permalink)}
${parent.bylink_button(_("parent"), thing.parent_permalink)}
</li>
%endif
%else:
%if not c.profilepage:
%if thing.parent_permalink:
<li>
${bylink_button("parent", _("parent"), thing.parent_permalink)}
${parent.bylink_button(_("parent"), thing.parent_permalink)}
</li>
%endif
%if c.user_is_loggedin and thing.author.name == c.user.name:
@@ -158,9 +157,3 @@ ${parent.midcol()}
%endif
${self.admintagline()}
</%def>
<%def name="bylink_button(name, title, link)">
<a href="${link}" class="bylink">${title}</a>
</%def>

View File

@@ -21,8 +21,7 @@
################################################################################
<%inherit file="printable.html"/>
<%namespace file="utils.html" import="plain_link" />
<%def name="midcol(display=True)">
%if c.profilepage or (not thing._deleted and (not thing._spam or c.user == thing.author or c.user_is_admin)):
@@ -71,3 +70,6 @@ ${self.tagline(True)}
</div>
</%def>
<%def name="bylink_button(title, link)">
${plain_link(title, link, _class="bylink", rel="nofollow")}
</%def>

View File

@@ -1,38 +0,0 @@
## The contents of this file are subject to the Common Public Attribution
## License Version 1.0. (the "License"); you may not use this file except in
## compliance with the License. You may obtain a copy of the License at
## http://code.reddit.com/LICENSE. The License is based on the Mozilla Public
## License Version 1.1, but Sections 14 and 15 have been added to cover use of
## software over a computer network and provide for limited attribution for the
## Original Developer. In addition, Exhibit A has been modified to be consistent
## with Exhibit B.
##
## Software distributed under the License is distributed on an "AS IS" basis,
## WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
## the specific language governing rights and limitations under the License.
##
## The Original Code is Reddit.
##
## The Original Developer is the Initial Developer. The Initial Developer of
## the Original Code is CondeNet, Inc.
##
## All portions of the code written by CondeNet are Copyright (c) 2006-2009
## CondeNet, Inc. All Rights Reserved.
################################################################################
<%def name="comment_button(name, title, showDsc=True)">
<span id="${name}_${thing._fullname}">
<a href="${thing.permalink}" class="bylink" \
%if newwindow:
target="_blank"\
%endif
>\
%if showDsc and thing.num_comments > 0:
${thing.num_comments} ${title}\
%else:
${title}\
%endif
</a>
</span>
</%def>

View File

@@ -73,8 +73,7 @@ ${unsafe(safemarkdown(thing.body))}
<%def name="buttons()">
%if hasattr(thing, "was_comment"):
<li>
${parent.comment_button("context", _("context"), 0,
thing.permalink + "?context=3")}
${parent.bylink_button(_("context"), thing.permalink + "?context=3")}
</li>
${parent.delete_or_report_buttons(delete=False)}
%else:

View File

@@ -339,4 +339,3 @@ thing id-${what._fullname}
_class="%s %s" % (a_class, cls), title=title, target=target)}
</%def>