'Edit the body text of a comment or self-post.'

@require_oauth2_scope('edit')
@validatedForm(VUser(), VModhash(), item=VByNameIfAuthor('thing_id'), text=VMarkdown('text'))
@api_doc(api_section.links_and_comments)
def POST_editusertext(self, form, jquery, item, text):

    if (form.has_errors('text', errors.NO_TEXT) or form.has_errors('thing_id', errors.NOT_AUTHOR)):
        return
    if (isinstance(item, Link) and (not item.is_self)):
        return abort(403, 'forbidden')
    if getattr(item, 'admin_takedown', False):
        return abort(403, 'this    content    is    locked    and    can    not    be    edited')
    if isinstance(item, Comment):
        max_length = 10000
        admin_override = False
    else:
        max_length = Link.SELFTEXT_MAX_LENGTH
        admin_override = c.user_is_admin
    if ((not admin_override) and (len(text) > max_length)):
        c.errors.add(errors.TOO_LONG, field='text', msg_params={'max_length': max_length})
        form.set_error(errors.TOO_LONG, 'text')
        return
    removed_mentions = None
    original_text = item.body
    if isinstance(item, Comment):
        kind = 'comment'
        prev_mentions = extract_user_mentions(original_text)
        new_mentions = extract_user_mentions(text)
        removed_mentions = (prev_mentions - new_mentions)
        item.body = text
    elif isinstance(item, Link):
        kind = 'link'
        if (not getattr(item, 'is_self', False)):
            return abort(403, 'forbidden')
        item.selftext = text
    else:
        g.log.warning('%s    tried    to    edit    usertext    on    %r', c.user, item)
        return
    if item._deleted:
        return abort(403, 'forbidden')
    if ((item._age > timedelta(minutes=3)) or (item.num_votes > 2)):
        item.editted = c.start_time
    item.ignore_reports = False
    item._commit()
    if hasattr(item, 'editted'):
        queries.edit(item)
    item.update_search_index()
    amqp.add_item(('%s_text_edited' % kind), item._fullname)
    hooks.get_hook('thing.edit').call(thing=item, original_text=original_text)
    if removed_mentions:
        queries.unnotify(item, list(Account._names_to_ids(removed_mentions, ignore_missing=True)))
    wrapper = default_thing_wrapper(expand_children=True)
    jquery('body>div.content').replace_things(item, True, True, wrap=wrapper)
    jquery('body>div.content    .link    .rank').hide()
