<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://mywikibiz.com/index.php?action=history&amp;feed=atom&amp;title=Module%3ACountry_population</id>
	<title>Module:Country population - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://mywikibiz.com/index.php?action=history&amp;feed=atom&amp;title=Module%3ACountry_population"/>
	<link rel="alternate" type="text/html" href="https://mywikibiz.com/index.php?title=Module:Country_population&amp;action=history"/>
	<updated>2026-07-28T19:59:23Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.3</generator>
	<entry>
		<id>https://mywikibiz.com/index.php?title=Module:Country_population&amp;diff=471423&amp;oldid=prev</id>
		<title>Zoran: Pywikibot 6.4.0</title>
		<link rel="alternate" type="text/html" href="https://mywikibiz.com/index.php?title=Module:Country_population&amp;diff=471423&amp;oldid=prev"/>
		<updated>2021-07-15T21:13:34Z</updated>

		<summary type="html">&lt;p&gt;Pywikibot 6.4.0&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;require('Module:No globals')&lt;br /&gt;
local fn = require('Module:Formatnum')&lt;br /&gt;
local mm = require('Module:Math')&lt;br /&gt;
local p ={}&lt;br /&gt;
--local pargs ={}&lt;br /&gt;
local args={}&lt;br /&gt;
local data={}&lt;br /&gt;
&lt;br /&gt;
p.getArgs =function(frameArgs)&lt;br /&gt;
    for k,v in pairs(frameArgs) do&lt;br /&gt;
    	args[k]=v&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
p.main = function(frame) -- entry point for template&lt;br /&gt;
	&lt;br /&gt;
	p.getArgs(frame:getParent().args)                  -- need to copy arguments because of the way frame arguments are handled&lt;br /&gt;
		&lt;br /&gt;
	if args['list'] then p.getCountriesFromList(args['list']) end&lt;br /&gt;
	&lt;br /&gt;
	if args['mode'] == &amp;quot;piechart&amp;quot; then&lt;br /&gt;
		return p._piechart(frame)&lt;br /&gt;
	else&lt;br /&gt;
		return p._populations(frame)&lt;br /&gt;
	end&lt;br /&gt;
    &lt;br /&gt;
end&lt;br /&gt;
function p.getCountriesFromList(list)&lt;br /&gt;
	local country_lists = {&lt;br /&gt;
		['South America']  = { &amp;quot;ARG&amp;quot;,&amp;quot;BOL&amp;quot;,&amp;quot;BRA&amp;quot;,&amp;quot;CHL&amp;quot;,&amp;quot;COL&amp;quot;,&amp;quot;ECU&amp;quot;,&amp;quot;GUY&amp;quot;,&amp;quot;PRY&amp;quot;,&amp;quot;PER&amp;quot;,&amp;quot;SUR&amp;quot;,&amp;quot;URY&amp;quot;,&amp;quot;VEN&amp;quot;,&amp;quot;BVT&amp;quot;,&amp;quot;FLK&amp;quot;,&amp;quot;SGS&amp;quot;,&amp;quot;GUF&amp;quot; },&lt;br /&gt;
		['North America']  = { &amp;quot;ATG&amp;quot;,&amp;quot;BHS&amp;quot;,&amp;quot;BLZ&amp;quot;,&amp;quot;BRB&amp;quot;,&amp;quot;CAN&amp;quot;,&amp;quot;CRI&amp;quot;,&amp;quot;CUB&amp;quot;,&amp;quot;DMA&amp;quot;,&amp;quot;DOM&amp;quot;,&amp;quot;GRD&amp;quot;,&amp;quot;GTM&amp;quot;,&amp;quot;HND&amp;quot;,&amp;quot;HTI&amp;quot;,&amp;quot;JAM&amp;quot;,&amp;quot;KNA&amp;quot;,&amp;quot;LCA&amp;quot;,&amp;quot;MEX&amp;quot;,&amp;quot;NIC&amp;quot;,&amp;quot;PAN&amp;quot;,&amp;quot;SLV&amp;quot;,&amp;quot;TTO&amp;quot;,&amp;quot;USA&amp;quot;,&amp;quot;VCT&amp;quot; },&lt;br /&gt;
		['Arab countries'] = { &amp;quot;EGY&amp;quot;,&amp;quot;DZA&amp;quot;,&amp;quot;SDN&amp;quot;,&amp;quot;IRQ&amp;quot;,&amp;quot;MAR&amp;quot;,&amp;quot;SAU&amp;quot;,&amp;quot;YEM&amp;quot;,&amp;quot;SYR&amp;quot;,&amp;quot;TUN&amp;quot;,&amp;quot;JOR&amp;quot;,&amp;quot;ARE&amp;quot;,&amp;quot;LBN&amp;quot;,&amp;quot;LBY&amp;quot;,&amp;quot;PSE&amp;quot;,&amp;quot;OMN&amp;quot;,&amp;quot;KWT&amp;quot;,&amp;quot;MRT&amp;quot;,&amp;quot;QAT&amp;quot;,&amp;quot;BHR&amp;quot;,&amp;quot;DJI&amp;quot;,&amp;quot;COM&amp;quot; }&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	---local i=1&lt;br /&gt;
	for k,v in pairs( country_lists[list] ) do&lt;br /&gt;
	     --args[i] = v&lt;br /&gt;
	     args[k] = v&lt;br /&gt;
	     --i=i+1&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.getPattern(section)&lt;br /&gt;
	local pattern = '&amp;lt;section begin=' .. section ..'[ ]*/&amp;gt;(.-)&amp;lt;section end='..section..'[ ]*/&amp;gt;'&lt;br /&gt;
	return pattern&lt;br /&gt;
end&lt;br /&gt;
function p.getPopulationData(frame)&lt;br /&gt;
&lt;br /&gt;
    local page = &amp;quot;List of countries by population (United Nations)&amp;quot;&lt;br /&gt;
	data['dates'] = {}&lt;br /&gt;
	data['total'] = {}&lt;br /&gt;
	data.total['latest'] = 0&lt;br /&gt;
	data.total['previous'] = 0&lt;br /&gt;
	data.total['projected'] = 0&lt;br /&gt;
	&lt;br /&gt;
	--local total = 0&lt;br /&gt;
	--local totalProjected = 0&lt;br /&gt;
	local count = 0&lt;br /&gt;
	local title = mw.title.new( page) -- , ns)  -- creates object if page doesn't exist (and valid page name)&lt;br /&gt;
	                                            --TODO: could use mw.title.makeTitle(), but that needs ns&lt;br /&gt;
	&lt;br /&gt;
	local content = title:getContent()&lt;br /&gt;
    &lt;br /&gt;
    -- get dates &lt;br /&gt;
	for value in string.gmatch( content , p.getPattern(&amp;quot;date_1&amp;quot;) ) do&lt;br /&gt;
		data.dates['latest']=value                                    -- date of latest data &lt;br /&gt;
	end&lt;br /&gt;
	for value in string.gmatch( content , p.getPattern(&amp;quot;date&amp;quot;) ) do&lt;br /&gt;
	    data.dates['previous']=mw.getContentLanguage():formatDate('j F Y', value)&lt;br /&gt;
	end		&lt;br /&gt;
	data.dates['today'] = mw.getContentLanguage():formatDate('j F Y')      -- today's date (for formatting see https://www.mediawiki.org/wiki/Help:Extension:ParserFunctions#.23time)&lt;br /&gt;
    &lt;br /&gt;
    -- get population data for each country passes as parameter&lt;br /&gt;
	for k,v in ipairs(args) do&lt;br /&gt;
		local country = mw.text.trim(v)&lt;br /&gt;
		&lt;br /&gt;
		-- get population data from section &lt;br /&gt;
	    local section = country .. &amp;quot;_1&amp;quot;&lt;br /&gt;
		for value in string.gmatch( content , p.getPattern(section) ) do&lt;br /&gt;
