Ejemplo n.º 1
0
    def cmd_commit(self, ri):
        form = ri.form

        if ri.is_spam:
            return self.text_wrapper(text_access_denied)
        if not config.EDITABLE or self.wikifile.path in page.locked_pages:
            return self.renderer_wrapper(views.locked_body())

        base_rev = form.get("base_rev", type=int)
        if not (base_rev <= self.head.revno) and base_rev > 0:
            raise exceptions.BadRequest()

        paraedit = self._get_paraedit(ri.form)

        wiki_text = unescape(form.get("text", "")).replace("\r\n", "\n")
        commitmsg_text = unescape(form.get("commitmsg", ""))
        ispreview = form.has_key("preview")

        wiki_src_full = wiki_text
        if paraedit:
            wiki_src_full = self.wikifile.get_paraedit_applied_data(paraedit[0], paraedit[1], wiki_text)
        # wiki_src_full = wiki2html.pre_convert_wiki(wiki_src_full)

        base_page = self.wikifile.switch_rev(base_rev)
        full_merged, merged, message = models.merge_with_latest(self.wikifile, base_page, wiki_src_full)

        if merged or ispreview or (not ri.is_valid_host):
            if paraedit and not merged:
                edit_src = wiki_text
            else:
                edit_src = full_merged
                paraedit = None

            preview_text = self.wikifile.get_preview_xhtml(edit_src)

            return self.renderer_wrapper(
                views.edit_body(preview_text, edit_src, commitmsg_text, message, paraedit, not ri.is_valid_host)
            )
        else:
            r = self.wikifile.write_text(full_merged, ri.user, commitmsg_text)
            return self.renderer_wrapper(views.commited_body(not not r, base_rev=self.head.revno, commited_rev=r))
Ejemplo n.º 2
0
    def cmd_comment(self, ri):
        form = ri.form
        if not self.wikifile.exist:
            raise exceptions.NotFound()

        if ri.is_spam or not config.EDITABLE:
            return self.text_wrapper(text_access_denied)

        author = unescape(form.get("author", "AnonymousCorward")).strip()
        message = unescape(form.get("message", "")).strip()
        comment_no = form.get("comment_no", type=int)

        if (not ri.is_valid_host) or (not message):
            return self.renderer_wrapper(views.edit_comment_body(comment_no, author, message, "", not ri.is_valid_host))

        r = self.wikifile.insert_comment(
            self.head.revno, ri.user, "comment by %s" % (author), comment_no, author, message
        )
        success = not not r

        return self.renderer_wrapper(views.commited_body(success, base_rev=self.head.revno, commited_rev=r))