mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-27 15:58:06 -05:00
wiki: Have a create page on page not found.
This commit is contained in:
@@ -196,7 +196,7 @@ def make_map():
|
||||
mc('/help/gold', controller='redirect', action='redirect', dest='/gold/about')
|
||||
mc('/help/*anything', controller='embed', action='help')
|
||||
|
||||
mc('/wiki/notfound/*page', controller='wiki', action='wiki_notfound')
|
||||
mc('/wiki/create/*page', controller='wiki', action='wiki_create')
|
||||
mc('/wiki/edit/*page', controller='wiki', action='wiki_revise')
|
||||
mc('/wiki/revisions/*page', controller='wiki', action='wiki_revisions')
|
||||
mc('/wiki/settings/*page', controller='wiki', action='wiki_settings')
|
||||
|
||||
@@ -43,7 +43,8 @@ from r2.controllers.validator.wiki import (VWikiPage, VWikiPageAndVersion,
|
||||
from r2.controllers.api_docs import api_doc, api_section
|
||||
from r2.lib.pages.wiki import (WikiPageView, WikiNotFound, WikiRevisions,
|
||||
WikiEdit, WikiSettings, WikiRecent,
|
||||
WikiListing, WikiDiscussions)
|
||||
WikiListing, WikiDiscussions,
|
||||
WikiCreate)
|
||||
|
||||
from r2.config.extensions import set_extension
|
||||
from r2.lib.template_helpers import add_sr
|
||||
@@ -86,8 +87,9 @@ class WikiController(RedditController):
|
||||
return self.redirect(url)
|
||||
|
||||
if not page:
|
||||
url = join_urls(c.wiki_base_url, '/notfound/', page_name[0])
|
||||
return self.redirect(url)
|
||||
if c.render_style in extensions.API_TYPES:
|
||||
self.handle_error(404, 'PAGE_NOT_CREATED')
|
||||
return WikiNotFound(page=page_name[0]).render()
|
||||
|
||||
if version:
|
||||
edit_by = version.get_author()
|
||||
@@ -130,7 +132,7 @@ class WikiController(RedditController):
|
||||
|
||||
@wiki_validate(wp=VWikiPageRevise('page'),
|
||||
page=VWikiPageName('page'))
|
||||
def GET_wiki_notfound(self, wp, page):
|
||||
def GET_wiki_create(self, wp, page):
|
||||
page = page[0]
|
||||
api = c.render_style in extensions.API_TYPES
|
||||
if wp[0]:
|
||||
@@ -150,13 +152,11 @@ class WikiController(RedditController):
|
||||
error = _('a max of %d separators "/" are allowed in a wiki page name.') % c.error['max_separators']
|
||||
return BoringPage(_("Wiki error"), infotext=error).render()
|
||||
else:
|
||||
return WikiNotFound(page=page, may_revise=True).render()
|
||||
return WikiCreate(page=page, may_revise=True).render()
|
||||
|
||||
@wiki_validate(wp=VWikiPageRevise('page', restricted=True))
|
||||
def GET_wiki_revise(self, wp, page, message=None, **kw):
|
||||
wp = wp[0]
|
||||
if not wp:
|
||||
return self.redirect(join_urls(c.wiki_base_url, '/notfound/', page))
|
||||
previous = kw.get('previous', wp._get('revision'))
|
||||
content = kw.get('content', wp.content)
|
||||
if not message and wp.name in page_descriptions:
|
||||
|
||||
@@ -16,6 +16,12 @@ class WikiView(Templated):
|
||||
self.base_url = c.wiki_base_url
|
||||
Templated.__init__(self)
|
||||
|
||||
class WikiPageNotFound(Templated):
|
||||
def __init__(self, page):
|
||||
self.page = page
|
||||
self.base_url = c.wiki_base_url
|
||||
Templated.__init__(self)
|
||||
|
||||
class WikiPageListing(Templated):
|
||||
def __init__(self, pages, linear_pages, page=None):
|
||||
self.pages = pages
|
||||
@@ -109,6 +115,13 @@ class WikiPageView(WikiBase):
|
||||
WikiBase.__init__(self, content, page=page, **context)
|
||||
|
||||
class WikiNotFound(WikiBase):
|
||||
def __init__(self, page, **context):
|
||||
content = WikiPageNotFound(page)
|
||||
context['alert'] = _("page %s does not exist in this subreddit") % page
|
||||
context['actionless'] = True
|
||||
WikiBase.__init__(self, content, page=page, **context)
|
||||
|
||||
class WikiCreate(WikiBase):
|
||||
def __init__(self, page, **context):
|
||||
context['alert'] = _("page %s does not exist in this subreddit") % page
|
||||
context['actionless'] = True
|
||||
|
||||
@@ -42,7 +42,7 @@ MAX_PAGE_LENGTH_BYTES = g.wiki_max_page_length_bytes
|
||||
|
||||
# Page names which should never be
|
||||
impossible_namespaces = ('edit/', 'revisions/', 'settings/', 'discussions/',
|
||||
'revisions/', 'pages/')
|
||||
'revisions/', 'pages/', 'create/')
|
||||
|
||||
# Namespaces in which access is denied to do anything but view
|
||||
restricted_namespaces = ('reddit/', 'config/', 'special/')
|
||||
|
||||
2
r2/r2/templates/wikipagenotfound.html
Normal file
2
r2/r2/templates/wikipagenotfound.html
Normal file
@@ -0,0 +1,2 @@
|
||||
${_('The page "%s" was not found in this subreddit.') % thing.page}<br/>
|
||||
<a href="${c.wiki_base_url}/create/${thing.page}">${_('Create page "%s"') % thing.page}
|
||||
Reference in New Issue
Block a user