Module:Find sources/autodoc: Difference between revisions
From All Skies Encyclopaedia
imported>Mr. Stradivarius (write a function to get all page names with a certain prefix, to avoid making users manually add new template config pagenames and link config pagenames to some data module) |
imported>Mr. Stradivarius (add a function to get subpages from a table of page names) |
||
Line 10: | Line 10: | ||
end |
end |
||
return pagenames |
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 |
end |
||
Revision as of 14:00, 26 September 2014
This module provides automatic documentation for templates based on Module:Find sources. See Module:Find sources for an overview.
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