Move duplicated code into new wiki_query function