{"payload":{"allShortcutsEnabled":false,"fileTree":{"r2/r2/lib/pages":{"items":[{"name":"__init__.py","path":"r2/r2/lib/pages/__init__.py","contentType":"file"},{"name":"admin_pages.py","path":"r2/r2/lib/pages/admin_pages.py","contentType":"file"},{"name":"pages.py","path":"r2/r2/lib/pages/pages.py","contentType":"file"},{"name":"things.py","path":"r2/r2/lib/pages/things.py","contentType":"file"},{"name":"trafficpages.py","path":"r2/r2/lib/pages/trafficpages.py","contentType":"file"},{"name":"wiki.py","path":"r2/r2/lib/pages/wiki.py","contentType":"file"}],"totalCount":6},"r2/r2/lib":{"items":[{"name":"authorize","path":"r2/r2/lib/authorize","contentType":"directory"},{"name":"c","path":"r2/r2/lib/c","contentType":"directory"},{"name":"contrib","path":"r2/r2/lib/contrib","contentType":"directory"},{"name":"db","path":"r2/r2/lib/db","contentType":"directory"},{"name":"manager","path":"r2/r2/lib/manager","contentType":"directory"},{"name":"migrate","path":"r2/r2/lib/migrate","contentType":"directory"},{"name":"mr_tools","path":"r2/r2/lib/mr_tools","contentType":"directory"},{"name":"pages","path":"r2/r2/lib/pages","contentType":"directory"},{"name":"utils","path":"r2/r2/lib/utils","contentType":"directory"},{"name":"__init__.py","path":"r2/r2/lib/__init__.py","contentType":"file"},{"name":"_normalized_hot.pyx","path":"r2/r2/lib/_normalized_hot.pyx","contentType":"file"},{"name":"amqp.py","path":"r2/r2/lib/amqp.py","contentType":"file"},{"name":"app_globals.py","path":"r2/r2/lib/app_globals.py","contentType":"file"},{"name":"authentication.py","path":"r2/r2/lib/authentication.py","contentType":"file"},{"name":"base.py","path":"r2/r2/lib/base.py","contentType":"file"},{"name":"cache.py","path":"r2/r2/lib/cache.py","contentType":"file"},{"name":"captcha.py","path":"r2/r2/lib/captcha.py","contentType":"file"},{"name":"cloudsearch.py","path":"r2/r2/lib/cloudsearch.py","contentType":"file"},{"name":"comment_tree.py","path":"r2/r2/lib/comment_tree.py","contentType":"file"},{"name":"configparse.py","path":"r2/r2/lib/configparse.py","contentType":"file"},{"name":"count.py","path":"r2/r2/lib/count.py","contentType":"file"},{"name":"cssfilter.py","path":"r2/r2/lib/cssfilter.py","contentType":"file"},{"name":"emailer.py","path":"r2/r2/lib/emailer.py","contentType":"file"},{"name":"export.py","path":"r2/r2/lib/export.py","contentType":"file"},{"name":"filters.py","path":"r2/r2/lib/filters.py","contentType":"file"},{"name":"hardcachebackend.py","path":"r2/r2/lib/hardcachebackend.py","contentType":"file"},{"name":"helpers.py","path":"r2/r2/lib/helpers.py","contentType":"file"},{"name":"js.py","path":"r2/r2/lib/js.py","contentType":"file"},{"name":"jsonresponse.py","path":"r2/r2/lib/jsonresponse.py","contentType":"file"},{"name":"jsontemplates.py","path":"r2/r2/lib/jsontemplates.py","contentType":"file"},{"name":"lock.py","path":"r2/r2/lib/lock.py","contentType":"file"},{"name":"log.py","path":"r2/r2/lib/log.py","contentType":"file"},{"name":"media.py","path":"r2/r2/lib/media.py","contentType":"file"},{"name":"memoize.py","path":"r2/r2/lib/memoize.py","contentType":"file"},{"name":"menus.py","path":"r2/r2/lib/menus.py","contentType":"file"},{"name":"merge.py","path":"r2/r2/lib/merge.py","contentType":"file"},{"name":"mr_account.py","path":"r2/r2/lib/mr_account.py","contentType":"file"},{"name":"mr_gold.py","path":"r2/r2/lib/mr_gold.py","contentType":"file"},{"name":"mr_top.py","path":"r2/r2/lib/mr_top.py","contentType":"file"},{"name":"normalized_hot.py","path":"r2/r2/lib/normalized_hot.py","contentType":"file"},{"name":"nymph.py","path":"r2/r2/lib/nymph.py","contentType":"file"},{"name":"organic.py","path":"r2/r2/lib/organic.py","contentType":"file"},{"name":"plugin.py","path":"r2/r2/lib/plugin.py","contentType":"file"},{"name":"promote.py","path":"r2/r2/lib/promote.py","contentType":"file"},{"name":"require.py","path":"r2/r2/lib/require.py","contentType":"file"},{"name":"rising.py","path":"r2/r2/lib/rising.py","contentType":"file"},{"name":"s3cp.py","path":"r2/r2/lib/s3cp.py","contentType":"file"},{"name":"scraper.py","path":"r2/r2/lib/scraper.py","contentType":"file"},{"name":"search.py","path":"r2/r2/lib/search.py","contentType":"file"},{"name":"sgm.pyx","path":"r2/r2/lib/sgm.pyx","contentType":"file"},{"name":"sr_pops.py","path":"r2/r2/lib/sr_pops.py","contentType":"file"},{"name":"static.py","path":"r2/r2/lib/static.py","contentType":"file"},{"name":"stats.py","path":"r2/r2/lib/stats.py","contentType":"file"},{"name":"strings.py","path":"r2/r2/lib/strings.py","contentType":"file"},{"name":"subreddit_search.py","path":"r2/r2/lib/subreddit_search.py","contentType":"file"},{"name":"sup.py","path":"r2/r2/lib/sup.py","contentType":"file"},{"name":"template_helpers.py","path":"r2/r2/lib/template_helpers.py","contentType":"file"},{"name":"totp.py","path":"r2/r2/lib/totp.py","contentType":"file"},{"name":"tracking.py","path":"r2/r2/lib/tracking.py","contentType":"file"},{"name":"translation.py","path":"r2/r2/lib/translation.py","contentType":"file"},{"name":"wrapped.pyx","path":"r2/r2/lib/wrapped.pyx","contentType":"file"},{"name":"wrapper.py","path":"r2/r2/lib/wrapper.py","contentType":"file"},{"name":"zookeeper.py","path":"r2/r2/lib/zookeeper.py","contentType":"file"}],"totalCount":63},"r2/r2":{"items":[{"name":"config","path":"r2/r2/config","contentType":"directory"},{"name":"controllers","path":"r2/r2/controllers","contentType":"directory"},{"name":"lib","path":"r2/r2/lib","contentType":"directory"},{"name":"models","path":"r2/r2/models","contentType":"directory"},{"name":"public","path":"r2/r2/public","contentType":"directory"},{"name":"templates","path":"r2/r2/templates","contentType":"directory"},{"name":"tests","path":"r2/r2/tests","contentType":"directory"},{"name":"__init__.py","path":"r2/r2/__init__.py","contentType":"file"},{"name":"commands.py","path":"r2/r2/commands.py","contentType":"file"},{"name":"websetup.py","path":"r2/r2/websetup.py","contentType":"file"}],"totalCount":10},"r2":{"items":[{"name":"r2","path":"r2/r2","contentType":"directory"},{"name":"Makefile","path":"r2/Makefile","contentType":"file"},{"name":"Makefile.py","path":"r2/Makefile.py","contentType":"file"},{"name":"babel.cfg","path":"r2/babel.cfg","contentType":"file"},{"name":"example.ini","path":"r2/example.ini","contentType":"file"},{"name":"ez_setup.py","path":"r2/ez_setup.py","contentType":"file"},{"name":"pylintrc","path":"r2/pylintrc","contentType":"file"},{"name":"setup.cfg","path":"r2/setup.cfg","contentType":"file"},{"name":"setup.py","path":"r2/setup.py","contentType":"file"},{"name":"updateini.py","path":"r2/updateini.py","contentType":"file"}],"totalCount":10},"":{"items":[{"name":"r2","path":"r2","contentType":"directory"},{"name":"scripts","path":"scripts","contentType":"directory"},{"name":"sql","path":"sql","contentType":"directory"},{"name":"upstart","path":"upstart","contentType":"directory"},{"name":".gitignore","path":".gitignore","contentType":"file"},{"name":".mailmap","path":".mailmap","contentType":"file"},{"name":"LICENSE","path":"LICENSE","contentType":"file"},{"name":"install-reddit.sh","path":"install-reddit.sh","contentType":"file"}],"totalCount":8}},"fileTreeProcessingTime":20.588997000000003,"foldersToFetch":[],"repo":{"id":5487669,"defaultBranch":"master","name":"reddit","ownerLogin":"kkress","currentUserCanPush":false,"isFork":true,"isEmpty":false,"createdAt":"2012-08-20T22:36:18.000Z","ownerAvatar":"https://avatars.githubusercontent.com/u/271525?v=4","public":true,"private":false,"isOrgOwned":false},"symbolsExpanded":false,"treeExpanded":true,"refInfo":{"name":"c77d070d837758d4c06b9b47fdaf4488f491e28d","listCacheKey":"v0:1615260746.164823","canEdit":false,"refType":"tree","currentOid":"c77d070d837758d4c06b9b47fdaf4488f491e28d"},"path":"r2/r2/lib/pages/pages.py","currentUser":null,"blob":{"rawLines":["# 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 reddit Inc.","#","# All portions of the code written by reddit are Copyright (c) 2006-2012 reddit","# Inc. All Rights Reserved.","###############################################################################","","import datetime","import pycountry","import random","import time","from itertools import chain","from urllib import quote","","import simplejson","from pylons.i18n import _","from pylons import g, c, request","from pylons.controllers.util import abort","","import r2.models as models","from r2.config import cache","from r2.config.extensions import is_api","from r2.lib import promote, menus","from r2.lib.captcha import get_iden","from r2.lib.db.thing import Thing, NotFound","from r2.lib.export import export","from r2.lib.filters import (#Functions"," _force_unicode,"," _force_utf8,"," safemarkdown,"," spaceCompress,"," unsafe,"," websafe,"," websafe_json,"," #Constants"," SC_ON,"," SC_OFF,"," )","from r2.lib.jsonresponse import json_respond","from r2.lib.log import log_text","from r2.lib.memoize import memoize","from r2.lib.menus import menu","from r2.lib.scraper import get_media_embed","from r2.lib.strings import plurals, rand_strings, strings, Score","from r2.lib.subreddit_search import popular_searches","from r2.lib.template_helpers import add_sr, get_domain, format_number","from r2.lib.tracking import AdframeInfo","from r2.lib.utils import (#Classes"," UrlParser,"," #Functions"," title_to_url,"," query_string,"," to_js,"," vote_hash,"," link_duplicates,"," make_offset_date,"," median,"," to36,"," trunc_time,"," timesince,"," timeuntil,"," )","from r2.lib.utils import trunc_string as _truncate","from r2.lib.wrapped import Wrapped, Templated, CachedTemplate","from r2.lib.wrapper import wrap_links, default_thing_wrapper","from r2.models import traffic","","__all__ = ["," #Constants Only, use @export for functions/classes"," ]","","","# the ip tracking code is currently deeply tied with spam prevention stuff","# this will be open sourced as soon as it can be decoupled","try:"," from r2admin.lib.ip_events import ips_by_account_id","except ImportError:"," def ips_by_account_id(account_id):"," return []","","","datefmt = _force_utf8(_('%d %b %Y'))","","MAX_DESCRIPTION_LENGTH = 150","","def get_captcha():"," if not c.user_is_loggedin or c.user.needs_captcha():"," return get_iden()","","def responsive(res, space_compress = False):"," \"\"\""," Use in places where the template is returned as the result of the"," controller so that it becomes compatible with the page cache."," \"\"\""," if is_api():"," res = json_respond(res)"," if c.allowed_callback:"," res = \"%s(%s)\" % (websafe_json(c.allowed_callback), res)"," elif space_compress:"," res = spaceCompress(res)"," c.response.content = res"," return c.response","","","@export","class Reddit(Templated):"," '''Base class for rendering a page on reddit. Handles toolbar creation,"," content of the footers, and content of the corner buttons.",""," Constructor arguments:",""," space_compress -- run r2.lib.filters.spaceCompress on render"," loginbox -- enable/disable rendering of the small login box in the right margin"," (only if no user is logged in; login box will be disabled for a logged in user)"," show_sidebar -- enable/disable content in the right margin"," "," infotext -- text to display in a
above the content"," nav_menus -- list of Menu objects to be shown in the area below the header"," content -- renderable object to fill the main content well in the page.",""," settings determined at class-declaration time",""," create_reddit_box -- enable/disable display of the \"Create a reddit\" box"," submit_box -- enable/disable display of the \"Submit\" box"," searchbox -- enable/disable the \"search\" box in the header"," extension_handling -- enable/disable rendering using non-html templates"," (e.g. js, xml for rss, etc.)"," '''",""," create_reddit_box = True"," submit_box = True"," footer = True"," searchbox = True"," extension_handling = True"," enable_login_cover = True"," site_tracking = True"," show_firsttext = True"," content_id = None"," css_class = None"," additional_css = None"," extra_page_classes = None",""," def __init__(self, space_compress = True, nav_menus = None, loginbox = True,"," infotext = '', content = None, short_description='', title = '', robots = None, "," show_sidebar = True, footer = True, srbar = True, page_classes = None,"," **context):"," Templated.__init__(self, **context)"," self.title = title"," self.short_description = short_description"," self.robots = robots"," self.infotext = infotext"," self.loginbox = True"," self.show_sidebar = show_sidebar"," self.space_compress = space_compress and not g.template_debug"," # instantiate a footer"," self.footer = RedditFooter() if footer else None"," self.supplied_page_classes = page_classes or []",""," #put the sort menus at the top"," self.nav_menu = MenuArea(menus = nav_menus) if nav_menus else None",""," #add the infobar"," self.infobar = None"," # generate a canonical link for google"," self.canonical_link = request.fullpath"," if c.render_style != \"html\":"," u = UrlParser(request.fullpath)"," u.set_extension(\"\")"," u.hostname = g.domain"," if g.domain_prefix:"," u.hostname = \"%s.%s\" % (g.domain_prefix, u.hostname)"," self.canonical_link = u.unparse()"," if self.show_firsttext and not infotext:"," if g.heavy_load_mode:"," # heavy load mode message overrides read only"," infotext = strings.heavy_load_msg"," elif g.read_only_mode:"," infotext = strings.read_only_msg"," elif (c.firsttime == 'mobile_suggest' and"," c.render_style != 'compact'):"," infotext = strings.iphone_first"," elif g.announcement_message:"," infotext = g.announcement_message"," elif c.firsttime and c.site.firsttext:"," infotext = c.site.firsttext",""," if infotext:"," self.infobar = InfoBar(message = infotext)",""," self.srtopbar = None"," if srbar and not c.cname and not is_api():"," self.srtopbar = SubredditTopBar()",""," if c.user_is_loggedin and self.show_sidebar and not is_api():"," self._content = PaneStack([ShareLink(), content])"," else:"," self._content = content",""," self.toolbars = self.build_toolbars()"," "," def wiki_actions_menu(self, moderator=False):"," buttons = []"," "," buttons.append(NamedButton(\"wikirecentrevisions\", "," css_class=\"wikiaction-revisions\","," dest=\"/wiki/revisions\"))"," "," buttons.append(NamedButton(\"wikipageslist\", "," css_class=\"wikiaction-pages\","," dest=\"/wiki/pages\"))"," if moderator:"," buttons += [NamedButton('wikibanned', css_class='reddit-ban', "," dest='/about/wikibanned'),"," NamedButton('wikicontributors', "," css_class='reddit-contributors', "," dest='/about/wikicontributors')"," ]"," "," return SideContentBox(_('wiki tools'),"," [NavMenu(buttons,"," type=\"flat_vert\","," css_class=\"icon-menu\","," separator=\"\")],"," _id=\"wikiactions\","," collapsible=True)"," "," def sr_admin_menu(self):"," buttons = []"," is_single_subreddit = not isinstance(c.site, "," (models.ModSR, models.MultiReddit))",""," if is_single_subreddit:"," buttons.append(menus.NavButton(menu.community_settings,"," css_class=\"reddit-edit\","," dest=\"edit\"))",""," buttons.append(menus.NamedButton(\"modmail\","," dest=\"message/inbox\","," css_class=\"moderator-mail\"))",""," if is_single_subreddit:"," buttons.append(menus.NamedButton(\"moderators\","," css_class=\"reddit-moderators\"))",""," if c.site.type != \"public\":"," buttons.append(menus.NamedButton(\"contributors\","," css_class="," \"reddit-contributors\"))"," else:"," buttons.append(menus.NavButton(menu.contributors,"," \"contributors\","," css_class=\"reddit-contributors\"))",""," buttons.append(menus.NamedButton(\"traffic\","," css_class=\"reddit-traffic\"))",""," buttons += [menus.NamedButton(\"modqueue\", css_class=\"reddit-modqueue\"),"," menus.NamedButton(\"reports\", css_class=\"reddit-reported\"),"," menus.NamedButton(\"spam\", css_class=\"reddit-spam\")]",""," if is_single_subreddit:"," buttons += [menus.NamedButton(\"banned\", css_class=\"reddit-ban\"),"," menus.NamedButton(\"flair\", css_class=\"reddit-flair\")]",""," buttons += [menus.NamedButton(\"log\", css_class=\"reddit-moderationlog\"),"," menus.NamedButton(\"unmoderated\","," css_class=\"reddit-unmoderated\")]",""," return SideContentBox(_('moderation tools'),"," [menus.NavMenu(buttons,"," type=\"flat_vert\","," base_path=\"/about/\","," css_class=\"icon-menu\","," separator=\"\")],"," _id=\"moderation_tools\","," collapsible=True)",""," def sr_moderators(self, limit = 10):"," accounts = models.Account._byID([uid"," for uid in c.site.moderators[:limit]],"," data=True, return_dict=False)"," return [WrappedUser(a) for a in accounts if not a._deleted]",""," def rightbox(self):"," \"\"\"generates content in