本文整理汇总了Python中MoinMoin.PageEditor.PageEditor.get_raw_body方法的典型用法代码示例。如果您正苦于以下问题:Python PageEditor.get_raw_body方法的具体用法?Python PageEditor.get_raw_body怎么用?Python PageEditor.get_raw_body使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MoinMoin.PageEditor.PageEditor
的用法示例。
在下文中一共展示了PageEditor.get_raw_body方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: group_del
# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import get_raw_body [as 别名]
def group_del(request, grouppage, accounts):
_ = request.getText
success, msg = check_grouppage(request, grouppage)
if not success:
raise GroupException(msg + "(%s)" % (grouppage))
members = request.groups[grouppage].members | request.groups[grouppage].member_groups
for name in accounts:
if name not in members:
raise GroupException(name + _(' not in group: ') + grouppage)
page = PageEditor(request, grouppage)
pagetext = page.get_raw_body()
newtext = _group_del(request, pagetext, accounts)
msg = page.saveText(newtext, 0,
comment="Deleted from group: " +
', '.join(accounts))
newmembers = request.groups[grouppage].members | request.groups[grouppage].member_groups
if not newmembers == members - set(accounts):
msg = page.saveText(pagetext, 0,
comment="Reverting due to problems in group operation.")
raise GroupException(_('Delete unsuccessful for unknown reasons.'))
return True, msg
示例2: execute
# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import get_raw_body [as 别名]
def execute(pagename, request):
form = values_to_form(request.values)
template = form.get('template', [''])[0]
if template and not request.page.exists():
template_page = wikiutil.unquoteWikiname(template)
if request.user.may.read(template_page):
editor = PageEditor(request, template_page)
editor.user = request.user
text = editor.get_raw_body()
editor.page_name = pagename
request.page.set_raw_body(editor._expand_variables(text))
newdata = parse_text(request, request.page,
request.page.get_raw_body())
# Add prototype metas (^ something::\s*$) as keys
protokeys = [y for x,y in dl_proto_re.findall(text)]
for key in protokeys:
if not (key in newdata[pagename].get('out', dict()) or
key in newdata[pagename].get('meta', dict())):
newdata[pagename].setdefault('meta', dict())[key] = list()
# I'll lie, cheat, do anything to make this work
newdata[pagename]['saved'] = True
# Add the template metas to cache so that they'd show
request.graphdata.cacheset(pagename, newdata.get(pagename, dict()))
MetaEdit.execute(pagename, request)
示例3: deletecomment
# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import get_raw_body [as 别名]
def deletecomment(macro, delkey, delpasswd):
# Deletes a comment with given index and password
request = Globs.macro.request
formatter = Globs.macro.formatter
datapagename = Globs.datapagename
_ = request.getText
if Params.encryptpass:
from MoinMoin import user
delpasswd = user.encodePassword(delpasswd)
pg = PageEditor( request, datapagename )
pagetext = pg.get_raw_body()
regex = ur"""
(?P<comblock>
^[\{]{3}\n
^(?P<icon>[^\n]*)\n
^(?P<name>[^\n]*)\n
^(?P<date>[^\n]*)[\n]+
^(?P<text>
\s*.*?
(?=[\}]{3})
)[\}]{3}[\n]*
^[#]{2}PASSWORD[ ](?P<passwd>[^\n]*)[\n]*
^[#]{2}LOGINUSER[ ](?P<loginuser>[^\n]*)[\n$]*
)"""
pattern = re.compile(regex, re.UNICODE + re.MULTILINE + re.VERBOSE + re.DOTALL)
commentitems = pattern.findall(pagetext)
for item in commentitems:
if delkey == item[3].strip():
comauthor = item[2]
if Globs.admin or (request.user.valid and request.user.name == comauthor) or delpasswd == item[5]:
newpagetext = pagetext.replace(item[0], '', 1)
action = 'SAVE'
comment = 'Deleted comment by "%s"' % comauthor
trivial = 1
pg._write_file(newpagetext, action, u'PageComment modification at %s' % Globs.curpagename)
addLogEntry(request, 'COMDEL', Globs.curpagename, comment)
msg = _('The comment is deleted.')
# send notification mails
if Params.notify:
msg = msg + commentNotify(comment, trivial)
message(msg)
return
else:
message(_('Sorry, wrong password.'))
return
message(_('No such comment'))
示例4: _remove_user_from_team
# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import get_raw_body [as 别名]
def _remove_user_from_team(u, team, cfg):
acl_request = u._request
acl_request.user = user.User(acl_request, None, cfg.openidrp_acl_admin)
pe = PageEditor(acl_request, team + cfg.openidrp_acl_page_postfix)
acl_text = pe.get_raw_body()
logging.log(logging.INFO, "ACL Page content: " + acl_text)
# does ACL want uid, name, username, auth_username?
p = re.compile(ur"^ \* %s" % u.name, re.MULTILINE)
if p.search(acl_text):
logging.log(logging.INFO, "found user %s in acl, removing..." % u.name)
acl_text = acl_text.replace(" * %s\n" % u.name, "")
try:
pe.saveText(acl_text, 0)
except PageEditor.EmptyPage:
pe.deletePage()
示例5: edit_meta
# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import get_raw_body [as 别名]
def edit_meta(request, pagename, oldmeta, newmeta):
page = PageEditor(request, pagename)
text = page.get_raw_body()
text = replace_metas(request, text, oldmeta, newmeta)
# PageEditor.saveText doesn't allow empty texts
if not text:
text = u" "
try:
msg = page.saveText(text, 0)
except page.Unchanged:
msg = u'Unchanged'
return msg
示例6: _addLocalWords
# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import get_raw_body [as 别名]
def _addLocalWords(request):
from MoinMoin.PageEditor import PageEditor
# get the new words as a string (if any are marked at all)
try:
newwords = request.form.getlist('newwords')
except KeyError:
# no new words checked
return
newwords = u' '.join(newwords)
# get the page contents
lsw_page = PageEditor(request, request.cfg.page_local_spelling_words)
words = lsw_page.get_raw_body()
# add the words to the page and save it
if words and words[-1] != '\n':
words = words + '\n'
lsw_page.saveText(words + '\n' + newwords, 0)
示例7: _add_user_to_team
# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import get_raw_body [as 别名]
def _add_user_to_team(u, team, cfg):
# use admin account to create or edit ACL page
# http://moinmo.in/MoinDev/CommonTasks
acl_request = u._request
acl_request.user = user.User(acl_request, None, cfg.openidrp_acl_admin)
pe = PageEditor(acl_request, team + cfg.openidrp_acl_page_postfix)
acl_text = pe.get_raw_body()
logging.log(logging.INFO, "ACL Page content: " + acl_text)
# make sure acl command is first line of document
# only the admin user specified in wikiconfig should
# be allowed to change these acl files
if not acl_text or acl_text == "" or acl_text[0] != "#":
acl_text = "#acl Known:read All:\n" + acl_text
# does ACL want uid, name, username, auth_username?
p = re.compile(ur"^ \* %s" % u.name, re.MULTILINE)
if not p.search(acl_text):
logging.log(logging.INFO, "did not find user %s in acl, adding..." % u.name)
acl_text += u" * %s\n" % u.name
pe.saveText(acl_text, 0)
示例8: group_rename
# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import get_raw_body [as 别名]
def group_rename(request, grouppage, accounts):
_ = request.getText
success, msg = check_grouppage(request, grouppage)
if not success:
raise GroupException(msg + "(%s)" % (grouppage))
check_users(request, accounts[::2])
if len(accounts) % 2:
raise ValueError(_('Wrong number of arguments for rename.'))
page = PageEditor(request, grouppage)
if page.exists():
members = request.groups[grouppage].members
else:
raise GroupException(_('Group does not exist: ') + grouppage)
for uname in accounts[::2]:
if uname not in members:
raise GroupException(_('User not in group: ') + uname)
page = PageEditor(request, grouppage)
pagetext = page.get_raw_body()
newtext = _group_rename(request, pagetext, accounts)
msg = page.saveText(newtext, 0,
comment="Changed group members: " +
' -> '.join(accounts))
newmembers = request.groups[grouppage].members
testmembers = members.copy()
for user1, user2 in zip(accounts[::2], accounts[1::2]):
testmembers.remove(user1)
testmembers.add(user2)
if testmembers != newmembers:
msg = page.saveText(pagetext, 0,
comment="Reverting due to problems in group operation.")
raise GroupException(_('Rename unsuccessful for unknown reasons.'))
return True, msg
示例9: addcomment
# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import get_raw_body [as 别名]
def addcomment(macro, comicon, comauthor, comtext, compasswd, comrev, comautopass, commarkup):
# Add a comment with inputs
request = Globs.macro.request
cfg = request.cfg
_ = request.getText
datapagename = Globs.datapagename
pg = PageEditor( request, datapagename )
pagetext = pg.get_raw_body()
# HACK for despam
try:
if not request.user.may.save( pg, comtext, pg.current_rev()):
#message("No permission to save this text.")
#return 0
pass
except pg.SaveError, msg:
message(msg)
return 0
示例10: group_add
# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import get_raw_body [as 别名]
def group_add(request, grouppage, accounts, create=False, usercheck=True):
_ = request.getText
success, msg = check_grouppage(request, grouppage, createcheck=not create)
if not success:
raise GroupException(msg + "(%s)" % (grouppage))
if usercheck:
check_users(request, accounts)
page = PageEditor(request, grouppage)
if page.exists():
members = request.groups[grouppage].members | request.groups[grouppage].member_groups
elif create:
members = set([])
else:
raise GroupException(_('Group does not exist: ') + grouppage)
for item in accounts:
if item in members:
raise GroupException(item + _(' already in group: ') + grouppage)
pagetext = page.get_raw_body()
if not pagetext:
pagetext = ''
newtext = _group_add(request, pagetext, accounts)
msg = page.saveText(newtext, 0,
comment="Added to group: " + ', '.join(accounts))
newmembers = request.groups[grouppage].members | request.groups[grouppage].member_groups
if not newmembers == members | set(accounts):
msg = page.saveText(pagetext, 0,
comment="Reverting due to problems in group operation.")
raise GroupException(_('Add unsuccessful for unknown reasons.'))
return True, msg
示例11: RenamePage
# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import get_raw_body [as 别名]
class RenamePage(RenamePageBasic):
def _inlink_rename(self, page, newpagename, oldpagename, comment):
rel_newpagename = wikiutil.RelPageName(page, newpagename)
# The following regexp match functions search for
# occurrences of the target page name, determine
# if they're absolute, relative or subpage
# matches, and replace them accordingly
def word_subfun(mo):
match = mo.groups()
if wikiutil.AbsPageName(page, match[1]) == oldpagename:
# If the link was relative:
if not oldpagename in match[1]:
# If the new page will be a subpage of the
# source, retain relative link. Else, make
# an absolute link.
if (rel_newpagename.startswith('/') or
rel_newpagename.startswith('../')):
return match[1].replace(
wikiutil.RelPageName(page, oldpagename),
rel_newpagename)
else:
return match[1].replace(
wikiutil.RelPageName(page, oldpagename),
newpagename)
# Else, change absolute link
return match[1].replace(oldpagename, newpagename)
# No match in this link -> move on
else:
return match[1]
def link_subfun(mo):
match = mo.groups()
if wikiutil.AbsPageName(page, match[1]) == oldpagename:
# If the link was relative:
if not oldpagename in match[0]:
# If the new page will be a subpage of the
# source, retain relative link. Else, make
# an absolute link.
if (rel_newpagename.startswith('/') or
rel_newpagename.startswith('../')):
return match[0].replace(
wikiutil.RelPageName(page, oldpagename),
rel_newpagename)
else:
return match[0].replace(
wikiutil.RelPageName(page, oldpagename),
newpagename)
# Else, change absolute link
return match[0].replace(oldpagename, newpagename)
# No match in this link -> move on
else:
return match[0]
def include_subfun(mo):
match = mo.groups()
if wikiutil.AbsPageName(page, match[1]) == oldpagename:
# If the link was relative:
if not oldpagename in match[0]:
# If the new page will be a subpage of the
# source, retain relative link. Else, make
# an absolute link.
if (rel_newpagename.startswith('/') or
rel_newpagename.startswith('../')):
return match[0].replace(
wikiutil.RelPageName(page, oldpagename),
rel_newpagename)
else:
return match[0].replace(
wikiutil.RelPageName(page, oldpagename),
newpagename)
# Else, change absolute link
return match[0].replace(oldpagename, newpagename)
# No match in this link -> move on
else:
return match[0]
self.page = PageEditor(self.request, page)
savetext = self.page.get_raw_body()
# Must replace both WikiWords and links, as
# [[WikiWord]] is a link.
word_re = re.compile(Parser.word_rule, re.VERBOSE)
savetext = word_re.sub(word_subfun, savetext)
link_re = re.compile(Parser.link_rule, re.VERBOSE)
savetext = link_re.sub(link_subfun, savetext)
# Also handle renaming (non-regexped) includes of the page
savetext = include_re.sub(include_subfun, savetext)
_ = self.request.getText
success = True
#.........这里部分代码省略.........
示例12: run
# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import get_raw_body [as 别名]
def run(yielder, sp):
# XXX add locking, acquire read-lock on sp
if debug:
self.log_status(ActionClass.INFO, raw_suffix="Processing %r" % sp)
local_pagename = sp.local_name
if not self.request.user.may.write(local_pagename):
self.log_status(ActionClass.WARN, _("Skipped page %s because of no write access to local page."), (local_pagename, ))
return
current_page = PageEditor(self.request, local_pagename) # YYY direct access
comment = u"Local Merge - %r" % (remote.get_interwiki_name() or remote.get_iwid())
tags = TagStore(current_page)
matching_tags = tags.fetch(iwid_full=remote.iwid_full, direction=match_direction)
matching_tags.sort()
if debug:
self.log_status(ActionClass.INFO, raw_suffix="Tags: %r <<BR>> All: %r" % (matching_tags, tags.tags))
# some default values for non matching tags
normalised_name = None
remote_rev = None
local_rev = sp.local_rev # merge against the newest version
old_contents = ""
if matching_tags:
newest_tag = matching_tags[-1]
local_change = newest_tag.current_rev != sp.local_rev
remote_change = newest_tag.remote_rev != sp.remote_rev
# handle some cases where we cannot continue for this page
if not remote_change and (direction == DOWN or not local_change):
return # no changes done, next page
if sp.local_deleted and sp.remote_deleted:
return
if sp.remote_deleted and not local_change:
msg = local.delete_page(sp.local_name, comment)
if not msg:
self.log_status(ActionClass.INFO, _("Deleted page %s locally."), (sp.name, ))
else:
self.log_status(ActionClass.ERROR, _("Error while deleting page %s locally:"), (sp.name, ), msg)
return
if sp.local_deleted and not remote_change:
if direction == DOWN:
return
yield remote.delete_page_pre(sp.remote_name, sp.remote_rev, local_full_iwid)
msg = remote.delete_page_post(yielder.fetch_result())
if not msg:
self.log_status(ActionClass.INFO, _("Deleted page %s remotely."), (sp.name, ))
else:
self.log_status(ActionClass.ERROR, _("Error while deleting page %s remotely:"), (sp.name, ), msg)
return
if sp.local_mime_type != MIMETYPE_MOIN and not (local_change ^ remote_change):
self.log_status(ActionClass.WARN, _("The item %s cannot be merged automatically but was changed in both wikis. Please delete it in one of both wikis and try again."), (sp.name, ))
return
if sp.local_mime_type != sp.remote_mime_type:
self.log_status(ActionClass.WARN, _("The item %s has different mime types in both wikis and cannot be merged. Please delete it in one of both wikis or unify the mime type, and try again."), (sp.name, ))
return
if newest_tag.normalised_name != sp.name:
self.log_status(ActionClass.WARN, _("The item %s was renamed locally. This is not implemented yet. Therefore the full synchronisation history is lost for this page."), (sp.name, )) # XXX implement renames
else:
normalised_name = newest_tag.normalised_name
local_rev = newest_tag.current_rev
remote_rev = newest_tag.remote_rev
old_contents = Page(self.request, local_pagename, rev=newest_tag.current_rev).get_raw_body_str() # YYY direct access
else:
if (sp.local_deleted and not sp.remote_rev) or (
sp.remote_deleted and not sp.local_rev):
return
self.log_status(ActionClass.INFO, _("Synchronising page %s with remote page %s ..."), (local_pagename, sp.remote_name))
if direction == DOWN:
remote_rev = None # always fetch the full page, ignore remote conflict check
patch_base_contents = ""
else:
patch_base_contents = old_contents
# retrieve remote contents diff
if remote_rev != sp.remote_rev:
if sp.remote_deleted: # ignore remote changes
current_remote_rev = sp.remote_rev
is_remote_conflict = False
diff = None
self.log_status(ActionClass.WARN, _("The page %s was deleted remotely but changed locally."), (sp.name, ))
else:
yield remote.get_diff_pre(sp.remote_name, remote_rev, None, normalised_name)
diff_result = remote.get_diff_post(yielder.fetch_result())
if diff_result is None:
self.log_status(ActionClass.ERROR, _("The page %s could not be synced. The remote page was renamed. This is not supported yet. You may want to delete one of the pages to get it synced."), (sp.remote_name, ))
return
is_remote_conflict = diff_result["conflict"]
assert diff_result["diffversion"] == 1
diff = diff_result["diff"]
current_remote_rev = diff_result["current"]
else:
current_remote_rev = remote_rev
if sp.local_mime_type == MIMETYPE_MOIN:
#.........这里部分代码省略.........
示例13: __init__
# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import get_raw_body [as 别名]
class RenamePage:
""" Rename page action
Note: the action name is the class name
"""
def __init__(self, pagename, request):
self.request = request
self.pagename = pagename
self.page = PageEditor(request, pagename)
self.newpage = None
self.error = ''
def allowed(self):
""" Check if user is allowed to do this
This could be a standard method of the base action class, doing
the filtering by action class name and cfg.allowed_actions.
"""
may = self.request.user.may
return (self.__class__.__name__ in self.request.cfg.allowed_actions and
may.write(self.pagename) and may.delete(self.pagename))
def render(self):
""" Render action
This action return a wiki page with optional message, or
redirect to new page.
"""
_ = self.request.getText
form = self.request.form
if form.has_key('cancel'):
# User canceled
return self.page.send_page(self.request)
# Validate user rights and page state. If we get error here, we
# return an error message, without the rename form.
error = None
if not self.allowed():
error = _('You are not allowed to rename pages in this wiki!')
elif not self.page.exists():
error = _('This page is already deleted or was never created!')
if error:
# Send page with an error message
return self.page.send_page(self.request, msg=error)
# Try to rename. If we get an error here, we return the error
# message with a rename form.
elif (form.has_key('rename') and form.has_key('newpagename') and
form.has_key('ticket')):
# User replied to the rename form with all required items
self.rename()
if not self.error:
self.request.http_redirect(self.newpage.url(self.request))
return self.request.finish()
# A new form request, or form has missing data, or rename
# failed. Return a new form with optional error.
return self.page.send_page(self.request, msg=self.makeform())
def rename(self):
""" Rename pagename and return the new page """
_ = self.request.getText
form = self.request.form
# Require a valid ticket. Make outside attacks harder by
# requiring two full HTTP transactions
if not wikiutil.checkTicket(form['ticket'][0]):
self.error = _('Please use the interactive user interface to rename pages!')
return
# Get new name from form and normalize.
comment = form.get('comment', [u''])[0]
newpagename = form.get('newpagename')[0]
newpagename = self.request.normalizePagename(newpagename)
# Name might be empty after normalization. To save translation
# work for this extreme case, we just use "EmptyName".
if not newpagename:
newpagename = "EmptyName"
# Valid new name
newpage = PageEditor(self.request, newpagename)
# Check whether a page with the new name already exists
if newpage.exists(includeDeleted=1):
return self.pageExistsError(newpagename)
# Get old page text
savetext = self.page.get_raw_body()
oldpath = self.page.getPagePath(check_create=0)
newpath = newpage.getPagePath(check_create=0)
# Rename page
# NOTE: might fail if another process created newpagename just
# NOW, while you read this comment. Rename is atomic for files -
# but for directories, rename will fail if the directory
# exists. We should have global edit-lock to avoid this.
#.........这里部分代码省略.........
示例14: execute
# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import get_raw_body [as 别名]
def execute(pagename, request):
_ = request.getText
form = values_to_form(request.values)
if not request.user.may.write(pagename):
request.reset()
backto = form.get('backto', [None])[0]
if backto:
request.page = Page(request, backto)
request.theme.add_msg(_('You are not allowed to edit this page.'),
"error")
request.page.send_page()
return
frm = wr(
u'<form id="metaformedit" method="POST" enctype="multipart/form-data" action="%s">\n',
actionname(request))+\
wr(u'<input form="metaformedit" type="hidden" name="action" value="MetaEdit">\n')+\
wr(u'<input form="metaformedit" type="hidden" name="gwikiseparator" value="%s">\n',
SEPARATOR)
btn = '<div class="saveform"><p class="savemessage">' + \
wr('<input type=submit name=saveform form="metaformedit" value="%s">',
_(form.get('saveBtnText', ['Save Changes'])[0])) + \
wr('<input form="metaformedit" type=submit name=cancel value="%s">',
_('Cancel')) +'</p></div>'
# Template to use for any new pages
template = form.get('template', [''])[0]
if template:
frm += wr('<input form="metaformedit" type="hidden" name="template" value="%s">', template)
# Where to after saving page
backto = form.get('backto', [''])[0]
if backto:
frm += wr('<input form="metaformedit" type="hidden" name="backto" value="%s">', backto)
old_header = request.cfg.page_header2
old_footer = request.cfg.page_footer1
# The post-header and pre-footer texts seem to be implemented in themes.
# Using post-header instead of page msg to avoid breaking header forms.
request.cfg.page_header2 += frm + btn
request.cfg.page_footer1 += btn + '</form>'
old_page = request.page
request.page = FormPage(request, pagename)
error = ''
newpage = False
template_text = ''
# If the page does not exist but we'd know how to construct it,
# replace the Page content with template and pretend it exists
if template and not request.page.exists():
template_page = wikiutil.unquoteWikiname(template)
if request.user.may.read(template_page):
editor = PageEditor(request, template_page)
editor.user = request.user
text = editor.get_raw_body()
editor.page_name = pagename
template_text = editor._expand_variables(text)
request.page.set_raw_body(template_text)
request.page.exists = lambda **kw: True
request.page.lastEditInfo = lambda: {}
newpage = True
else:
error = '<div class="saveform"><p class="savemessage">' + \
_("Cannot read template") + '</p></div>'
elif not template and not request.page.exists():
error = '<div class="saveform"><p class="savemessage">' + \
_("No template specified, cannot edit") + '</p></div>'
if error:
request.cfg.page_header2 = request.cfg.page_header2 + error
request.cfg.page_footer1 = request.cfg.page_footer1
# Extra spaces from formatter need to be removed, that's why the
# page is not sent as it is
out = StringIO.StringIO()
request.redirect(out)
request.sent_headers = True
request.page.send_page()
request.redirect()
graphdata = request.graphdata
vals_on_keys = graphdata.get_vals_on_keys()
# If we're making a new page based on a template, make sure that
# the values from the evaluated template are included in the form editor
if newpage:
templatePage = Page(request, template)
data = parse_text(request, templatePage, template_text)
for page in data:
for key in data[page].get('meta', list()):
for val in data[page]['meta'][key]:
vals_on_keys.setdefault(key, set()).add(val)
for key in data[page].get('out', list()):
for val in data[page]['out'][key]:
#.........这里部分代码省略.........
示例15: RenamePage
# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import get_raw_body [as 别名]
#.........这里部分代码省略.........
# Else, change absolute link
return match[0].replace(oldpagename, newpagename)
# No match in this link -> move on
else:
return match[0]
def include_subfun(mo):
match = mo.groups()
if wikiutil.AbsPageName(page, match[1]) == oldpagename:
# If the link was relative:
if not oldpagename in match[0]:
# If the new page will be a subpage of the
# source, retain relative link. Else, make
# an absolute link.
if (rel_newpagename.startswith('/') or
rel_newpagename.startswith('../')):
return match[0].replace(
wikiutil.RelPageName(page, oldpagename),
rel_newpagename)
else:
return match[0].replace(
wikiutil.RelPageName(page, oldpagename),
newpagename)
# Else, change absolute link
return match[0].replace(oldpagename, newpagename)
# No match in this link -> move on
else:
return match[0]
self.page = PageEditor(self.request, page)
savetext = self.page.get_raw_body()
# Must replace both WikiWords and links, as
# [[WikiWord]] is a link.
word_re = re.compile(Parser.word_rule, re.VERBOSE)
savetext = word_re.sub(word_subfun, savetext)
link_re = re.compile(Parser.link_rule, re.VERBOSE)
savetext = link_re.sub(link_subfun, savetext)
# Also handle renaming (non-regexped) includes of the page
savetext = include_re.sub(include_subfun, savetext)
_ = self.request.getText
success = True
try:
msg = self.page.saveText(savetext, 0, comment=comment,
notify=False)
except self.page.Unchanged:
msg = _('Error changing links on page %s!') % (self.page.page_name)
success = False
return success, msg
def rename_inlinks(self, newpagename, comment, msgs):
comment = "%s (%s)" % (comment, _("changed links:") +
" %s -> %s" % (self.pagename, newpagename))
# List pages that link to the renamed page
pages = set()
inlinks = self.request.graphdata.get_in(self.pagename)
for type in inlinks:
pages.update(inlinks[type])