Permalink
Browse files

wiki: Have a create page on page not found.

  • Loading branch information...
1 parent 4061bdd commit 387cecccd0a5f5008631f038d57df04182351026 @andre-d andre-d committed with spladug Oct 23, 2012
View
@@ -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')
View
@@ -43,7 +43,8 @@
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 @@ def GET_wiki_page(self, pv, page_name):
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 @@ def GET_wiki_revisions(self, num, after, reverse, count, page):
@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 @@ def GET_wiki_notfound(self, wp, page):
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:
View
@@ -16,6 +16,12 @@ def __init__(self, content, edit_by, edit_date, may_revise=False, page=None, dif
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
@@ -110,6 +116,13 @@ def __init__(self, content, page, diff=None, **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
content = WikiEditPage(show_reason_field=False, page=page)
View
@@ -42,7 +42,7 @@
# 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/')
@@ -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}

0 comments on commit 387cecc

Please sign in to comment.