Skip to content
Snippets Groups Projects
Commit 8c85670f authored by Magnus Giesbert's avatar Magnus Giesbert
Browse files

add ´change_links´ and update ´move_page´

parent 7a7547c3
No related branches found
No related tags found
No related merge requests found
......@@ -12,13 +12,7 @@ def move_page(original_page, new_page, delete=False):
proxy.wiki.putPage(new_page, page_content, {"sum":"Moved from " + original_page})
# update back links to new page #
back_links = proxy.wiki.getBackLinks(original_page)
reg = rf"\[\[\s*{original_page}\s*\|(.*?)\]\]" # regex for dokuwiki links we want to replace
_replacer = lambda matched : "[[" + new_page + "|" + matched.group(1) + "]]"
for page in back_links:
content = proxy.wiki.getPage(page)
content = re.sub(reg, _replacer, content)
proxy.wiki.putPage(page, content, {"sum":"Update links from " +original_page+ " to " + new_page})
change_links(original_page, new_page)
# either flag or delete original page #
if not delete:
......@@ -28,6 +22,18 @@ def move_page(original_page, new_page, delete=False):
proxy.wiki.putPage(original_page, "", {"sum":"Moved to " + new_page}) # deletes original page
def change_links(old_page, new_page):
"""Updates pages that link to old page, to link to new page"""
with Proxy(config.WIKI_API_URL) as proxy:
backLinks = proxy.wiki.getBackLinks(old_page)
reg = rf"\[\[\s*{old_page}\s*\|(.*?)\]\]" # regex for dokuwiki links we want to replace
_replacer = lambda matched : "[[" + new_page + "|" + matched.group(1) + "]]"
for page in backLinks:
content = proxy.wiki.getPage(page)
content = re.sub(reg, _replacer, content)
proxy.wiki.putPage(page, content, {"sum":"Update links from " +old_page+ " to " + new_page})
def find_old_pages(timedelta, namespace=""):
"""Returns all pages whose rev is older than the given timedelta"""
with Proxy(config.WIKI_API_URL) as proxy:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment