Skip to content

Commit

Permalink
wiki: Assume force if previous value is None.
Browse files Browse the repository at this point in the history
This allows clients that don't send the previous IDs to skip conflict detection and update the wikified text fields.
This allows for backwards compatibility, as well as making stylesheet updating not require an extra lookup.
  • Loading branch information
andre-d committed Sep 28, 2012
1 parent c0ceeda commit bc91f31
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
22 changes: 15 additions & 7 deletions r2/r2/controllers/api.py
Expand Up @@ -1227,7 +1227,12 @@ def POST_subreddit_stylesheet(self, form, jquery,
stylesheet_contents = '', prevstyle='', op='save'): stylesheet_contents = '', prevstyle='', op='save'):


report, parsed = c.site.parse_css(stylesheet_contents) report, parsed = c.site.parse_css(stylesheet_contents)


# Use the raw POST value as we need to tell the difference between
# None/Undefined and an empty string. The validators use a default
# value with both of those cases and would need to be changed.
# In order to avoid breaking functionality, this was done instead.
prevstyle = request.post.get('prevstyle')
if not report: if not report:
return self.abort(403,'forbidden') return self.abort(403,'forbidden')


Expand Down Expand Up @@ -1502,17 +1507,20 @@ def apply_wikid_field(sr, form, pagename, value, prev, field, error):
redir = False redir = False
kw = dict((k, v) for k, v in kw.iteritems() kw = dict((k, v) for k, v in kw.iteritems()
if k in ('name', 'title', 'domain', 'description', if k in ('name', 'title', 'domain', 'description',
'prev_description_id', 'prev_public_description_id',
'show_media', 'show_cname_sidebar', 'type', 'link_type', 'lang', 'show_media', 'show_cname_sidebar', 'type', 'link_type', 'lang',
'css_on_cname', 'header_title', 'over_18', 'css_on_cname', 'header_title', 'over_18',
'wikimode', 'wiki_edit_karma', 'wiki_edit_age', 'wikimode', 'wiki_edit_karma', 'wiki_edit_age',
'allow_top', 'public_description')) 'allow_top', 'public_description'))


description = kw.pop('description')
prev_desc = kw.pop('prev_description_id')

public_description = kw.pop('public_description') public_description = kw.pop('public_description')
prev_pubdesc = kw.pop('prev_public_description_id') description = kw.pop('description')

# Use the raw POST value as we need to tell the difference between
# None/Undefined and an empty string. The validators use a default
# value with both of those cases and would need to be changed.
# In order to avoid breaking functionality, this was done instead.
prev_desc = request.post.get('prev_description_id')
prev_pubdesc = request.post.get('prev_public_description_id')


def update_wiki_text(sr): def update_wiki_text(sr):
apply_wikid_field(sr, apply_wikid_field(sr,
Expand Down
6 changes: 5 additions & 1 deletion r2/r2/controllers/wiki.py
Expand Up @@ -235,7 +235,11 @@ class WikiApiController(WikiController):
content=VMarkdown(('content'))) content=VMarkdown(('content')))
def POST_wiki_edit(self, pageandprevious, content): def POST_wiki_edit(self, pageandprevious, content):
page, previous = pageandprevious page, previous = pageandprevious
previous = previous._id if previous else None # Use the raw POST value as we need to tell the difference between
# None/Undefined and an empty string. The validators use a default
# value with both of those cases and would need to be changed.
# In order to avoid breaking functionality, this was done instead.
previous = previous._id if previous else request.post.get('previous')
try: try:
if page.name == 'config/stylesheet': if page.name == 'config/stylesheet':
report, parsed = c.site.parse_css(content, verify=False) report, parsed = c.site.parse_css(content, verify=False)
Expand Down
1 change: 1 addition & 0 deletions r2/r2/models/wiki.py
Expand Up @@ -272,6 +272,7 @@ def has_editor(self, editor):
def revise(self, content, previous = None, author=None, force=False, reason=None): def revise(self, content, previous = None, author=None, force=False, reason=None):
if self.content == content: if self.content == content:
return return
force = True if previous is None else force
max_length = special_length_restrictions_bytes.get(self.name, MAX_PAGE_LENGTH_BYTES) max_length = special_length_restrictions_bytes.get(self.name, MAX_PAGE_LENGTH_BYTES)
if len(content) > max_length: if len(content) > max_length:
raise ContentLengthError(max_length) raise ContentLengthError(max_length)
Expand Down

0 comments on commit bc91f31

Please sign in to comment.