&lt;br /&gt;
	    	count=count+1&lt;br /&gt;
	    	data[count] = {}&lt;br /&gt;
	        data[count]['country'] = country&lt;br /&gt;
			data[count]['populationString'] = frame:preprocess(value)&lt;br /&gt;
			local raw = string.gsub(data[count]['populationString'], &amp;quot;,&amp;quot;, &amp;quot;&amp;quot;) -- strip formatting from number string&lt;br /&gt;
            data[count]['populationNumber'] = tonumber(raw)&lt;br /&gt;
            data.total['latest'] = data.total['latest'] + data[count]['populationNumber']&lt;br /&gt;
            &lt;br /&gt;
            local section = country .. &amp;quot;_0&amp;quot;&lt;br /&gt;
           	for value2 in  string.gmatch( content , p.getPattern(section) ) do&lt;br /&gt;
				data[count]['populationString2'] = frame:preprocess(value2)&lt;br /&gt;
				local raw = string.gsub(data[count]['populationString2'], &amp;quot;,&amp;quot;, &amp;quot;&amp;quot;) -- strip formatting from number string&lt;br /&gt;
                data[count]['populationNumber2'] = tonumber(raw)&lt;br /&gt;
                data.total['previous'] = data.total['previous'] + data[count]['populationNumber2']&lt;br /&gt;
                &lt;br /&gt;
                data[count]['populationIncrement']=data[count]['populationNumber'] - data[count]['populationNumber2']&lt;br /&gt;
                data[count]['populationGrowth'] =data[count]['populationIncrement']/data[count]['populationNumber2']&lt;br /&gt;
                data[count]['populationDouble'] = p.getPopulationDoubleTime(data[count]['populationNumber'],data[count]['populationNumber2'])&lt;br /&gt;
&lt;br /&gt;
                data[count]['populationProjected'] = p.getPopulationProjection(data[count]['populationNumber'],data[count]['populationNumber2'])&lt;br /&gt;
                data.total['projected'] = data.total['projected'] + data[count]['populationProjected'] &lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
    return true&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- estimate time to double population based on latest growth rate&lt;br /&gt;
function p.getPopulationDoubleTime(latest,previous)&lt;br /&gt;
	local growth = (latest - previous) / previous&lt;br /&gt;
    local doubleTime = math.log( 2 ) / math.log(1 + growth)&lt;br /&gt;
    return doubleTime&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- estimate today's population based on latest growth rate&lt;br /&gt;
function p.getPopulationProjection(latest,previous)&lt;br /&gt;
	local ay =  ( mw.getCurrentFrame():callParserFunction{ name = '#time', args = { &amp;quot;U&amp;quot;, data.dates['today'] } }&lt;br /&gt;
                - mw.getCurrentFrame():callParserFunction{ name = '#time', args = { &amp;quot;U&amp;quot;, data.dates['previous'] } })&lt;br /&gt;
                /60/60/24/365.2425 -- number of years since first date until today‬&lt;br /&gt;
	local projected = math.pow(previous, 1 - ay ) * math.pow(latest, ay)&lt;br /&gt;
    return projected&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[ sort rows by population (defaults to latest population)&lt;br /&gt;
     TODO add options for sorting columns&lt;br /&gt;
  ]]&lt;br /&gt;
function p.sortPopulationData(ByColumn)&lt;br /&gt;
	&lt;br /&gt;
    local sort_function = function( a,b )&lt;br /&gt;
	    if (tonumber(a.populationNumber) &amp;gt; tonumber(b.populationNumber)) then                -- primary sort on 'population' -&amp;gt; a before b&lt;br /&gt;
	        return true&lt;br /&gt;
	    end&lt;br /&gt;
	end&lt;br /&gt;
		&lt;br /&gt;
    table.sort(data, sort_function)&lt;br /&gt;
