Module:CIA World Factbook

Documentation for this module may be created at Module:CIA World Factbook/doc

Documentation for this module may be created at Module:CIA World Factbook/doc

local p = {}
local getArgs = require('Module:Arguments').getArgs

-- prefix of all World Factbook pages
local factbookPrefix = 'https://www.cia.gov/the-world-factbook/'

--  Format of archive link. Both %d represent the year of the archive
local archiveFormat = ' [https://www.cia.gov/the-world-factbook/about/archives/download/factbook-%d.zip (Archived %d edition)]'

-- Function to turn a string into a URL fragment appropriate for CIA website
local function parseFragment(s)
	if not s then
		return ''
	end
	s = mw.ustring.lower(s)
	s = mw.ustring.gsub(s,' ','-')
	s = mw.ustring.gsub(s,',','')
	return s
end

-- Function to fill in factbook link:
-- Arguments:
--    args.country: topic of page (optional)
--    args.section: section of page (optional)
-- Returns:
--    link to World Factbook page about country, with section anchor
function p._country(args)
	if not args.country then
		return factbookPrefix
	end
	local result = factbookPrefix..'countries/'..parseFragment(args.country)
	if args.section then
		return result..'/#'..parseFragment(args.section)
	end
	return result
end

-- Function to fill in archive link:
-- Arguments:
--    args.archive: if non-empty, return nil
--    args.year: else if this is non-empty, use it for year
--    args.date: else if this is non-empty, parse it for a year
-- Returns:
--    the link, above, filled in with the year, or nil
function p._archive(args)
	if args.archive then
		return nil
	end
	local year = nil
	if args.year then
		year = tonumber(args.year)
	elseif args.date then
		i, j = mw.ustring.find(args.date,'20%d%d')
		if i and j then
			year = tonumber(mw.ustring.sub(args.date,i,j))
		end
	end
	if not year then
		return year
	end
	if year >= tonumber(os.date('%Y'))-1 then
		return false
	end
	return mw.ustring.format(archiveFormat, year, year)
end

function p.country(frame)
	local args = getArgs(frame)
	return p._country(args)
end

function p.archive(frame)
	local args = getArgs(frame)
	return p._archive(args) or ''
end

return p


Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.