localp={}localgetArgs=require('Module:Arguments').getArgs-- prefix of all World Factbook pageslocalfactbookPrefix='https://www.cia.gov/the-world-factbook/'-- Format of archive link. Both %d represent the year of the archivelocalarchiveFormat=' [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 websitelocalfunctionparseFragment(s)ifnotsthenreturn''ends=mw.ustring.lower(s)s=mw.ustring.gsub(s,' ','-')s=mw.ustring.gsub(s,',','')returnsend-- 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 anchorfunctionp._country(args)ifnotargs.countrythenreturnfactbookPrefixendlocalresult=factbookPrefix..'countries/'..parseFragment(args.country)ifargs.sectionthenreturnresult..'/#'..parseFragment(args.section)endreturnresultend-- 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 nilfunctionp._archive(args)ifargs.archivethenreturnnilendlocalyear=nilifargs.yearthenyear=tonumber(args.year)elseifargs.datetheni,j=mw.ustring.find(args.date,'20%d%d')ifiandjthenyear=tonumber(mw.ustring.sub(args.date,i,j))endendifnotyearthenreturnyearendifyear>=tonumber(os.date('%Y'))-1thenreturnfalseendreturnmw.ustring.format(archiveFormat,year,year)endfunctionp.country(frame)localargs=getArgs(frame)returnp._country(args)endfunctionp.archive(frame)localargs=getArgs(frame)returnp._archive(args)or''endreturnp