Module:GenerateID
From TANGOWIKI-TITAF
Documentation for this module may be created at Module:GenerateID/doc
-- Module:GenerateID
-- This module generates the next available TITAF-P-xxxxxxx ID for Person pages
-- and TITAF-G-xxxxxxx ID for Musical Groups
local p = {}
local digits = 7
function p.personID()
return p._generateID("TITAF-P-", "[[Category:TangoPeople]]", "TITAF%-P%-(%d+)")
end
function p.groupID()
return p._generateID("TITAF-G-", "[[Category:MusicalGroups]]", "TITAF%-G%-(%d+)")
end
function p._generateID(prefix, category, pattern)
local allPages = mw.smw.ask {
category,
"?=page",
"limit=5000"
}
local maxId = 0
if allPages then
for _, result in ipairs(allPages) do
local title = result["page"] or ""
local idNum = title:match(pattern)
if idNum then
local num = tonumber(idNum)
if num and num > maxId then
maxId = num
end
end
end
end
local newId = maxId + 1
return prefix .. string.format("%0" .. digits .. "d", newId)
end
return p