Skip to content
Snippets Groups Projects
Select Git revision
  • f977295e7436abef2c43eda75d34944eacebf6ce
  • master default protected
  • postgres_integration
  • s3compatible
  • intros
  • bootstrap4
  • modules
7 results

db_example.sql

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    wikibot.py 1.68 KiB
    # documentation of dokuwiki xmlrpc commands: https://www.dokuwiki.org/devel:xmlrpc
    import config
    from xmlrpc.client import ServerProxy as Proxy, Error as wikiError
    import re
    import datetime
    
    def move_page(original_page, new_page, delete=False):
    	"""Moves a page, updates link to new page and flags or deletes the old one"""
    	with Proxy(config.WIKI_API_URL) as proxy:
    		# create new page with identical content #
    		page_content = proxy.wiki.getPage(original_page)
    		proxy.wiki.putPage(new_page, page_content, {"sum":"Moved from " + original_page})
    
    		# update back links to new page #
    		backLinks = 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 backLinks:
    			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})
    
    		# either flag or delete original page #
    		if not delete:
    			proxy.dokuwiki.appendPage(original_page, "\n DELETEME This page was moved to "+ new_page,
    				{"sum":"Moved to " + new_page + " and marked page for deletion"}) 
    		else:
    			proxy.wiki.putPage(original_page, "", {"sum":"Moved to " + new_page}) # deletes original 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:
    		pages = proxy.dokuwiki.getPagelist(namespace)
    		proxy_time = proxy.dokuwiki.getTime()
    		old_pages = [page for page in pages if (proxy_time - page.get('rev') > timedelta.total_seconds())] 
    		return old_pages