def GET_wiki_create(self, may_create, page, view=False): api = c.extension == 'json' if c.error and c.error['reason'] == 'PAGE_EXISTS': return self.redirect(join_urls(c.wiki_base_url, page)) elif not may_create or api: if may_create and c.error: self.handle_error(403, **c.error) else: self.handle_error(404, 'PAGE_NOT_FOUND', may_create=may_create) elif c.error: error = '' if c.error['reason'] == 'PAGE_NAME_LENGTH': error = _( "this wiki cannot handle page names of that magnitude! please select a page name shorter than %d characters" ) % c.error['max_length'] elif c.error['reason'] == 'PAGE_CREATED_ELSEWHERE': error = _( "this page is a special page, please go into the subreddit settings and save the field once to create this special page" ) elif c.error['reason'] == 'PAGE_NAME_MAX_SEPARATORS': error = _( 'a max of %d separators "/" are allowed in a wiki page name.' ) % c.error['MAX_SEPARATORS'] return BoringPage(_("Wiki error"), infotext=error).render() elif view: return WikiNotFound().render() elif may_create: WikiPage.create(c.site, page) url = join_urls(c.wiki_base_url, '/edit/', page) return self.redirect(url)
def pre(self): RedditController.pre(self) if g.disable_wiki and not c.user_is_admin: self.handle_error(403, 'WIKI_DOWN') if not c.site._should_wiki: self.handle_error(404, 'NOT_WIKIABLE') # /r/mod for an example frontpage = c.site.is_homepage c.wiki_base_url = join_urls(c.site.path, 'wiki') c.wiki_api_url = join_urls(c.site.path, '/api/wiki') # CUSTOM if frontpage: c.wiki_base_url = join_urls('/', 'wiki') c.wiki_api_url = join_urls('/', '/api/wiki') c.wiki_id = g.default_sr if frontpage else c.site.name self.editconflict = False c.is_wiki_mod = (c.user_is_admin or c.site.is_moderator_with_perms( c.user, 'wiki')) if c.user_is_loggedin else False c.wikidisabled = False mode = c.site.wikimode if not mode or mode == 'disabled': if not c.is_wiki_mod: self.handle_error(403, 'WIKI_DISABLED') else: c.wikidisabled = True
def GET_wiki_create(self, may_create, page, view=False): api = c.extension == 'json' if c.error and c.error['reason'] == 'PAGE_EXISTS': return self.redirect(join_urls(c.wiki_base_url, page)) elif not may_create or api: if may_create and c.error: self.handle_error(403, **c.error) else: self.handle_error(404, 'PAGE_NOT_FOUND', may_create=may_create) elif c.error: error = '' if c.error['reason'] == 'PAGE_NAME_LENGTH': error = _("this wiki cannot handle page names of that magnitude! please select a page name shorter than %d characters") % c.error['max_length'] elif c.error['reason'] == 'PAGE_CREATED_ELSEWHERE': error = _("this page is a special page, please go into the subreddit settings and save the field once to create this special page") elif c.error['reason'] == 'PAGE_NAME_MAX_SEPARATORS': error = _('a max of %d separators "/" are allowed in a wiki page name.') % c.error['MAX_SEPARATORS'] return BoringPage(_("Wiki error"), infotext=error).render() elif view: return WikiNotFound().render() elif may_create: WikiPage.create(c.site, page) url = join_urls(c.wiki_base_url, '/edit/', page) return self.redirect(url)
def GET_wiki_create(self, wp, page): api = c.render_style in extensions.API_TYPES error = c.errors.get(('WIKI_CREATE_ERROR', 'page')) if error: error = error.msg_params if wp[0]: return self.redirect(join_urls(c.wiki_base_url, wp[0].name)) elif api: if error: self.handle_error(403, **error) else: self.handle_error(404, 'PAGE_NOT_CREATED') elif error: error_msg = '' if error['reason'] == 'PAGE_NAME_LENGTH': error_msg = _( "this wiki cannot handle page names of that magnitude! please select a page name shorter than %d characters" ) % error['max_length'] elif error['reason'] == 'PAGE_CREATED_ELSEWHERE': error_msg = _( "this page is a special page, please go into the subreddit settings and save the field once to create this special page" ) elif error['reason'] == 'PAGE_NAME_MAX_SEPARATORS': error_msg = _( 'a max of %d separators "/" are allowed in a wiki page name.' ) % error['max_separators'] return BoringPage(_("Wiki error"), infotext=error_msg).render() else: return WikiCreate(page=page, may_revise=True).render()
def GET_wiki_create(self, wp, page): api = c.render_style in extensions.API_TYPES error = c.errors.get(("WIKI_CREATE_ERROR", "page")) if error: error = error.msg_params if wp[0]: return self.redirect(join_urls(c.wiki_base_url, wp[0].name)) elif api: if error: self.handle_error(403, **error) else: self.handle_error(404, "PAGE_NOT_CREATED") elif error: error_msg = "" if error["reason"] == "PAGE_NAME_LENGTH": error_msg = ( _( "this wiki cannot handle page names of that magnitude! please select a page name shorter than %d characters" ) % error["max_length"] ) elif error["reason"] == "PAGE_CREATED_ELSEWHERE": error_msg = _( "this page is a special page, please go into the subreddit settings and save the field once to create this special page" ) elif error["reason"] == "PAGE_NAME_MAX_SEPARATORS": error_msg = _('a max of %d separators "/" are allowed in a wiki page name.') % error["max_separators"] return BoringPage(_("Wiki error"), infotext=error_msg).render() else: return WikiCreate(page=page, may_revise=True).render()
def GET_wiki_create(self, wp, page): api = c.render_style in extensions.API_TYPES error = c.errors.get(('WIKI_CREATE_ERROR', 'page')) if error: error = error.msg_params if wp[0]: VNotInTimeout().run(action_name="wikirevise", details_text="create", target=page) return self.redirect(join_urls(c.wiki_base_url, wp[0].name)) elif api: if error: self.handle_error(403, **error) else: self.handle_error(404, 'PAGE_NOT_CREATED') elif error: error_msg = '' if error['reason'] == 'PAGE_NAME_LENGTH': error_msg = _("this wiki cannot handle page names of that magnitude! please select a page name shorter than %d characters") % error['max_length'] elif error['reason'] == 'PAGE_CREATED_ELSEWHERE': error_msg = _("this page is a special page, please go into the subreddit settings and save the field once to create this special page") elif error['reason'] == 'PAGE_NAME_MAX_SEPARATORS': error_msg = _('a max of %d separators "/" are allowed in a wiki page name.') % error['max_separators'] return BoringPage(_("Wiki error"), infotext=error_msg).render() else: VNotInTimeout().run(action_name="wikirevise", details_text="create") return WikiCreate(page=page, may_revise=True).render()
def GET_wiki_page(self, pv, page_name): """Return the content of a wiki page If `v` is given, show the wiki page as it was at that version If both `v` and `v2` are given, show a diff of the two """ message = None if c.errors.get(('PAGE_NAME_NORMALIZED', 'page')): url = join_urls(c.wiki_base_url, page_name) return self.redirect(url) page, version, version2 = pv if not page: is_api = c.render_style in extensions.API_TYPES if this_may_revise(): if is_api: self.handle_error(404, 'PAGE_NOT_CREATED') errorpage = WikiNotFound(page=page_name) request.environ['usable_error_content'] = errorpage.render() elif is_api: self.handle_error(404, 'PAGE_NOT_FOUND') self.abort404() if version: edit_by = version.get_author() edit_date = version.date else: edit_by = page.get_author() edit_date = page._get('last_edit_date') diffcontent = None if not version: content = page.content if c.is_wiki_mod and page.name in page_descriptions: message = page_descriptions[page.name] else: message = _("viewing revision from %s") % timesince(version.date) if version2: t1 = timesince(version.date) t2 = timesince(version2.date) timestamp1 = _("%s ago") % t1 timestamp2 = _("%s ago") % t2 message = _("comparing revisions from %(date_1)s and %(date_2)s") \ % {'date_1': t1, 'date_2': t2} diffcontent = make_htmldiff(version.content, version2.content, timestamp1, timestamp2) content = version2.content else: message = _("viewing revision from %s ago") % timesince(version.date) content = version.content renderer = RENDERERS_BY_PAGE.get(page.name, 'wiki') return WikiPageView(content, alert=message, v=version, diff=diffcontent, may_revise=this_may_revise(page), edit_by=edit_by, edit_date=edit_date, page=page.name, renderer=renderer).render()
def GET_wiki_page(self, pv, page_name): message = None if c.errors.get(("PAGE_NAME_NORMALIZED", "page")): url = join_urls(c.wiki_base_url, page_name) return self.redirect(url) page, version, version2 = pv if not page: is_api = c.render_style in extensions.API_TYPES if this_may_revise(): if is_api: self.handle_error(404, "PAGE_NOT_CREATED") errorpage = WikiNotFound(page=page_name) request.environ["usable_error_content"] = errorpage.render() elif is_api: self.handle_error(404, "PAGE_NOT_FOUND") self.abort404() if version: edit_by = version.get_author() edit_date = version.date else: edit_by = page.get_author() edit_date = page._get("last_edit_date") diffcontent = None if not version: content = page.content if c.is_wiki_mod and page.name in page_descriptions: message = page_descriptions[page.name] else: message = _("viewing revision from %s") % timesince(version.date) if version2: t1 = timesince(version.date) t2 = timesince(version2.date) timestamp1 = _("%s ago") % t1 timestamp2 = _("%s ago") % t2 message = _("comparing revisions from %(date_1)s and %(date_2)s") % {"date_1": t1, "date_2": t2} diffcontent = make_htmldiff(version.content, version2.content, timestamp1, timestamp2) content = version2.content else: message = _("viewing revision from %s ago") % timesince(version.date) content = version.content renderer = RENDERERS_BY_PAGE.get(page.name, "wiki") return WikiPageView( content, alert=message, v=version, diff=diffcontent, may_revise=this_may_revise(page), edit_by=edit_by, edit_date=edit_date, page=page.name, renderer=renderer, ).render()
def pre(self): RedditController.pre(self) if g.disable_wiki and not c.user_is_admin: self.handle_error(403, 'WIKI_DOWN') if not c.site._should_wiki: self.handle_error(404, 'NOT_WIKIABLE') # /r/mod for an example frontpage = isinstance(c.site, DefaultSR) c.wiki_base_url = join_urls(c.site.path, 'wiki') c.wiki_api_url = join_urls(c.site.path, '/api/wiki') c.wiki_id = g.default_sr if frontpage else c.site.name self.editconflict = False c.is_wiki_mod = (c.user_is_admin or c.site.is_moderator(c.user)) if c.user_is_loggedin else False c.wikidisabled = False mode = c.site.wikimode if not mode or mode == 'disabled': if not c.is_wiki_mod: self.handle_error(403, 'WIKI_DISABLED') else: c.wikidisabled = True
def GET_landing(self, eligible, organization): if not feature.is_enabled('reddit_donate'): return self.abort404() if c.user_is_loggedin: nomination_count = DonationNominationsByAccount.count(c.user) else: nomination_count = None if organization: wrapped_organization = inject_nomination_status([organization]) else: wrapped_organization = None content = pages.DonateLanding( eligible=eligible, ) og_data = { "site_name": "reddit.com", } if organization: og_data["title"] = "reddit donate: vote for %s" % organization.data["DisplayName"] og_data["url"] = join_urls(g.origin, "donate?organization=%s" % organization.data["EIN"]) else: og_data["title"] = "reddit donate: giving 10% back" og_data["url"] = join_urls(g.origin, "donate") return pages.DonatePage( title=_("reddit donate"), content=content, og_data=og_data, extra_js_config={ "unloadedNominations": nomination_count, "accountIsEligible": eligible, "organization": wrapped_organization, }, ).render()
def GET_landing(self, eligible, organization): if not feature.is_enabled('reddit_donate'): return self.abort404() if c.user_is_loggedin: nomination_count = DonationNominationsByAccount.count(c.user) else: nomination_count = None if organization: wrapped_organization = inject_nomination_status([organization]) else: wrapped_organization = None content = pages.DonateLanding(eligible=eligible, ) og_data = { "site_name": "reddit.com", } if organization: og_data[ "title"] = "reddit donate: vote for %s" % organization.data[ "DisplayName"] og_data["url"] = join_urls( g.origin, "donate?organization=%s" % organization.data["EIN"]) else: og_data["title"] = "reddit donate: giving 10% back" og_data["url"] = join_urls(g.origin, "donate") return pages.DonatePage( title=_("reddit donate"), content=content, og_data=og_data, extra_js_config={ "unloadedNominations": nomination_count, "accountIsEligible": eligible, "organization": wrapped_organization, }, ).render()
def GET_wiki_page(self, pv, page_name): message = None if c.errors.get(('PAGE_NAME_NORMALIZED', 'page')): url = join_urls(c.wiki_base_url, page_name) return self.redirect(url) page, version, version2 = pv if not page: if c.render_style in extensions.API_TYPES: self.handle_error(404, 'PAGE_NOT_CREATED') return WikiNotFound(page=page_name).render() if version: edit_by = version.get_author() edit_date = version.date else: edit_by = page.get_author() edit_date = page._get('last_edit_date') diffcontent = None if not version: content = page.content if c.is_wiki_mod and page.name in page_descriptions: message = page_descriptions[page.name] else: message = _("viewing revision from %s") % timesince(version.date) if version2: t1 = timesince(version.date) t2 = timesince(version2.date) timestamp1 = _("%s ago") % t1 timestamp2 = _("%s ago") % t2 message = _("comparing revisions from %(date_1)s and %(date_2)s") \ % {'date_1': t1, 'date_2': t2} diffcontent = make_htmldiff(version.content, version2.content, timestamp1, timestamp2) content = version2.content else: message = _("viewing revision from %s ago") % timesince(version.date) content = version.content return WikiPageView(content, alert=message, v=version, diff=diffcontent, may_revise=this_may_revise(page), edit_by=edit_by, edit_date=edit_date, page=page.name).render()