Jump to content

Module:Find sources/autodoc

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 14:00, 26 September 2014 (add a function to get subpages from a table of page names). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}

function p.getPrefixPagenames(prefix)
	local specialText = string.format('{{Special:PrefixIndex/%s}}', prefix)
	specialText = mw.getCurrentFrame():preprocess(specialText)
	specialText = mw.text.unstrip(specialText)
	local pagenames = {}
	for s in string.gmatch(specialText, '<a href="[^"]*" title="([^"]*)"[^>]*>[^<]*</a>') do
		pagenames[#pagenames + 1] = mw.text.decode(s)
	end
	return pagenames
end

function p.getSubpages(pagenames, prefix)
	local stripped = {}
	for i, page in ipairs(pagenames) do
		local pattern = '^' .. prefix:gsub('%p', '%%%0') -- Turn the prefix into a Lua pattern
		stripped[i] = mw.ustring.gsub(page, pattern, '')
	end
	return stripped
end

return p