Ejemplo n.º 1
0
    def GET_policy_page(self, page, requested_rev):
        if c.render_style == 'compact':
            self.redirect('/wiki/' + page)
        if page == 'privacypolicy':
            wiki_name = g.wiki_page_privacy_policy
            pagename = _('privacy policy')
        elif page == 'useragreement':
            wiki_name = g.wiki_page_user_agreement
            pagename = _('user agreement')
        elif page == 'contentpolicy':
            wiki_name = g.wiki_page_content_policy
            pagename = _('content policy')
        else:
            abort(404)

        wp = WikiPage.get(Frontpage, wiki_name)

        revs = list(wp.get_revisions())

        # collapse minor edits into revisions with reasons
        rev_info = []
        last_edit = None
        for rev in revs:
            if rev.is_hidden:
                continue

            if not last_edit:
                last_edit = rev

            if rev._get('reason'):
                rev_info.append({
                    'id': str(last_edit._id),
                    'title': rev._get('reason'),
                })
                last_edit = None

        if requested_rev:
            try:
                display_rev = WikiRevision.get(requested_rev, wp._id)
            except (tdb_cassandra.NotFound, WikiBadRevision):
                abort(404)
        else:
            display_rev = revs[0]

        doc_html = wikimarkdown(display_rev.content, include_toc=False)
        soup = BeautifulSoup(doc_html.decode('utf-8'))
        toc = generate_table_of_contents(soup, prefix='section')
        self._number_sections(soup)
        self._linkify_headings(soup)

        content = PolicyView(
            body_html=unsafe(soup),
            toc_html=unsafe(toc),
            revs=rev_info,
            display_rev=str(display_rev._id),
        )
        return PolicyPage(
            pagename=pagename,
            content=content,
        ).render()
Ejemplo n.º 2
0
    def search_fail(self, exception):
        from r2.lib.contrib.pysolr import SolrError
        from r2.lib.indextank import IndextankException

        if isinstance(exception, SolrError):
            errmsg = "SolrError: %r" % exception

            if str(exception) == "None":
                # Production error logs only get non-None errors
                g.log.debug(errmsg)
            else:
                g.log.error(errmsg)
        elif isinstance(exception, (IndextankException, socket.error)):
            g.log.error("IndexTank Error: %s" % repr(exception))

        sf = pages.SearchFail()

        us = filters.unsafe(sf.render())

        errpage = pages.SciteitError(_("search failed"), us)

        c.response = Response()
        c.response.status_code = 503
        request.environ["usable_error_content"] = errpage.render()
        request.environ["retry_after"] = 60

        abort(503)
Ejemplo n.º 3
0
    def search_fail(self, exception):
        from r2.lib.contrib.pysolr import SolrError
        from r2.lib.indextank import IndextankException
        if isinstance(exception, SolrError):
            errmsg = "SolrError: %r" % exception

            if (str(exception) == 'None'):
                # Production error logs only get non-None errors
                g.log.debug(errmsg)
            else:
                g.log.error(errmsg)
        elif isinstance(exception, (IndextankException, socket.error)):
            g.log.error("IndexTank Error: %s" % repr(exception))

        sf = pages.SearchFail()

        us = filters.unsafe(sf.render())

        errpage = pages.RedditError(_('search failed'), us)

        c.response = Response()
        c.response.status_code = 503
        request.environ['usable_error_content'] = errpage.render()
        request.environ['retry_after'] = 60

        abort(503)
Ejemplo n.º 4
0
    def send404(self):
        c.response.status_code = 404
        if 'usable_error_content' in request.environ:
            return request.environ['usable_error_content']
        if c.site._spam and not c.user_is_admin:
            message = (strings.banned_subreddit % dict(link = '/feedback'))

            res = pages.RedditError(_('this reddit has been banned'),
                                    unsafe(safemarkdown(message)))
            return res.render()
        else:
            return pages.Reddit404().render()
Ejemplo n.º 5
0
    def send404(self):
        c.response.status_code = 404
        if "usable_error_content" in request.environ:
            return request.environ["usable_error_content"]
        if c.site.spammy() and not c.user_is_admin:
            subject = "the subreddit /r/%s has been incorrectly banned" % c.site.name
            lnk = "/r/redditrequest/submit?url=%s&title=%s" % (
                url_escape("http://%s/r/%s" % (g.domain, c.site.name)),
                ("the subreddit /r/%s has been incorrectly banned" % c.site.name),
            )
            message = strings.banned_subreddit % dict(link=lnk)

            res = pages.RedditError(_("this reddit has been banned"), unsafe(safemarkdown(message)))
            return res.render()
        else:
            return pages.Reddit404().render()
Ejemplo n.º 6
0
    def send404(self):
        c.response.status_code = 404
        if 'usable_error_content' in request.environ:
            return request.environ['usable_error_content']
        if c.site._spam and not c.user_is_admin:
            subject = ("the subreddit /r/%s has been incorrectly banned" %
                       c.site.name)
            message = (strings.banned_subreddit %
                       dict(link = '/message/compose?to=%s&subject=%s' %
                            (url_escape(g.admin_message_acct),
                             url_escape(subject))))

            res = pages.RedditError(_('this reddit has been banned'),
                                    unsafe(safemarkdown(message)))
            return res.render()
        else:
            return pages.Reddit404().render()
