Module:DPLUtil

local util_text = require('Module:TextUtil') local util_table = require('Module:TableUtil') local lang = mw.getLanguage('en') local p = {}

function p.query(args) args[1] = '' return mw.getCurrentFrame:callParserFunction{ name = '#dpl:', args = args } end

function p.truncateResult(tbl) if not next(tbl) then return {} end table.remove(tbl, #tbl) return tbl end

function p.getListOfPagenames(args) args.format = ',%PAGE%,;;,' args.debug = 0 local result = p.query(args) local tbl = util_text.split(result or '',';;') return p.truncateResult(tbl) end

function p.escape(link) link = link or '' link = string.gsub(link,'%(','\\%(') link = string.gsub(link,'%)','\\%)') link = string.gsub(link,'%+','\\%+') return link end

function p.whichPagesExist(links) for k, link in ipairs(links) do		links[k] = lang:ucfirst(p.escape(link)) end newlinks = mw.getCurrentFrame:callParserFunction{ name = '#dpl:', args = { '',			titleregexp = table.concat(links,'|'), format = ',%PAGE%,;,', namespace = '', debug = 0, }	}	newlinks = newlinks .. mw.title.getCurrentTitle.text return util_text.split(newlinks,';') end

function p.whatRedirectsHere(page, settings) local args = { '',		linksto = page, redirects = 'only', namespace = '', format = ',,%PAGE%;,', debug = '0' }	util_table.merge(args, settings) local list = mw.getCurrentFrame:callParserFunction{ name = '#dpl', args = args }	local tbl = util_text.split(list,';') return p.truncateResult(tbl) end

return p