From 2d86a76962c242b8752a6432fcacfc259b10f177 Mon Sep 17 00:00:00 2001 From: spez Date: Thu, 12 Feb 2009 14:34:43 -0800 Subject: [PATCH] Send sup-id headers on 304s, added nofollows to comment permalinks --- r2/r2/config/middleware.py | 16 +++++++++-- r2/r2/controllers/error.py | 6 ++++ r2/r2/controllers/listingcontroller.py | 6 ++-- r2/r2/models/subreddit.py | 2 ++ r2/r2/templates/comment.html | 13 ++------- r2/r2/templates/comment_skeleton.html | 6 ++-- r2/r2/templates/commentbutton.html | 38 -------------------------- r2/r2/templates/message.html | 3 +- r2/r2/templates/printable.html | 1 - 9 files changed, 33 insertions(+), 58 deletions(-) delete mode 100644 r2/r2/templates/commentbutton.html diff --git a/r2/r2/config/middleware.py b/r2/r2/config/middleware.py index 90971fee8..89643d8c6 100644 --- a/r2/r2/config/middleware.py +++ b/r2/r2/config/middleware.py @@ -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 diff --git a/r2/r2/controllers/error.py b/r2/r2/controllers/error.py index eb029d188..88bd6907c 100644 --- a/r2/r2/controllers/error.py +++ b/r2/r2/controllers/error.py @@ -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: diff --git a/r2/r2/controllers/listingcontroller.py b/r2/r2/controllers/listingcontroller.py index d4fe22724..c94882b9d 100644 --- a/r2/r2/controllers/listingcontroller.py +++ b/r2/r2/controllers/listingcontroller.py @@ -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: diff --git a/r2/r2/models/subreddit.py b/r2/r2/models/subreddit.py index 8f2673871..51d9b8b65 100644 --- a/r2/r2/models/subreddit.py +++ b/r2/r2/models/subreddit.py @@ -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, diff --git a/r2/r2/templates/comment.html b/r2/r2/templates/comment.html index 56c015014..765a4fd12 100644 --- a/r2/r2/templates/comment.html +++ b/r2/r2/templates/comment.html @@ -123,21 +123,20 @@ ${parent.midcol()} <%def name="buttons()">
  • - ${parent.comment_button("permalink", _("permalink"), 0, - thing.permalink)} + ${parent.bylink_button(_("permalink"), thing.permalink)}
  • %if thing.deleted: %if thing.parent_permalink and not c.profilepage:
  • - ${bylink_button("parent", _("parent"), thing.parent_permalink)} + ${parent.bylink_button(_("parent"), thing.parent_permalink)}
  • %endif %else: %if not c.profilepage: %if thing.parent_permalink:
  • - ${bylink_button("parent", _("parent"), thing.parent_permalink)} + ${parent.bylink_button(_("parent"), thing.parent_permalink)}
  • %endif %if c.user_is_loggedin and thing.author.name == c.user.name: @@ -158,9 +157,3 @@ ${parent.midcol()} %endif ${self.admintagline()} - - -<%def name="bylink_button(name, title, link)"> - ${title} - - diff --git a/r2/r2/templates/comment_skeleton.html b/r2/r2/templates/comment_skeleton.html index fa65bafc3..155780837 100644 --- a/r2/r2/templates/comment_skeleton.html +++ b/r2/r2/templates/comment_skeleton.html @@ -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)} +<%def name="bylink_button(title, link)"> + ${plain_link(title, link, _class="bylink", rel="nofollow")} + diff --git a/r2/r2/templates/commentbutton.html b/r2/r2/templates/commentbutton.html deleted file mode 100644 index 6f45da636..000000000 --- a/r2/r2/templates/commentbutton.html +++ /dev/null @@ -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)"> - - \ - %if showDsc and thing.num_comments > 0: - ${thing.num_comments} ${title}\ - %else: - ${title}\ - %endif - - - - diff --git a/r2/r2/templates/message.html b/r2/r2/templates/message.html index 0ffea0dd8..62f66cf3a 100644 --- a/r2/r2/templates/message.html +++ b/r2/r2/templates/message.html @@ -73,8 +73,7 @@ ${unsafe(safemarkdown(thing.body))} <%def name="buttons()"> %if hasattr(thing, "was_comment"):
  • - ${parent.comment_button("context", _("context"), 0, - thing.permalink + "?context=3")} + ${parent.bylink_button(_("context"), thing.permalink + "?context=3")}
  • ${parent.delete_or_report_buttons(delete=False)} %else: diff --git a/r2/r2/templates/printable.html b/r2/r2/templates/printable.html index 08265dbf5..8bf11eecc 100644 --- a/r2/r2/templates/printable.html +++ b/r2/r2/templates/printable.html @@ -339,4 +339,3 @@ thing id-${what._fullname} _class="%s %s" % (a_class, cls), title=title, target=target)} -