Ejemplo n.º 7
0
    def send404(self):
        c.response.status_code = 404
        if 'usable_error_content' in request.environ:
            return request.environ['usable_error_content']
        if c.site._spam and not c.user_is_admin:
            subject = ("the subreddit /r/%s has been incorrectly banned" %
                       c.site.name)
            message = (
                strings.banned_subreddit %
                dict(link='/message/compose?to=%s&subject=%s' %
                     (url_escape(g.admin_message_acct), url_escape(subject))))

            res = pages.RedditError(_('this reddit has been banned'),
                                    unsafe(safemarkdown(message)))
            return res.render()
        else:
            return pages.Reddit404().render()
Ejemplo n.º 8
0
    def send404(self):
        c.response.status_code = 404
        if 'usable_error_content' in request.environ:
            return request.environ['usable_error_content']
        if c.site.spammy() and not c.user_is_admin:
            subject = ("the subreddit /r/%s has been incorrectly banned" %
                       c.site.name)
            lnk = ("/r/redditrequest/submit?url=%s&title=%s" %
                   (url_escape("http://%s/r/%s" % (g.domain, c.site.name)),
                    ("the subreddit /r/%s has been incorrectly banned" %
                     c.site.name)))
            message = strings.banned_subreddit % dict(link=lnk)

            res = pages.RedditError(_('this reddit has been banned'),
                                    unsafe(safemarkdown(message)))
            return res.render()
        else:
            return pages.Reddit404().render()
Ejemplo n.º 9
0
    def _search(self, query_obj, num, after, reverse, count=0):
        """Helper function for interfacing with search.  Basically a
        thin wrapper for SearchBuilder."""

        builder = SearchBuilder(
            query_obj,
            after=after,
            num=num,
            reverse=reverse,
            count=count,
            wrap=ListingController.builder_wrapper)

        listing = LinkListing(builder, show_nums=True)

        # have to do it in two steps since total_num and timing are only
        # computed after fetch_more
        try:
            res = listing.listing()
        except SolrError, e:
            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
                g.log.debug(errmsg)
            else:
                g.log.error(errmsg)

            sf = SearchFail()
            sb = SearchBar(prev_search=query_obj.q)

            us = unsafe(sb.render() + sf.render())

            errpage = pages.RedditError(_('search failed'), us)

            c.response = Response()
            c.response.status_code = 503
            request.environ['usable_error_content'] = errpage.render()
            request.environ['retry_after'] = 60

            abort(503)
Ejemplo n.º 10
0
    def _search(self, query_obj, num, after, reverse, count=0):
        """Helper function for interfacing with search.  Basically a
        thin wrapper for SearchBuilder."""

        builder = SearchBuilder(query_obj,
                                after=after,
                                num=num,
                                reverse=reverse,
                                count=count,
                                wrap=ListingController.builder_wrapper)

        listing = LinkListing(builder, show_nums=True)

        # have to do it in two steps since total_num and timing are only
        # computed after fetch_more
        try:
            res = listing.listing()
        except SolrError, e:
            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
                g.log.debug(errmsg)
            else:
                g.log.error(errmsg)

            sf = SearchFail()
            sb = SearchBar(prev_search=query_obj.q)

            us = unsafe(sb.render() + sf.render())

            errpage = pages.RedditError(_('search failed'), us)

            c.response = Response()
            c.response.status_code = 503
            request.environ['usable_error_content'] = errpage.render()
            request.environ['retry_after'] = 60

            abort(503)
Ejemplo n.º 11
0
    def search_fail(self, exception):
        from r2.lib.contrib.pysolr import SolrError
        from r2.lib.indextank import IndextankException
        if isinstance(exception, SolrError):
            errmsg = "SolrError: %r" % exception

            if (str(exception) == 'None'):
                # Production error logs only get non-None errors
                g.log.debug(errmsg)
            else:
                g.log.error(errmsg)
        elif isinstance(exception, (IndextankException, socket.error)):
            g.log.error("IndexTank Error: %s" % repr(exception))

        sf = pages.SearchFail()

        us = filters.unsafe(sf.render())

        errpage = pages.RedditError(_('search failed'), us)
        request.environ['usable_error_content'] = errpage.render()
        request.environ['retry_after'] = 60
        abort(503)
Ejemplo n.º 12
0
    def send404(self):
        c.response.status_code = 404
        if 'usable_error_content' in request.environ:
            return request.environ['usable_error_content']
        if c.site.spammy() and not c.user_is_admin:
            ban_info = getattr(c.site, "ban_info", {})
            if "message" in ban_info:
                message = ban_info["message"]
            else:
                subject = ("the subreddit /r/%s has been incorrectly banned" %
                           c.site.name)
                lnk = ("/r/redditrequest/submit?url=%s&title=%s"
                       % (url_escape("http://%s/r/%s" % (g.domain, c.site.name)),
                          ("the subreddit /r/%s has been incorrectly banned" %
                           c.site.name)))
                message = strings.banned_subreddit % dict(link = lnk)

            res = pages.RedditError(_('this reddit has been banned'),
                                    unsafe(safemarkdown(message)))
            return res.render()
        else:
            return pages.Reddit404().render()