Permalink
Browse files

wiki: Rework page name validator.

  • Loading branch information...
1 parent 94fd776 commit 3d069bea0b7e3490fa80932d5c1f3c625f9953e7 @andre-d andre-d committed with spladug Nov 26, 2012
Showing with 16 additions and 11 deletions.
  1. +9 −4 r2/r2/controllers/validator/wiki.py
  2. +7 −7 r2/r2/controllers/wiki.py
@@ -185,6 +185,10 @@ def __init__(self, fatal=False, *a, **kw):
VSrModerator.__init__(self, fatal=fatal, *a, **kw)
class VWikiPageName(Validator):
+ def __init__(self, param, error_on_different=False, *a, **kw):
+ self.error_on_different = error_on_different
+ Validator.__init__(self, param, *a, **kw)
+
def run(self, page):
original_page = page
if not page:
@@ -207,7 +211,10 @@ def run(self, page):
if WikiPage.is_impossible(page):
return self.set_error('INVALID_PAGE_NAME', code=400)
- return (page, page != original_page)
+ if self.error_on_different and page != original_page:
+ self.set_error('PAGE_NAME_MOVED')
+
+ return page
class VWikiPage(VWikiPageName):
def __init__(self, param, required=True, restricted=True, modonly=False,
@@ -216,16 +223,14 @@ def __init__(self, param, required=True, restricted=True, modonly=False,
self.modonly = modonly
self.allow_hidden_revision = allow_hidden_revision
self.required = required
- Validator.__init__(self, param, **kw)
+ VWikiPageName.__init__(self, param, **kw)
def run(self, page):
page = VWikiPageName.run(self, page)
if self.has_errors:
return
- page = page[0]
-
if (not c.is_wiki_mod) and self.modonly:
return self.set_error('MOD_REQUIRED', code=403)
@@ -77,19 +77,20 @@ class WikiController(RedditController):
@wiki_validate(pv=VWikiPageAndVersion(('page', 'v', 'v2'), required=False,
restricted=False, allow_hidden_revision=False),
- page_name=VWikiPageName('page'))
+ page_name=VWikiPageName(('page'), error_on_different=True))
def GET_wiki_page(self, pv, page_name):
- page, version, version2 = pv
message = None
- if page_name[1]:
- url = join_urls(c.wiki_base_url, page_name[0])
+ if c.errors.get(('PAGE_NAME_MOVED', '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[0]).render()
+ return WikiNotFound(page=page_name).render()
if version:
edit_by = version.get_author()
@@ -133,7 +134,6 @@ def GET_wiki_revisions(self, num, after, reverse, count, page):
@wiki_validate(wp=VWikiPageRevise('page'),
page=VWikiPageName('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:
@@ -260,7 +260,7 @@ def POST_wiki_edit(self, pageandprevious, content, page_name, reason):
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])
+ page = WikiPage.create(c.site, page_name)
if c.user._spam:
error =_("You are doing that too much, please try again later.")
self.handle_error(415, 'SPECIAL_ERRORS', special_errors=[error])

0 comments on commit 3d069be

Please sign in to comment.