end&lt;br /&gt;
--[[  Function to get flag icon and handle special cases &lt;br /&gt;
      1.  There is an issue of non-standard sizes when used with static rank column &lt;br /&gt;
	      The three countries with extra height (and the required size parameter) are &lt;br /&gt;
	           Nepal/NPL (size=12px), Switzerland/CHE (size=15px), Vatican/VAT (size=15px)&lt;br /&gt;
	           a few have lower default heights so it doesn't matter (Poland, New Caledonia)&lt;br /&gt;
      2. Alias, e.g. NEP-&amp;gt;NPL, TRI-&amp;gt;TTO&lt;br /&gt;
  ]]&lt;br /&gt;
function p.getFlagLabel(countryCode)&lt;br /&gt;
	local output &lt;br /&gt;
	local templateArgs = { countryCode }&lt;br /&gt;
	&lt;br /&gt;
	local size&lt;br /&gt;
    if countryCode == &amp;quot;CHE&amp;quot; or countryCode == &amp;quot;VAT&amp;quot; then&lt;br /&gt;
    	size=&amp;quot;15px&amp;quot;&lt;br /&gt;
    elseif countryCode == &amp;quot;NPL&amp;quot; then&lt;br /&gt;
    	size=&amp;quot;12px&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    if size then templateArgs['size'] = size end&lt;br /&gt;
&lt;br /&gt;
	-- simple version&lt;br /&gt;
	--output = mw.getCurrentFrame():expandTemplate{ title = &amp;quot;flagcountry&amp;quot;, args = templateArgs } &lt;br /&gt;
	&lt;br /&gt;
	-- method with fixed-height div and overflow&lt;br /&gt;
    output = '&amp;lt;div style=&amp;quot;height:15px;overflow:visible;&amp;quot; &amp;gt;'&lt;br /&gt;
		  .. mw.getCurrentFrame():expandTemplate{ title = &amp;quot;flagcountry&amp;quot;, args = templateArgs  }&lt;br /&gt;
	      .. '&amp;lt;/div&amp;gt;'&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
	return output		          	        &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[ output table of data as Wikitext table&lt;br /&gt;
  ]]&lt;br /&gt;
function p.tabulateDataWikitext(frame)&lt;br /&gt;
&lt;br /&gt;
    local output&lt;br /&gt;
    local i = 1&lt;br /&gt;
    -- output table&lt;br /&gt;
    output = '{| class=&amp;quot;wikitable sortable mw-datatable&amp;quot; style=&amp;quot;text-align:right;&amp;quot; '    -- table&lt;br /&gt;
    output = '|-class=wrap'&lt;br /&gt;
    output = output                                                        --headers (top row)&lt;br /&gt;
              .. '\n!rowspan=2|#'&lt;br /&gt;
              .. '\n!rowspan=2|Country'&lt;br /&gt;
              .. '\n!rowspan=2|Projected population&amp;lt;br/&amp;gt;(' .. data['dates']['today'] .. ')' &lt;br /&gt;
              .. '\n!rowspan=2|Pct of&amp;lt;br/&amp;gt;total'&lt;br /&gt;
              .. '\n!colspan=2|UN Population estimates'&lt;br /&gt;
              .. '\n!colspan=2|Annual growth'&lt;br /&gt;
              .. '\n!rowspan=2|Doubling time&amp;lt;br/&amp;gt;(years)'&lt;br /&gt;
            &lt;br /&gt;
              .. '\n|-'                                                    -- headers (second row)&lt;br /&gt;
              .. '\n!' .. data.dates['latest'] &lt;br /&gt;
              .. '\n!' .. data.dates['previous'] &lt;br /&gt;
              .. '\n!Increment'&lt;br /&gt;
              .. '\n!Rate'                  &lt;br /&gt;
    &lt;br /&gt;
    while (data[i]) do                                                     -- add rows&lt;br /&gt;
       output = output .. '\n|-\n|' ..  i &lt;br /&gt;
       output = output .. '\n|style=&amp;quot;text-align:left;&amp;quot; |' .. frame:expandTemplate{ title = &amp;quot;flaglist+link&amp;quot;, args = {'Demographics of', data[i]['country'] }  }&lt;br /&gt;
       output = output .. '\n| ' .. mm._precision_format(data[i]['populationProjected'],0)  &lt;br /&gt;
       output = output .. '\n| ' .. mm._precision_format(data[i]['populationProjected']/data.total['projected']*100,2) .. &amp;quot;%&amp;quot; -- projected&lt;br /&gt;
       output = output .. '\n| ' .. data[i]['populationString'] &lt;br /&gt;
       output = output .. '\n| ' .. data[i]['populationString2'] &lt;br /&gt;
       output = output .. '\n| ' .. mm._precision_format(data[i]['populationIncrement'],0) &lt;br /&gt;
       output = output .. '\n| ' .. mm._round(data[i]['populationGrowth']*100,2) .. &amp;quot;%&amp;quot;&lt;br /&gt;
       output = output .. '\n| ' .. mm._round(data[i]['populationDouble'],0)&lt;br /&gt;
       i=i+1&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    local newcell = '\n! style=&amp;quot;text-align:right;&amp;quot; | '    &lt;br /&gt;
    output = output .. '\n|-'                                              -- totals row&lt;br /&gt;
        .. '\n! !! Total' &lt;br /&gt;
        .. newcell .. fn.formatNum(mm._round(data.total['projected'],0),&amp;quot;en&amp;quot;,0) &lt;br /&gt;
        .. newcell .. '100%'&lt;br /&gt;
        .. newcell .. fn.formatNum(data.total['latest'],&amp;quot;en&amp;quot;,0) &lt;br /&gt;
        .. newcell .. fn.formatNum(data.total['previous'],&amp;quot;en&amp;quot;,0) &lt;br /&gt;
        .. newcell .. fn.formatNum(data.total['latest']-data.total['previous'],&amp;quot;en&amp;quot;,0)&lt;br /&gt;
        .. newcell .. fn.formatNum((data.total['latest']-data.total['previous'])/data.total['previous']*100,&amp;quot;en&amp;quot;,2)..&amp;quot;%&amp;quot;&lt;br /&gt;
        .. newcell .. mm._precision_format(p.getPopulationDoubleTime(data.total['latest'],data.total['previous']),0)&lt;br /&gt;
                                 &lt;br /&gt;
    output = output .. '\n|}'&lt;br /&gt;
    return output&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[ output table of data as use Lua HTML Library&lt;br /&gt;
]]&lt;br /&gt;
function p.tabulateData(frame)&lt;br /&gt;
    &lt;br /&gt;
    local hideYearsCols = false&lt;br /&gt;
    if args['hide_years'] == &amp;quot;true&amp;quot; then hideYearsCols = true end -- note the frame argument is a string, not a boolean&lt;br /&gt;
    local doublingFootnote = args['doubling_note'] or &amp;quot;&amp;quot;&lt;br /&gt;
    local growthFootnote = args['growth_note'] or &amp;quot;&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    local i = 1&lt;br /&gt;
    local static = mw.html.create('table'):addClass('wikitable')&lt;br /&gt;
                                         &lt;br /&gt;
    static:tag('tr'):tag('th'):attr('rowspan', 1):wikitext('&amp;lt;br/&amp;gt;'):cssText('border-bottom-color:#eaecf0;')&lt;br /&gt;
    static:tag('tr'):tag('th'):wikitext('&amp;lt;br/&amp;gt;'):cssText('border-top-color:#eaecf0;')&lt;br /&gt;
    while (data[i]) do                                                     -- add rows&lt;br /&gt;
		static:tag('tr'):tag('td'):wikitext(i)&lt;br /&gt;
		i=i+1&lt;br /&gt;
	end&lt;br /&gt;
    static:tag('tr'):tag('th'):wikitext('&amp;lt;br/&amp;gt;')&lt;br /&gt;
    local numRows=i-1&lt;br /&gt;
