Move some logic from ui.py to wiki.py