<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://phuketer.com/w/index.php?action=history&amp;feed=atom&amp;title=Module%3ACIA_World_Factbook</id>
	<title>Module:CIA World Factbook - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://phuketer.com/w/index.php?action=history&amp;feed=atom&amp;title=Module%3ACIA_World_Factbook"/>
	<link rel="alternate" type="text/html" href="https://phuketer.com/w/index.php?title=Module:CIA_World_Factbook&amp;action=history"/>
	<updated>2026-06-17T19:16:42Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.2</generator>
	<entry>
		<id>https://phuketer.com/w/index.php?title=Module:CIA_World_Factbook&amp;diff=1621&amp;oldid=prev</id>
		<title>imported&gt;Hike395: protect against nil month</title>
		<link rel="alternate" type="text/html" href="https://phuketer.com/w/index.php?title=Module:CIA_World_Factbook&amp;diff=1621&amp;oldid=prev"/>
		<updated>2026-02-13T11:20:58Z</updated>

		<summary type="html">&lt;p&gt;protect against nil month&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local p = {}&lt;br /&gt;
local getArgs = require(&amp;#039;Module:Arguments&amp;#039;).getArgs&lt;br /&gt;
&lt;br /&gt;
-- prefix of all World Factbook pages&lt;br /&gt;
local factbookPrefix = &amp;#039;https://web.archive.org/web/%04d%02d%02d000000/https://www.cia.gov/the-world-factbook/&amp;#039;&lt;br /&gt;
local archiveURL = &amp;#039;https://web.archive.org/web/20211205000000/https://www.cia.gov/the-world-factbook/about/archives/download/factbook-%d.zip&amp;#039;&lt;br /&gt;
&lt;br /&gt;
-- Function to turn a string into a URL fragment appropriate for CIA website&lt;br /&gt;
local function parseFragment(s)&lt;br /&gt;
	if not s then&lt;br /&gt;
		return &amp;#039;&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
	s = mw.ustring.lower(s)&lt;br /&gt;
	s = mw.ustring.gsub(s,&amp;#039; &amp;#039;,&amp;#039;-&amp;#039;)&lt;br /&gt;
	s = mw.ustring.gsub(s,&amp;#039;,&amp;#039;,&amp;#039;&amp;#039;)&lt;br /&gt;
	return s&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local monthMap = {january=1,february=2,march=3,april=4,may=5,june=6,&lt;br /&gt;
	              july=7,august=8,september=9,october=10,november=11,december=12,&lt;br /&gt;
	              jan=1,feb=2,mar=3,apr=4,may=5,jun=6,jul=7,aug=8,sep=9,oct=10,nov=11,dec=12}&lt;br /&gt;
&lt;br /&gt;
local function parseDate(date)&lt;br /&gt;
	local year, month, day&lt;br /&gt;
	if not date then return nil, nil, nil end&lt;br /&gt;
	_, _, year, month, day = mw.ustring.find(date,&amp;quot;(20%d%d)-(%d+)-(%d+)&amp;quot;)&lt;br /&gt;
	if year then return year, month, day end&lt;br /&gt;
	_, _, day, month, year = mw.ustring.find(date,&amp;quot;(%d+)%s+(%a+)%s+(20%d%d)&amp;quot;)&lt;br /&gt;
	month = month and monthMap[mw.ustring.lower(month)]&lt;br /&gt;
	if year then return year, month, day end&lt;br /&gt;
	_, _, month, day, year = mw.ustring.find(date,&amp;quot;(%a+)%s(%d+),%s+(20%d%d)&amp;quot;)&lt;br /&gt;
	month = month and monthMap[mw.ustring.lower(month)]&lt;br /&gt;
	if year then return year, month, day end&lt;br /&gt;
	_, _, year = mw.ustring.find(date,&amp;quot;(20%d%d)&amp;quot;)&lt;br /&gt;
	if year then return year, nil, nil end&lt;br /&gt;
	return nil, nil, nil&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function archiveDate(args)&lt;br /&gt;
	local year, month, day = parseDate(args.date)&lt;br /&gt;
	if not args.year or args.year == year then return tonumber(year), month, day end&lt;br /&gt;
	return tonumber(args.year), nil, nil&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Function to fill in factbook link:&lt;br /&gt;
-- Arguments:&lt;br /&gt;
--    args.country: topic of page (optional)&lt;br /&gt;
--    args.section: section of page (optional)&lt;br /&gt;
-- Returns:&lt;br /&gt;
--    link to World Factbook page about country, with section anchor&lt;br /&gt;
function p._country(args)&lt;br /&gt;
	local year, month, day = archiveDate(args)&lt;br /&gt;
	if not year or year &amp;gt; 2025 then&lt;br /&gt;
		year = 2025&lt;br /&gt;
		month = 12&lt;br /&gt;
		day = 5&lt;br /&gt;
	end&lt;br /&gt;
	if year &amp;lt; 2021 then&lt;br /&gt;
		return mw.ustring.format(archiveURL,year)&lt;br /&gt;
	end&lt;br /&gt;
	if not month then month = 12 end&lt;br /&gt;
	if not day then day = 5 end&lt;br /&gt;
	local prefix = mw.ustring.format(factbookPrefix,year,month,day)&lt;br /&gt;
	if not args.country then&lt;br /&gt;
		return prefix&lt;br /&gt;
	end&lt;br /&gt;
	local result = prefix..&amp;#039;countries/&amp;#039;..parseFragment(args.country)&lt;br /&gt;
	if args.section then&lt;br /&gt;
		return result..&amp;#039;/#&amp;#039;..parseFragment(args.section)&lt;br /&gt;
	end&lt;br /&gt;
	return result&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function p.country(frame)&lt;br /&gt;
	local args = getArgs(frame)&lt;br /&gt;
	return p._country(args)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>imported&gt;Hike395</name></author>
	</entry>
</feed>