&lt;br /&gt;
    local tbl = mw.html.create('table'):addClass('wikitable')             -- start table&lt;br /&gt;
                                       :addClass('sortable')&lt;br /&gt;
                                       :addClass('mw-datatable')&lt;br /&gt;
                                       :addClass('static-row-numbers')   -- prefix with row numbers using css and templatestyles&lt;br /&gt;
--									   :addClass('nowrap')&lt;br /&gt;
                                       :css('text-align','right')&lt;br /&gt;
                                       &lt;br /&gt;
    local row = tbl:tag('tr')                                             -- header row&lt;br /&gt;
                   :addClass('static-row-header')                                -- for templatestyles in some skins&lt;br /&gt;
			--:tag('th'):attr('rowspan', 2):wikitext('#')&lt;br /&gt;
	row	    :tag('th'):attr('rowspan', 2):wikitext('Country')&lt;br /&gt;
			:tag('th'):attr('rowspan', 2):wikitext('Projected population&amp;lt;br/&amp;gt;(' .. data['dates']['today'] .. ')' )&lt;br /&gt;
		    :tag('th'):attr('rowspan', 2):wikitext('Pct of&amp;lt;br/&amp;gt;total')&lt;br /&gt;
    if not hideYearsCols then&lt;br /&gt;
		row :tag('th'):attr('colspan', 2):wikitext('UN Population estimates')&lt;br /&gt;
	end&lt;br /&gt;
	row	    :tag('th'):attr('colspan', 2):wikitext('Annual growth'..growthFootnote)&lt;br /&gt;
		    :tag('th'):attr('rowspan', 2):wikitext('Doubling time&amp;lt;br/&amp;gt;(years)'..doublingFootnote)&lt;br /&gt;
    &lt;br /&gt;
    row = tbl:tag('tr')                                                    -- headers (second row)&lt;br /&gt;
             :addClass('static-row-header')                                -- for templatestyles in some skins&lt;br /&gt;
    if not hideYearsCols then&lt;br /&gt;
		row :tag('th'):wikitext(data.dates['latest'] )&lt;br /&gt;
		    :tag('th'):wikitext(data.dates['previous'] )&lt;br /&gt;
    end&lt;br /&gt;
	row		:tag('th'):wikitext('Increment')&lt;br /&gt;
		    :tag('th'):wikitext('Rate')     &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
    i = 1&lt;br /&gt;
    while (data[i]) do                                                     -- add country rows&lt;br /&gt;
		&lt;br /&gt;
		local row=tbl:tag('tr') &lt;br /&gt;
		--row :tag('td'):wikitext(i)  &lt;br /&gt;
		row		:tag('td'):cssText(&amp;quot;text-align:left;&amp;quot;)&lt;br /&gt;
			              :wikitext( frame:expandTemplate{ title = &amp;quot;flaglist+link&amp;quot;, args = { 'Demographics of', data[i]['country'] } } )&lt;br /&gt;
				:tag('td'):wikitext( mm._precision_format(data[i]['populationProjected'],0)  )&lt;br /&gt;
				:tag('td'):wikitext( mm._precision_format(data[i]['populationProjected']/data.total['projected']*100,2) .. &amp;quot;%&amp;quot; ) -- % of projected &lt;br /&gt;
		if not hideYearsCols then&lt;br /&gt;
			row	:tag('td'):wikitext( data[i]['populationString'] )&lt;br /&gt;
				:tag('td'):wikitext( data[i]['populationString2'] )&lt;br /&gt;
		end&lt;br /&gt;
		row		:tag('td'):wikitext( mm._precision_format(data[i]['populationIncrement'],0) )&lt;br /&gt;
				:tag('td'):wikitext( mm._precision_format(data[i]['populationGrowth']*100,2) .. &amp;quot;%&amp;quot; )&lt;br /&gt;
				:tag('td'):wikitext( mm._precision_format(data[i]['populationDouble'],0) )&lt;br /&gt;
		i=i+1&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    local style = { ['text-align']='right' }    &lt;br /&gt;
    row = tbl:tag('tr')                                             -- totals row&lt;br /&gt;
            :addClass('static-row-header')                                -- for templatestyles in some skins&lt;br /&gt;
		    --:tag('th')           :wikitext()&lt;br /&gt;
	row	    :tag('th')           :wikitext('Total')&lt;br /&gt;
		    :tag('th'):css(style):wikitext( fn.formatNum(mm._round(data.total['projected'],0),&amp;quot;en&amp;quot;,0) ) &lt;br /&gt;
		    :tag('th'):css(style):wikitext( '100%' )&lt;br /&gt;
	if not hideYearsCols then&lt;br /&gt;
	   row  :tag('th'):css(style):wikitext( fn.formatNum(data.total['latest'],  &amp;quot;en&amp;quot;,0) )&lt;br /&gt;
		    :tag('th'):css(style):wikitext( fn.formatNum(data.total['previous'],&amp;quot;en&amp;quot;,0) )&lt;br /&gt;
	end&lt;br /&gt;
	row		:tag('th'):css(style):wikitext( fn.formatNum(data.total['latest']  - data.total['previous'],&amp;quot;en&amp;quot;,0) )&lt;br /&gt;
		    :tag('th'):css(style):wikitext( fn.formatNum((data.total['latest'] - data.total['previous']) / data.total['previous'] * 100,&amp;quot;en&amp;quot;,2)..&amp;quot;%&amp;quot; )&lt;br /&gt;
		    :tag('th'):css(style):wikitext( mm._precision_format(p.getPopulationDoubleTime(data.total['latest'],data.total['previous']),0) )&lt;br /&gt;
	                             &lt;br /&gt;
    -- return tostring(tbl) -- return table without row numbers&lt;br /&gt;
    &lt;br /&gt;
    -- use separate column for static row numbers&lt;br /&gt;
    -- return '{|\n|style=&amp;quot;vertical-align:top;&amp;quot; |' .. tostring(static) .. '\n|' .. tostring(tbl) .. '\n|}'&lt;br /&gt;
    &lt;br /&gt;
    -- use css method and templatestyles to prefix row numbers&lt;br /&gt;
    return p.templateStyle( frame, &amp;quot;Template:Static_row_numbers/styles.css&amp;quot; ) .. tostring(tbl)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[  currently the main entry function&lt;br /&gt;
         takes list of country codes&lt;br /&gt;
         gets population data from &amp;quot;List of countries by population (United Nations)&amp;quot;&lt;br /&gt;
         outputs sorted table&lt;br /&gt;
  ]]&lt;br /&gt;
