def save_page(self, output): editor = PageEditor(self.macro.request, self.pagename) text = self.create_header() text += editor.normalizeText(output) dummy, revision, exists = editor.get_rev() try: res = editor.saveText(text, revision, comment="updated by MakeList macro.") return res except editor.Unchanged: return "You did not change the page content, not saved!" except: return "An error occured!"
def do_savepage(pagename, request): from MoinMoin.PageEditor import PageEditor _ = request.getText if not request.user.may.write(pagename): Page(request, pagename).send_page(request, msg = _('You are not allowed to edit this page.')) return pg = PageEditor(request, pagename) savetext = request.form.get('savetext', [u''])[0] rev = int(request.form.get('rev', ['0'])[0]) comment = request.form.get('comment', [u''])[0] category = request.form.get('category', [None])[0] rstrip = int(request.form.get('rstrip', ['0'])[0]) trivial = int(request.form.get('trivial', ['0'])[0]) # IMPORTANT: normalize text from the form. This should be done in # one place before we manipulate the text. savetext = pg.normalizeText(savetext, stripspaces=rstrip) # Add category # TODO: this code does not work with extended links, and is doing # things behind your back, and in general not needed. Either we have # a full interface for categories (add, delete) or just add them by # markup. if category: # strip trailing whitespace savetext = savetext.rstrip() # Add category separator if last non-empty line contains # non-categories. lines = filter(None, savetext.splitlines()) if lines: #TODO: this code is broken, will not work for extended links #categories, e.g ["category hebrew"] categories = lines[-1].split() if categories: confirmed = wikiutil.filterCategoryPages(request, categories) if len(confirmed) < len(categories): # This was not a categories line, add separator savetext += u'\n----\n' # Add new category if savetext and savetext[-1] != u'\n': savetext += ' ' savetext += category + u'\n' # Should end with newline! # Clean comment - replace CR, LF, TAB by whitespace, delete control chars # TODO: move this to config, create on first call then return cached. remap_chars = { ord(u'\t'): u' ', ord(u'\r'): u' ', ord(u'\n'): u' ', } control_chars = u'\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0b\x0c\x0e\x0f' \ '\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f' for c in control_chars: remap_chars[c] = None comment = comment.translate(remap_chars) # Preview, spellcheck or spellcheck add new words if (request.form.has_key('button_preview') or request.form.has_key('button_spellcheck') or request.form.has_key('button_newwords')): pg.sendEditor(preview=savetext, comment=comment) # Edit was canceled elif request.form.has_key('button_cancel'): pg.sendCancel(savetext, rev) # Save new text else: try: savemsg = pg.saveText(savetext, rev, trivial=trivial, comment=comment) except pg.EditConflict, msg: # Handle conflict and send editor # TODO: conflict messages are duplicated from PageEditor, # refactor to one place only. conflict_msg = _('Someone else changed this page while you were editing!') pg.set_raw_body(savetext, modified=1) if pg.mergeEditConflict(rev): conflict_msg = _("""Someone else saved this page while you were editing! Please review the page and save then. Do not save this page as it is! Have a look at the diff of %(difflink)s to see what has been changed.""") % { 'difflink': pg.link_to(pg.request, querystr='action=diff&rev=%d' % rev) } # We don't send preview when we do merge conflict pg.sendEditor(msg=conflict_msg, comment=comment) return else: savemsg = conflict_msg except pg.SaveError, msg: # msg contain a unicode string savemsg = unicode(msg)
# coding: utf-8 import py from MoinMoin import wikiutil from MoinMoin.PageEditor import PageEditor from MoinMoin.web.contexts import ScriptContext pagename = 'Class_%23AC0' req = ScriptContext('localhost:8080', pagename) editor = PageEditor(request, pagename) text = editor.normalizeText('''= #AC<sup>0</sup> = The class of functions from {0,1}<sup>n</sup> to nonnegative integers computed by polynomial-size constant-depth arithmetic circuits, using addition and multiplication gates and the constants 0 and 1. Contained in GapAC<sup>0</sup>.''') _, rev, _ = editor.get_rev() editor.saveText(text, rev)