Documentation for this module may be created at Module:Sandbox/GreenC/getcategory/doc
-- Find the date of birth/death from [[Category:XXXX births]]
-- Doesn't preserve AD, BC, ca. etc..
local p = {}
function p.getcategory(frame)
local pframe = frame:getParent()
local args = pframe.args
-- Load the page
t = mw.title.getCurrentTitle()
pagetext = t:getContent()
if pagetext == nil then
return ""
end
-- Remove false positives
pagetext = mw.ustring.gsub( mw.ustring.gsub(pagetext, "<!--.--->", ""), "<nowiki>.-</nowiki>", "")
-- Scrape for the Category and find date
local birthcheck = mw.ustring.match(pagetext, "%[%[%s-[Cc]ategory:%s-%d+%.?%d*%s-births%s-%]%]" )
if birthcheck ~= nil then
birthcat = mw.ustring.match(birthcheck, "%d+%.?%d*")
else
birthcat = "Unknown"
end
local deathcheck = mw.ustring.match(pagetext, "%[%[%s-[Cc]ategory:%s-%d+%.?%d*%s-deaths%s-%]%]" )
if deathcheck ~= nil then
deathcat = mw.ustring.match(deathcheck, "%d+%.?%d*")
else
deathcat = "Unknown"
end
return birthcat .. "-" .. deathcat
end
return p