function p.populations(frame) -- entru point for invoke (uses frame arguments)&lt;br /&gt;
    &lt;br /&gt;
    args = frame.args  --TODO handle parent args for template&lt;br /&gt;
    return p._populations(frame)&lt;br /&gt;
end&lt;br /&gt;
function p._populations(frame)&lt;br /&gt;
   &lt;br /&gt;
    local page = &amp;quot;List of countries by population (United Nations)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
	local title = mw.title.new( page) -- , ns)  -- creates object if page doesn't exist (and valid page name)&lt;br /&gt;
	                                            --TODO: could use mw.title.makeTitle(), but that needs ns&lt;br /&gt;
    local output = &amp;quot;&amp;quot;&lt;br /&gt;
	if title and title.exists then &lt;br /&gt;
		local content = title:getContent()&lt;br /&gt;
&lt;br /&gt;
        if not p.getPopulationData(frame) then&lt;br /&gt;
        	return p.errormsg(&amp;quot;Error retrieving data.&amp;quot;)&lt;br /&gt;
        end&lt;br /&gt;
		&lt;br /&gt;
		p.sortPopulationData(&amp;quot;latest&amp;quot;)&lt;br /&gt;
        &lt;br /&gt;
        --output =  p.tabulateDataWikitext(frame) -- version building table with Wikitext&lt;br /&gt;
        output =  p.tabulateData(frame)           -- version building table with mw.html library&lt;br /&gt;
        &lt;br /&gt;
    else&lt;br /&gt;
    	return  '&amp;lt;span class=&amp;quot;error&amp;quot;&amp;gt;No page title found&amp;lt;/span&amp;gt;'&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
    local test = &amp;quot;test: &amp;quot; &lt;br /&gt;
	local number=5435.12345 &lt;br /&gt;
	test= 	fn.formatNum(5435.12345,&amp;quot;en&amp;quot;,0)&lt;br /&gt;
	--test=   frame:expandTemplate{ title = &amp;quot;formatnum&amp;quot;, args = { totalProjected ,&amp;quot;en&amp;quot;,0 } }&lt;br /&gt;
	--test=frame:callParserFunction{ name = 'formatnum', args = { totalProjected, decs=2 } }   &lt;br /&gt;
   &lt;br /&gt;
   &lt;br /&gt;
   return output            --.. test&lt;br /&gt;
end&lt;br /&gt;
-- function for pie chart&lt;br /&gt;
function p.piechart(frame)&lt;br /&gt;
    &lt;br /&gt;
    args = frame.args  --TODO handle parent args for template&lt;br /&gt;
    return p._piechart(frame)&lt;br /&gt;
