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
local p = {}
local idPrefix = "TITAF-P-"
local digits = 7
function p.getNextId()
local allPages = mw.smw.ask {
"[[Category:TangoPeople]]",
"?=page",
"limit=5000"
}
local maxId = 0
if allPages then
for _, result in ipairs(allPages) do
local title = result["page"] or ""
local idNum = title:match("TITAF%-P%-(%d+)")
if idNum then
local num = tonumber(idNum)
if num and num > maxId then
maxId = num
end
end
end
end
local newId = maxId + 1
return idPrefix .. string.format("%0" .. digits .. "d", newId)
end
return p