mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-04-27 03:00:12 -04:00
redirect: Use our actual redirect.
This commit is contained in:
@@ -21,7 +21,6 @@
|
||||
###############################################################################
|
||||
|
||||
from pylons.i18n import _, ungettext
|
||||
from pylons.controllers.util import redirect_to
|
||||
from r2.controllers.reddit_base import (
|
||||
base_listing,
|
||||
pagecache_policy,
|
||||
@@ -449,7 +448,7 @@ class FrontController(RedditController):
|
||||
if c.site.stylesheet_url_http:
|
||||
url = Reddit.get_subreddit_stylesheet_url()
|
||||
if url:
|
||||
redirect_to(url)
|
||||
return self.redirect(url)
|
||||
else:
|
||||
self.abort404()
|
||||
|
||||
|
||||
@@ -50,7 +50,6 @@ import socket
|
||||
from api_docs import api_doc, api_section
|
||||
|
||||
from pylons.i18n import _
|
||||
from pylons.controllers.util import redirect_to
|
||||
|
||||
import random
|
||||
from functools import partial
|
||||
@@ -789,7 +788,7 @@ class UserController(ListingController):
|
||||
query_string = request.environ.get('QUERY_STRING')
|
||||
if query_string:
|
||||
dest += "?" + query_string
|
||||
return redirect_to(dest)
|
||||
return self.redirect(dest)
|
||||
|
||||
class MessageController(ListingController):
|
||||
show_nums = False
|
||||
|
||||
@@ -40,7 +40,6 @@ import pylibmc
|
||||
|
||||
from mako.filters import url_escape
|
||||
from pylons import c, g, request, response
|
||||
from pylons.controllers.util import redirect_to
|
||||
from pylons.i18n import _
|
||||
from pylons.i18n.translation import LanguageError
|
||||
|
||||
@@ -356,7 +355,8 @@ def set_subreddit():
|
||||
domain = g.domain
|
||||
if g.domain_prefix:
|
||||
domain = ".".join((g.domain_prefix, domain))
|
||||
redirect_to('http://%s%s' % (domain, sr.path), _code=301)
|
||||
path = 'http://%s%s' % (domain, sr.path)
|
||||
abort(301, location=BaseController.format_output_url(path))
|
||||
elif sr_name == 'r':
|
||||
#reddits
|
||||
c.site = Sub
|
||||
@@ -395,14 +395,16 @@ def set_subreddit():
|
||||
else:
|
||||
c.site = Mod
|
||||
else:
|
||||
redirect_to("/subreddits/search?q=%s" % sr_name)
|
||||
path = "/subreddits/search?q=%s" % sr_name
|
||||
abort(302, location=BaseController.format_output_url(path))
|
||||
else:
|
||||
try:
|
||||
c.site = Subreddit._by_name(sr_name, stale=can_stale)
|
||||
except NotFound:
|
||||
sr_name = chksrname(sr_name)
|
||||
if sr_name:
|
||||
redirect_to("/subreddits/search?q=%s" % sr_name)
|
||||
path = "/subreddits/search?q=%s" % sr_name
|
||||
abort(302, location=BaseController.format_output_url(path))
|
||||
elif not c.error_page and not request.path.startswith("/api/login/") :
|
||||
abort(404)
|
||||
|
||||
@@ -412,7 +414,9 @@ def set_subreddit():
|
||||
try:
|
||||
idna = _force_unicode(domain).encode("idna")
|
||||
if idna != domain:
|
||||
redirect_to("/domain/%s%s" % (idna, request.environ["PATH_INFO"]))
|
||||
path_info = request.environ["PATH_INFO"]
|
||||
path = "/domain/%s%s" % (idna, path_info)
|
||||
abort(302, location=BaseController.format_output_url(path))
|
||||
except UnicodeError:
|
||||
domain = '' # Ensure valid_ascii_domain fails
|
||||
if not c.error_page and not valid_ascii_domain.match(domain):
|
||||
@@ -440,7 +444,8 @@ def set_multireddit():
|
||||
# trim off multi id
|
||||
url_parts = request.path_qs.split("/")[5:]
|
||||
url_parts.insert(0, "/me/m/%s" % multipath)
|
||||
abort(302, location="/".join(url_parts))
|
||||
path = "/".join(url_parts)
|
||||
abort(302, location=BaseController.format_output_url(path))
|
||||
|
||||
multi_id = "/user/%s/m/%s" % (username, multipath)
|
||||
|
||||
@@ -879,6 +884,7 @@ class MinimalController(BaseController):
|
||||
c.cdn_cacheable = (request.via_cdn and
|
||||
g.login_cookie not in request.cookies)
|
||||
|
||||
c.extension = request.environ.get('extension')
|
||||
# the domain has to be set before Cookies get initialized
|
||||
set_subreddit()
|
||||
c.errors = ErrorSet()
|
||||
@@ -1274,16 +1280,21 @@ class RedditController(OAuth2ResourceController):
|
||||
# random reddit trickery -- have to do this after the content lang is set
|
||||
if c.site == Random:
|
||||
c.site = Subreddit.random_reddit(user=c.user)
|
||||
redirect_to("/" + c.site.path.strip('/') + request.path_qs)
|
||||
site_path = c.site.path.strip('/')
|
||||
path = "/" + site_path + request.path_qs
|
||||
abort(302, location=self.format_output_url(path))
|
||||
elif c.site == RandomSubscription:
|
||||
if c.user.gold:
|
||||
c.site = Subreddit.random_subscription(c.user)
|
||||
redirect_to('/' + c.site.path.strip('/') + request.path_qs)
|
||||
else:
|
||||
redirect_to('/gold/about')
|
||||
if not c.user.gold:
|
||||
abort(302, location=self.format_output_url('/gold/about'))
|
||||
c.site = Subreddit.random_subscription(c.user)
|
||||
site_path = c.site.path.strip('/')
|
||||
path = '/' + site_path + request.path_qs
|
||||
abort(302, location=self.format_output_url(path))
|
||||
elif c.site == RandomNSFW:
|
||||
c.site = Subreddit.random_reddit(over18=True, user=c.user)
|
||||
redirect_to("/" + c.site.path.strip('/') + request.path_qs)
|
||||
site_path = c.site.path.strip('/')
|
||||
path = '/' + site_path + request.path_qs
|
||||
abort(302, location=self.format_output_url(path))
|
||||
|
||||
if not request.path.startswith("/api/login/"):
|
||||
# is the subreddit banned?
|
||||
|
||||
@@ -19,16 +19,20 @@
|
||||
# All portions of the code written by reddit are Copyright (c) 2006-2013 reddit
|
||||
# Inc. All Rights Reserved.
|
||||
###############################################################################
|
||||
from pylons import request
|
||||
from pylons.controllers.util import abort, redirect_to
|
||||
from pylons import request, c
|
||||
from pylons.controllers.util import abort
|
||||
|
||||
from r2.lib.base import BaseController
|
||||
from r2.lib.validator import chkuser, chksrname
|
||||
|
||||
|
||||
class RedirectController(BaseController):
|
||||
def pre(self, *k, **kw):
|
||||
BaseController.pre(self, *k, **kw)
|
||||
c.extension = request.environ.get('extension')
|
||||
|
||||
def GET_redirect(self, dest):
|
||||
return redirect_to(str(dest))
|
||||
return self.redirect(str(dest))
|
||||
|
||||
def GET_user_redirect(self, username, rest=None):
|
||||
user = chkuser(username)
|
||||
@@ -39,7 +43,7 @@ class RedirectController(BaseController):
|
||||
url += "/" + rest
|
||||
if request.query_string:
|
||||
url += "?" + request.query_string
|
||||
return redirect_to(str(url), _code=301)
|
||||
return self.redirect(str(url), code=301)
|
||||
|
||||
def GET_timereddit_redirect(self, timereddit, rest=None):
|
||||
tr_name = chksrname(timereddit)
|
||||
@@ -49,4 +53,4 @@ class RedirectController(BaseController):
|
||||
rest = str(rest)
|
||||
else:
|
||||
rest = ''
|
||||
return redirect_to("/r/t:%s/%s" % (tr_name, rest), _code=301)
|
||||
return self.redirect("/r/t:%s/%s" % (tr_name, rest), code=301)
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
###############################################################################
|
||||
|
||||
from pylons import request, g, c
|
||||
from pylons.controllers.util import redirect_to
|
||||
from reddit_base import RedditController
|
||||
from r2.controllers.oauth2 import require_oauth2_scope
|
||||
from r2.lib.utils import url_links_builder
|
||||
@@ -242,7 +241,7 @@ class WikiController(RedditController):
|
||||
return WikiListing(pages, linear_pages).render()
|
||||
|
||||
def GET_wiki_redirect(self, page='index'):
|
||||
return redirect_to(str("%s/%s" % (c.wiki_base_url, page)), _code=301)
|
||||
return self.redirect(str("%s/%s" % (c.wiki_base_url, page)), code=301)
|
||||
|
||||
@require_oauth2_scope("wikiread")
|
||||
@api_doc(api_section.wiki, uri='/wiki/discussions/{page}', uses_site=True)
|
||||
|
||||
@@ -27,7 +27,6 @@ import re
|
||||
|
||||
from pylons.i18n import _
|
||||
|
||||
from pylons.controllers.util import redirect_to
|
||||
from pylons import c, g, request
|
||||
|
||||
from r2.models.wiki import WikiPage, WikiRevision, WikiBadRevision
|
||||
|
||||
Reference in New Issue
Block a user