def POST_undelete(self, page_name=''): page = db.get_page(page_name) if not page: return web.badrequest() db.undelete_page(page.id, page_name) latest = db.get_revision(page.id) deleted_rev = db.get_revision(page.id, latest.revision - 1) db.new_revision(page.id, latest.revision + 1, deleted_rev.content, '<em>Delete undone.</em>') web.seeother(page.url)
def POST_recover_live_version(self): i = web.input('page_name') page = db.get_page(i.page_name) if page: rev = db.get_revision(page.id) db.delete_draft(page.id) serialize_json(content=rev.content)
def POST_edit(self, page_name=''): i = web.input('spinner', recaptcha=False) spinner, recaptcha_p = i.spinner, i.recaptcha error_to_use = None if recaptcha_p: c = recaptcha.submit(i.recaptcha_challenge_field, i.recaptcha_response_field, os.environ['RECAPTCHA_PRIVKEY'], web.ctx.ip) if not c.is_valid: error_to_use = c.error_code i = auth.unspuninput(page_name, 'content', 'scroll_pos', 'caret_pos', 'current_revision', save=False, delete=False) page = db.get_page(page_name) content = re.sub(r'(\r\n|\r)', '\n', i.content) if (jt.site.security == 'open' and not auth.logged_in()) and (not recaptcha_p or error_to_use): captcha = recaptcha.displayhtml(os.environ['RECAPTCHA_PUBKEY'], use_ssl=True, error=error_to_use) timestamp, spinner, spinfield = auth.spinner(page_name) return render('captcha', vars=locals()) if not page: db.new_page(page_name, content, i.scroll_pos, i.caret_pos) page = db.get_page(page_name) revision = db.get_revision(page.id) if i.current_revision and revision.revision != int( i.current_revision ) and not page.deleted and revision.content != content: timestamp, spinner, spinfield = auth.spinner(page_name) orig = db.get_revision(page.id, i.current_revision) diff = better_diff(orig.content, content) return render('edit_conflict', vars=locals()) if i.delete and page_name: db.delete_page(page.id) return web.seeother(page.url) db.update_page(page.id, content, i.scroll_pos, i.caret_pos) if page.deleted: db.undelete_page(page.id, page_name) web.seeother(page.url)
def POST_datestr(self, page_name=''): page = db.get_page(page_name) if not page: return web.badrequest() revision = db.get_revision(page.id) d = datestr(revision.created) serialize_json(datestr=d)
def POST_revert(self, page_name=''): page = db.get_page(page_name) if not page: return web.badrequest() i = web.input('r') revert_to = db.get_revision(page.id, i.r) if not revert_to: return web.badrequest() if page.deleted: db.undelete_page(page.id, page_name) latest = db.get_revision(page.id) if latest.content != revert_to.content: db.update_page(page.id, revert_to.content) web.seeother(page.url)
def GET_edit(self, page_name=''): page = db.get_page(page_name) timestamp, spinner, spinfield = auth.spinner(page_name) if page: revision = db.get_revision(page.id) draft = db.get_draft(page.id) content = (draft and draft.content) or revision.content render('edit_page', vars=locals())
def GET_diff(self, page_name=''): page = db.get_page(page_name) if not page: return web.seeother('/') i = web.input(r=[]) if len(i.r) == 0: ia = db.get_num_revisions(page_name) ib = max(ia - 1, 1) elif len(i.r) == 1: ia = int(i.r[0]) if ia == 1: ib = 1 else: ib = ia - 1 elif len(i.r) == 2: ia, ib = i.r try: ia, ib = int(ia), int(ib) except ValueError: return web.badrequest() else: return web.badrequest() if ia > ib: # get ordering right ib, ia = ia, ib a = db.get_revision(page.id, ia) b = db.get_revision(page.id, ib) if not a or not b: return web.badrequest() nextrev, prevrev = '', '' # jinja doesn't like None if ia > 1: prevrev = str(ia - 1) if db.get_revision(page.id, ib + 1): nextrev = str(ib + 1) diff = better_diff(a.content, b.content) revisions = list(db.get_revisions(page.id)) render('diff', vars=locals())
def GET_view(self, page_name=''): i = web.input(r='') page = db.get_page(page_name) if not page: web.ctx.status = '404 Not Found' return render('notfound', vars=locals()) if page.deleted and not i.r: return render('deleted', vars=locals()) if i.r: revision = db.get_revision(page.id, i.r) revisions = list(db.get_revisions(page.id)) latest = revisions[0] else: latest = revision = db.get_revision(page.id) if not revision: return web.badrequest() success = web.cookies(success=None).success web.setcookie('success', '', expires=-1) render('view_page', vars=locals())
def GET_history(self, page_name=''): page = db.get_page(page_name) max_revision = db.get_max_revisions(page.id) if not (page and max_revision): return web.seeother(jt.site.url + page_name) try: start = int(web.input(start=0).start) except: start = 0 revisions = list(db.get_revisions(page.id, start=max_revision - start)) pagination_end = min(11 + start / 10, int(math.ceil((max_revision + 10) / 10.0))) pagination_start = (pagination_end < 21 and 1 or pagination_end - 20) latest = db.get_revision(page.id) render('history', vars=locals())
def POST_current_revision(self, page_name=''): page = db.get_page(page_name) if page: revision = db.get_revision(page.id) serialize_json(revision=revision.revision)