Permalink
Browse files

wiki: Handle wiki create errors with set_error.

  • Loading branch information...
1 parent 9341181 commit 23fdb0e225f9dc596acae7da9a79fbc13cbadf39 @andre-d andre-d committed with spladug Oct 23, 2012
Showing with 21 additions and 14 deletions.
  1. +4 −1 r2/r2/controllers/validator/wiki.py
  2. +17 −13 r2/r2/controllers/wiki.py
@@ -305,7 +305,10 @@ def run(self, page, previous=None):
return self.set_error('PAGE_NOT_FOUND', code=404)
return self.set_error('MAY_NOT_REVISE', code=403)
if not wp:
- c.error = self.may_not_create(page)
+ # No abort code on purpose, controller will handle
+ error = self.may_not_create(page)
+ if error:
+ self.set_error('WIKI_CREATE_ERROR', msg_params=error)
return (None, None)
if previous:
try:
View
@@ -135,22 +135,25 @@ def GET_wiki_revisions(self, num, after, reverse, count, page):
def GET_wiki_create(self, wp, page):
page = page[0]
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 c.error:
- self.handle_error(403, **c.error)
+ if error:
+ self.handle_error(403, **error)
else:
self.handle_error(404, 'PAGE_NOT_CREATED')
- 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 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()
@@ -254,8 +257,9 @@ def POST_wiki_edit(self, pageandprevious, content, page_name, reason):
page, previous = pageandprevious
if not page:
- if c.error:
- self.handle_error(403, **c.error)
+ error = c.errors.get(('WIKI_CREATE_ERROR', 'page'))
+ if error:
+ self.handle_error(403, **(error.msg_params or {}))
page = WikiPage.create(c.site, page_name[0])
# Use the raw POST value as we need to tell the difference between

0 comments on commit 23fdb0e

Please sign in to comment.