Module:TemplateStarter: Difference between revisions
// via Wikitext Extension for VSCode |
// via Wikitext Extension for VSCode |
||
| Line 170: | Line 170: | ||
end | end | ||
local templates = {} | local templates = {} | ||
if ConfigRepository.templates then | if ConfigRepository.templates then | ||
local index = 1 | local index = 1 | ||
for templateName, | for templateName, config in pairs(ConfigRepository.templates) do | ||
if templateName and templateName ~= "" then | -- Include template if page_creator is not explicitly false | ||
if templateName and templateName ~= "" and (not config.meta or config.meta.page_creator ~= false) then | |||
templates[index] = templateName | templates[index] = templateName | ||
index = index + 1 | index = index + 1 | ||
| Line 184: | Line 183: | ||
table.sort(templates) | table.sort(templates) | ||
end | end | ||
templateListCache = templates | templateListCache = templates | ||
templateListCacheTime = currentTime | templateListCacheTime = currentTime | ||
| Line 195: | Line 192: | ||
-- Get list of available templates including variants | -- Get list of available templates including variants | ||
function p.getAvailableTemplatesWithVariants() | function p.getAvailableTemplatesWithVariants() | ||
local | -- Get the filtered list of base templates that are allowed for page creation | ||
local baseTemplates = p.getAvailableTemplates() | |||
local templatesWithVariants = {} | local templatesWithVariants = {} | ||
-- Add base templates | -- Use a map to ensure uniqueness before adding to the final list | ||
for _, templateName in ipairs( | local templateMap = {} | ||
-- Add base templates to the map | |||
for _, templateName in ipairs(baseTemplates) do | |||
templateMap[templateName] = true | |||
end | end | ||
-- | -- Iterate through the allowed base templates to find their variants | ||
for _, templateName in ipairs(baseTemplates) do | |||
local config = ConfigRepository.getConfig(templateName) | |||
if config and config.variants then | |||
for _, variant in pairs(config.variants) do | |||
-- A variant is included if it's active and not explicitly excluded | |||
if variant.state and variant.name and (not variant.meta or variant.meta.page_creator ~= false) then | |||
templateMap[variant.name] = true | |||
end | end | ||
end | end | ||
| Line 220: | Line 217: | ||
end | end | ||
-- Sort the combined list | -- Convert map keys to a list | ||
local index = 1 | |||
for templateName, _ in pairs(templateMap) do | |||
templatesWithVariants[index] = templateName | |||
index = index + 1 | |||
end | |||
-- Sort the final combined list | |||
table.sort(templatesWithVariants) | table.sort(templatesWithVariants) | ||