end&lt;br /&gt;
function p._piechart(frame)&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
    local page = &amp;quot;List of countries by population (United Nations)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
	local title = mw.title.new( page) -- , ns)  -- creates object if page doesn't exist (and valid page name)&lt;br /&gt;
	                                            --TODO: could use mw.title.makeTitle(), but that needs ns&lt;br /&gt;
    local output = &amp;quot;&amp;quot;&lt;br /&gt;
	if title and title.exists then &lt;br /&gt;
		local content = title:getContent()&lt;br /&gt;
&lt;br /&gt;
        if not p.getPopulationData(frame) then&lt;br /&gt;
        	return p.errormsg(&amp;quot;Error retrieving data.&amp;quot;)&lt;br /&gt;
        end&lt;br /&gt;
		&lt;br /&gt;
		p.sortPopulationData(&amp;quot;latest&amp;quot;)&lt;br /&gt;
        &lt;br /&gt;
        --output =  p.tabulateDataWikitext(frame) -- version building table with Wikitext&lt;br /&gt;
        output =  p.makePieChart(frame)           -- version building table with mw.html library&lt;br /&gt;
        &lt;br /&gt;
    else&lt;br /&gt;
    	return  '&amp;lt;span class=&amp;quot;error&amp;quot;&amp;gt;No page title found&amp;lt;/span&amp;gt;'&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
   &lt;br /&gt;
   return output            --.. test&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.makePieChart(frame)   &lt;br /&gt;
   &lt;br /&gt;
   --local args=frame.args&lt;br /&gt;
   local templateArgs = {}&lt;br /&gt;
   &lt;br /&gt;
   templateArgs['caption'] = args['caption'] or &amp;quot;&amp;quot; --'South American population by country'  --.. ' (top 8)'&lt;br /&gt;
   templateArgs['thumb'] = args['thumb'] or &amp;quot;right&amp;quot;&lt;br /&gt;
   templateArgs['other'] = args['other'] or nil&lt;br /&gt;
   local maxSlices = tonumber(args['slices']) -- nil if not a number&lt;br /&gt;
   if type(maxSlices) ~= &amp;quot;number&amp;quot; or maxSlices &amp;gt; 30 or maxSlices &amp;lt; 1 then&lt;br /&gt;
	   maxSlices = 30 -- limit of template                                -- get number from data&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
   &lt;br /&gt;
   local i=1&lt;br /&gt;
   while data[i] and i &amp;lt;= maxSlices do&lt;br /&gt;
	   --templateArgs['label'..i] = data[i]['country'] &lt;br /&gt;
	   templateArgs['label'..i] = mw.getCurrentFrame():expandTemplate{ title = &amp;quot;getalias&amp;quot;, args = { data[i]['country'], raw='y', 'shortname' } }&lt;br /&gt;
	   templateArgs['value'..i] = mm._round( data[i]['populationNumber']/data.total['latest']*100,1)&lt;br /&gt;
	   templateArgs['color'..i] = args['color'..i] or nil&lt;br /&gt;
	   i=i+1&lt;br /&gt;
   end&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
