'Update the permissions and visibility of wiki `page`'

@require_oauth2_scope('modwiki')
@api_doc(api_section.wiki, uri='/wiki/settings/{page}', uses_site=True)
@validate(VModhash(), page=VWikiPage('page', restricted=True, modonly=True), permlevel=VInt('permlevel'), listed=VBoolean('listed'))
def POST_wiki_settings(self, page, permlevel, listed):

    oldpermlevel = page.permlevel
    if (oldpermlevel != permlevel):
        VNotInTimeout().run(action_name='wikipermlevel', details_text='edit', target=page)
    if (page.listed != listed):
        VNotInTimeout().run(action_name='wikipagelisted', details_text='edit', target=page)
    try:
        page.change_permlevel(permlevel)
    except ValueError:
        self.handle_error(403, 'INVALID_PERMLEVEL')
    if (page.listed != listed):
        page.listed = listed
        page._commit()
        verb = ('Relisted' if listed else 'Delisted')
        description = ('%s    page    %s' % (verb, page.name))
        ModAction.create(c.site, c.user, 'wikipagelisted', description=description)
    if (oldpermlevel != permlevel):
        description = ('Page:    %s,    Changed    from    %s    to    %s' % (page.name, oldpermlevel, permlevel))
        ModAction.create(c.site, c.user, 'wikipermlevel', description=description)
    return self.GET_wiki_settings(page=page.name)
