Modul:HistoricalCountries
Documentația acestui modul poate fi creată la Modul:HistoricalCountries/doc
local p = {}
local wikidata = require('Modul:Wikidata')
local nameAndFlag = require('Modul:NameAndImage')._nameAndImage
local StringUtils = require('Modul:StringUtils')
local TableTools = require('Modul:TableTools')
local getArgs = require('Modul:Arguments').getArgs
local DateUtils = require('Modul:DateUtils')
local EditAtWikidata = require('Modul:EditAtWikidata')
p.displayList = function(frame)
local args = getArgs(frame)
local outerDiv = mw.html.create('div'):addClass('quotebox')
:css('padding', '6px'):css('border', '1px solid #aaa'):css('font-size', '88%'):css('background-color', '#FFFFFF')
if args.align == 'right' then
outerDiv:css('float', 'right'):css('clear', 'right'):css('margin', '0.5em 0 0.8em 1.4em')
elseif args.align == 'center' then
outerDiv:css('margin', 'auto')
else
outerDiv:css('float', 'left'):css('clear', 'left'):css('margin', '0.5em 1.4em 0.8em 0'):css('width', '21.5em')
end
outerDiv:tag('div'):css('background-color', '#FFFFFF'):css('color', 'black')
:css('text-align', 'center'):css('font-size', 'larger'):css('font-weight', 'bold')
:wikitext('Istoria apartenenței statale ' .. EditAtWikidata.displayMessage('P17'))
local mainDiv = outerDiv:tag('div'):css('position', 'relative'):css('text-align', 'left')
:tag('div')
local countryClaims = wikidata.findSortedClaimsForProperty(StringUtils.prependIfMissing({args['q'], 'Q'}), 'P17')
local countryDataList = {}
if countryClaims then
for _,eachCountryClaim in ipairs(countryClaims) do
if eachCountryClaim.type == 'statement' and eachCountryClaim.mainsnak and eachCountryClaim.mainsnak.snaktype == 'value' then
local countryId = eachCountryClaim.mainsnak.datavalue.value['numeric-id']
local endYear = nil
local years = {}
if eachCountryClaim.qualifiers and eachCountryClaim.qualifiers['P580'] and #(eachCountryClaim.qualifiers['P580']) > 0 then
local startTimeQual = eachCountryClaim.qualifiers['P580'][1]
table.insert(years, DateUtils.formatYear(wikidata.extractDateFromClaim(startTimeQual).year))
else
table.insert(years, '')
end
if eachCountryClaim.qualifiers and eachCountryClaim.qualifiers['P582'] and #(eachCountryClaim.qualifiers['P582']) > 0 then
local endTimeQual = eachCountryClaim.qualifiers['P582'][1]
endYear = wikidata.extractDateFromClaim(endTimeQual).year
table.insert(years, DateUtils.formatYear(endYear))
else
table.insert(years, '')
end
local out = nameAndFlag(StringUtils.prependIfMissing({tostring(countryId), 'Q'}), 'P41', endYear and {year=endYear} or nil) .. ' '
local yearsStr = table.concat(TableTools.removeDuplicates(years), '–')
out = out .. ' ' .. yearsStr
if yearsStr and mw.text.trim(yearsStr) ~= '' then
table.insert(countryDataList, out)
end
end
end
mainDiv:wikitext(table.concat(countryDataList, tostring(mw.html.create('br'))))
end
if #countryDataList > 0 then
return tostring(outerDiv)
else
return ''
end
end
return p