--[[{{Pie chart&lt;br /&gt;
|caption= South American population by country (top 8)&lt;br /&gt;
|other = yes&lt;br /&gt;
|label1 = {{getalias|BRA}}&lt;br /&gt;
|value1 = {{#expr: {{country population|BRA|raw=y}} / {{xyz|Total}} * 100 round 1}}&lt;br /&gt;
|label2 = {{getalias|COL}}&lt;br /&gt;
|value2 = {{#expr: {{country population|COL|raw=y}} / {{xyz|Total}} * 100 round 1}}&lt;br /&gt;
|label3 = {{getalias|ARG}}&lt;br /&gt;
|value3 = {{#expr: {{country population|ARG|raw=y}} / {{xyz|Total}} * 100 round 1}}&lt;br /&gt;
|label4 = {{getalias|PER}}&lt;br /&gt;
|value4 = {{#expr: {{country population|PER|raw=y}} / {{xyz|Total}} * 100 round 1}}&lt;br /&gt;
|label5 = {{getalias|VEN}}&lt;br /&gt;
|value5 = {{#expr: {{country population|VEN|raw=y}} / {{xyz|Total}} * 100 round 1}}&lt;br /&gt;
|label6 = {{getalias|CHL}}&lt;br /&gt;
|value6 = {{#expr: {{country population|CHL|raw=y}} / {{xyz|Total}} * 100 round 1}}&lt;br /&gt;
|label7 = {{getalias|ECU}}&lt;br /&gt;
|value7 = {{#expr: {{country population|ECU|raw=y}} / {{xyz|Total}} * 100 round 1}}&lt;br /&gt;
|label8 = {{getalias|BOL}}&lt;br /&gt;
|value8 = {{#expr: {{country population|BOL|raw=y}} / {{xyz|Total}} * 100 round 1}}&lt;br /&gt;
}}  ]] &lt;br /&gt;
   &lt;br /&gt;
   local chart = mw.getCurrentFrame():expandTemplate{ title = &amp;quot;Pie chart&amp;quot;, args = templateArgs  }&lt;br /&gt;
   &lt;br /&gt;
   return chart&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function p.firstToUpper(str)&lt;br /&gt;
    return (str:gsub(&amp;quot;^%l&amp;quot;, string.upper))&lt;br /&gt;
end&lt;br /&gt;
p.errormsg = function (message)&lt;br /&gt;
	return '&amp;lt;span class=&amp;quot;error&amp;quot;&amp;gt;' .. message .. '&amp;lt;/span&amp;gt;' &lt;br /&gt;
end	&lt;br /&gt;
&lt;br /&gt;
-- Test why was the sort being applied to the wrong level? Fixed &lt;br /&gt;
function p.test(frame) -- meant test()&lt;br /&gt;
&lt;br /&gt;
    local tbl = mw.html.create('table'):addClass('wikitable'):addClass('sortable'):addClass('mw-datatable')&lt;br /&gt;
                                                   :css('text-align','right')&lt;br /&gt;
    &lt;br /&gt;
    tbl:tag('tr')                                             -- header row&lt;br /&gt;
		:tag('th'):attr('rowspan', 2):wikitext('#')&lt;br /&gt;
		:tag('th'):attr('rowspan', 2):wikitext('A')&lt;br /&gt;
	    :tag('th'):attr('rowspan', 2):wikitext('B')&lt;br /&gt;
	    :tag('th'):attr('colspan', 2):wikitext('C+D'):addClass('unsortable')&lt;br /&gt;
	    :tag('th'):attr('colspan', 2):wikitext('E+F'):addClass('unsortable')&lt;br /&gt;
	    :tag('th'):attr('rowspan', 2):wikitext('G')&lt;br /&gt;
    &lt;br /&gt;
    tbl:tag('tr')                                                    -- headers (second row)&lt;br /&gt;
	    :tag('th'):wikitext('C'):addClass('sortable')&lt;br /&gt;
	    :tag('th'):wikitext('D'):addClass('sortable')&lt;br /&gt;
	    :tag('th'):wikitext('E'):addClass('sortable')&lt;br /&gt;
	    :tag('th'):wikitext('F')   :addClass('sortable')  &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
    local i = 1&lt;br /&gt;
    while (i&amp;lt;5) do                                                     -- add rows&lt;br /&gt;
		tbl:tag('tr') &lt;br /&gt;
			:tag('td'):wikitext(i)  &lt;br /&gt;
			:tag('td'):wikitext(&amp;quot;A&amp;quot;..i)&lt;br /&gt;
			:tag('td'):wikitext(&amp;quot;B&amp;quot;..i)&lt;br /&gt;
			:tag('td'):wikitext(tostring(math.fmod(5-i,2)) .. 'C' .. i )&lt;br /&gt;
			:tag('td'):wikitext(&amp;quot;D&amp;quot;..i)&lt;br /&gt;
			:tag('td'):wikitext(&amp;quot;E&amp;quot;..i)&lt;br /&gt;
			:tag('td'):wikitext(tostring(math.fmod(5-i,2)) .. 'F' .. i )&lt;br /&gt;
			:tag('td'):wikitext(&amp;quot;G&amp;quot;..i)&lt;br /&gt;
		i=i+1&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    local output = '{| class=&amp;quot;wikitable sortable mw-datatable&amp;quot; style=&amp;quot;text-align:right;&amp;quot; '    -- table&lt;br /&gt;
    output = output&lt;br /&gt;
              .. '\n!rowspan=2|#'&lt;br /&gt;
              .. '\n!rowspan=2|A'&lt;br /&gt;
              .. '\n!rowspan=2|B' &lt;br /&gt;
              .. '\n!colspan=2|C+D'&lt;br /&gt;
              .. '\n!colspan=2|E+F'&lt;br /&gt;
              .. '\n!rowspan=2|G'&lt;br /&gt;
            &lt;br /&gt;
              .. '\n|-'                                                    -- headers (second row)&lt;br /&gt;
              .. '\n!C' &lt;br /&gt;
              .. '\n!D' &lt;br /&gt;
              .. '\n!E'&lt;br /&gt;
              .. '\n!F'                  &lt;br /&gt;
    i=1&lt;br /&gt;
    while (i&amp;lt;5) do                                                     -- add rows&lt;br /&gt;
       output = output .. '\n|-\n|' ..  i &lt;br /&gt;
       output = output .. '\n|A' .. i &lt;br /&gt;
       output = output .. '\n|B' .. i&lt;br /&gt;
       output = output .. '\n|' .. tostring(math.fmod(5-i,2)) .. 'C' .. i &lt;br /&gt;
       output = output .. '\n|D' .. i &lt;br /&gt;
       output = output .. '\n|E' .. i &lt;br /&gt;
       output = output .. '\n|' .. tostring(math.fmod(5-i,2)) .. 'F' .. i &lt;br /&gt;
       output = output .. '\n|G' .. i&lt;br /&gt;
       i=i+1&lt;br /&gt;
    end&lt;br /&gt;
    output = output .. '\n|}'&lt;br /&gt;
&lt;br /&gt;
    return output .. tostring(tbl)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- function for static rank column&lt;br /&gt;
&lt;br /&gt;
function p.rank(frame)&lt;br /&gt;
&lt;br /&gt;
	--args = frame.args           -- for module TODO allow invoke to work&lt;br /&gt;
	args = frame:getParent().args -- parent arguments for template&lt;br /&gt;
	args = frame.args -- invoke arguments for template&lt;br /&gt;
	&lt;br /&gt;
	local caption         = args['caption']          &lt;br /&gt;
	local valign          = args['valign'] or &amp;quot;top&amp;quot;&lt;br /&gt;
	local rowHeader       = args['row-header'] &lt;br /&gt;
	local headerPadding   = args['header-padding'] or &amp;quot;0px&amp;quot;&lt;br /&gt;
	local textAlign       = args['text-align'] or &amp;quot;right&amp;quot;&lt;br /&gt;
	local style           = args['style'] or &amp;quot;&amp;quot;&lt;br /&gt;
	local headerHeight    = args['header-height'] or &amp;quot;&amp;quot;&lt;br /&gt;
	local headerLines     = args['header-lines']  or 1&lt;br /&gt;
	local headerText      = args['header-text'] or &amp;quot;&amp;quot;&lt;br /&gt;
	local rows            = tonumber(args['rows']) or 0&lt;br /&gt;
	local rowHeader       = args['row-header'] &lt;br /&gt;
	local rowHeight       = args['row-height'] &lt;br /&gt;
	&lt;br /&gt;
	local marginRight = &amp;quot;0px&amp;quot;&lt;br /&gt;
	if rowHeader then marginRight = &amp;quot;-8px&amp;quot; end&lt;br /&gt;
	local headerValign    = &amp;quot;bottom&amp;quot;&lt;br /&gt;
	if rowHeader then headerValign = &amp;quot;center&amp;quot; end     -- copied from template; should be middle?&lt;br /&gt;
	local linebreaks = &amp;quot;&amp;quot;&lt;br /&gt;
	if headerLines then&lt;br /&gt;
		local i=0&lt;br /&gt;
		while i&amp;lt;tonumber(headerLines) do&lt;br /&gt;
			linebreaks = linebreaks ..  &amp;quot;&amp;lt;br /&amp;gt;&amp;quot;&lt;br /&gt;
			i=i+1&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
{| &lt;br /&gt;
|+'''{{{caption| }}}'''&lt;br /&gt;
| valign={{{valign|top}}} |&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-right:{{#if:{{{row-header|}}}|-8px|0px}}; padding:{{{header-padding|0px}}}; text-align:{{{text-align|right}}};{{{style|}}}&amp;quot;&lt;br /&gt;
! style=height:{{{header-height|}}} valign={{{header-valign|{{#if: {{{row-header|}}} | center | bottom}}}}} | {{#if:{{{header-lines|}}}|{{repeat|{{#expr:{{{header-lines}}}-1}}|&amp;lt;br&amp;gt;}}}}{{{header-text|}}}&lt;br /&gt;
]]&lt;br /&gt;
    local heightClass = &amp;quot;static-rank-col&amp;quot;&lt;br /&gt;
    if rowHeight and rowHeight == &amp;quot;large&amp;quot; then&lt;br /&gt;
    	heightClass = &amp;quot;static-rank-col-large&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
	local output =      '\n{| class=&amp;quot;'..heightClass..'&amp;quot;'                                                          --start static rank table&lt;br /&gt;
    if caption then&lt;br /&gt;
    	output = output  .. &amp;quot;\n|+'''&amp;quot; .. caption .. &amp;quot;'''&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    output = output  .. '\n|valign=' .. valign .. ' |'&lt;br /&gt;
        	    	 .. '\n{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-right:'..marginRight&lt;br /&gt;
                    		                      ..'; padding:'..headerPadding&lt;br /&gt;
                            		              ..'; text-align:'..textAlign &lt;br /&gt;
                                    		      ..';'.. style&lt;br /&gt;
        		     .. '\n! style=&amp;quot;height:'..headerHeight..';&amp;quot; valign=&amp;quot;'..headerValign ..';&amp;quot; | ' &lt;br /&gt;
            		 ..  linebreaks .. headerText&lt;br /&gt;
&lt;br /&gt;
--[[ {{#ifexpr:{{{rows}}}=0|&amp;lt;br /&amp;gt;&lt;br /&gt;
{{end}}}}{{#ifexpr:{{{rows}}}&amp;gt;=1|{{Static column row |row-height={{{row-height|}}} |number=1 |row-header={{{row-header| }}} }}}}{{#ifexpr:{{{rows}}}=1|&amp;lt;br /&amp;gt;&lt;br /&gt;
{{end}}}}{{#ifexpr:{{{rows}}}&amp;gt;=2|{{Static column row |row-height={{{row-height|}}} |number=2 |row-header={{{row-header| }}} }}}}{{#ifexpr:{{{rows}}}=2|&amp;lt;br /&amp;gt;&lt;br /&gt;
{{end}}}&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
	local i=0&lt;br /&gt;
	while i&amp;lt;rows do&lt;br /&gt;
		i=i+1&lt;br /&gt;
	    --output = output .. '\n|-\n|' .. tostring(i)           -- simple unformatted version&lt;br /&gt;
	    &lt;br /&gt;
--[[	    &amp;lt;br /&amp;gt;&lt;br /&gt;
|- {{#if: {{{row-height|}}}|style=&amp;quot;height:{{{row-height|}}}&amp;quot;|}}&lt;br /&gt;
{{#if: {{{row-header|}}} | ! | {{!}} }} {{{number}}}&lt;br /&gt;
]] &lt;br /&gt;
                                                          -- version emulating Template:Static column row                                                &lt;br /&gt;
          local rowStyle = &amp;quot;&amp;quot;&lt;br /&gt;
          if rowHeight then rowStyle  = 'style=&amp;quot;height:'..rowHeight..';&amp;quot; |' end&lt;br /&gt;
          local cellType = &amp;quot;|&amp;quot;&lt;br /&gt;
          if rowHeader then cellType = &amp;quot;!&amp;quot; end&lt;br /&gt;
          output = output .. '\n|-' .. rowStyle &lt;br /&gt;
                          .. '\n' .. cellType .. tostring(i) .. '&amp;lt;br /&amp;gt;'&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	output = output .. '\n|}'                                                      -- close the static rank table&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	output = output .. '\n|'     -- new cell for the main table&lt;br /&gt;
&lt;br /&gt;
	--output = output .. '\n|}'  -- unnecessary: the table will be closed with an {{end}} template&lt;br /&gt;
&lt;br /&gt;
	return p.templateStyle( frame, &amp;quot;Static column begin/styles.css&amp;quot; ) .. output&lt;br /&gt;
	&lt;br /&gt;
end&lt;br /&gt;
function p.templateStyle( frame, src )&lt;br /&gt;
   return frame:extensionTag( 'templatestyles', '', { src = src } );&lt;br /&gt;
end&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>Zoran</name></author>
	</entry>
</feed>