Модул:Игралиште/Милан Јелисавчић/СписакДобитника

Документацију овог модула можете да направите на страници Модул:Игралиште/Милан Јелисавчић/СписакДобитника/док

-- WikimediaCEETable: builds a list of articles based on information from Wikidata
-- Sample use: {{#invoke:WikimediaCEETable|table|Q1|Q2|Q3|Q4|Q5}}
-- Can be used to list 400+ articles on 1 page
-- by User:Voll, with additions by Halibutt, Braveheart, Jura1, Strainu, Yupik
-- Original at https://meta.wikimedia.org/wiki/Module:WikimediaCEETable. Please contribute amendments there and keep copies in sync with that version.
--
local langTable = { 'sr' }

local p = {}

local function def(bla)
  local zdef = {}
  for _, l in ipairs(bla) do zdef[l] = true end
  return zdef
end

local function femico(wdata)
	local cl
	if wdata.claims then
		cl = wdata.claims["P21"]
	end
	if (cl and 
		cl[1] and 
		cl[1].mainsnak.snaktype == "value" and
		cl[1].mainsnak.datavalue.type == "wikibase-entityid" and 
		cl[1].mainsnak.datavalue.value["numeric-id"] and 
		(cl[1].mainsnak.datavalue.value["numeric-id"] == 6581072 or cl[1].mainsnak.datavalue.value["numeric-id"] == 1052281)) then
		return ' [[File:Female Icon.svg|link=|18px]]'
	else
		return ''
	end
end

local function humanyears(wdata)
	local cl
	if wdata.claims then
		cl = wdata.claims["P31"]
	end
	if (cl and 
		cl[1] and 
		cl[1].mainsnak.snaktype == "value" and 
		cl[1].mainsnak.datavalue.type == "wikibase-entityid" and 
		cl[1].mainsnak.datavalue.value["numeric-id"] and 
		cl[1].mainsnak.datavalue.value["numeric-id"] == 5) then
		local yr = "%d%d%d%d$"
		local p569 = wdata:formatPropertyValues( 'P569' ).value
		if p569 ~= "" then
			if p569:match(yr) ~= nil then
				p569 = p569:match(yr)
			end
			local p570 = wdata:formatPropertyValues( 'P570' ).value
			if p570 ~= "" then
				if p570:match(yr) ~= nil then
					p570 = p570:match(yr)
				end
				return ' <span style="font-size:smaller;font-weight:100">(' .. p569 .. '-' .. p570 .. ')</span> '
			else
				return ' <span style="font-size:smaller;font-weight:100">(b. ' .. p569 .. ')</span>'
			end
		else
			return ' <span style="font-size:smaller;font-weight:100">(?)</span>'
		end
	else
		return ''
	end
end

local function foccupation(wdata)
	local cl
	if wdata.claims then
		cl = wdata.claims["P106"]
	end
	if (cl and 
		cl[1] and 
		cl[1].mainsnak.snaktype == "value" and 
		cl[1].mainsnak.datavalue.type == "wikibase-entityid" and 
		cl[1].mainsnak.datavalue.value["id"]) then
		entity2 = mw.wikibase.getEntityObject(cl[1].mainsnak.datavalue.value["id"])
		local occupation = entity2:getLabel('sr')
		return ' \n| ' .. occupation
	else
		return '\n| - '
	end
end

local function fimage(wdata)
	local cl
	if wdata.claims then
		cl = wdata.claims["P18"]
	end
	if (cl and 
		cl[1] and 
		cl[1].mainsnak.snaktype == "value" and 
		cl[1].mainsnak.datatype == "commonsMedia" and 
		cl[1].mainsnak.datavalue.value) then
		entity2 = cl[1].mainsnak.datavalue.value
		return ' \n| ' .. '[[File:' .. entity2 .. '|64px]]'
	else
		return '\n| '
	end
end

local function fwikidata(wid)
	wid = string.gsub(wid, "\n", "")
	mw.log(wid)
	return ' \n| ' .. '[[d:' .. wid .. '|' .. wid .. ']]'
end

function p.table(frame)
	-- header/init
	header = {'{| class="wikitable sortable" width=100%\n|-\n! Бр. ',
		'!! style="width:18%"|Чланак ',
		'!! class="unsortable" style="width:64px"|Слика ',
		'!! Књига ',
		'!! Википодаци ',
		'!! <span title="број основних изјава на ставци">реф.</span> \n|-'}
	resultTable = table.concat(header);

	index = 1
		
	ctt = {}
	for langCount = 1, #langTable do
		ctt[langCount] = 0
	end
	
	-- TODO
	statementst = 0
	coords = 0
	images = 0
	wqsitems = ""
	qids = ""
	timeline = 0
	mylang = frame:preprocess('{{int:lang}}')
	
	-- rows
	while frame.args[index] do
		Id = frame.args[index]
		local entity = mw.wikibase.getEntityObject(Id)
		-- if not entity or not entity.sitelinks then
		if not entity then
			return '<b>Entity ' .. Id .. ' not found</b>'
		end
		Label = entity:getLabel(mylang)
		
		if not Label then
			Label = ''
		end
		
   		local srsitelink = entity:getSitelink( 'srwiki' )
		if srsitelink then
			if Label == '' then
				Label = srsitelink
			end
		end
   	
    	result2 = ''
    	ct = 0
    	wqsitems = wqsitems .. "wd%3A" .. Id .. "%20"
    	qids = qids .. string.sub(Id, 2) .. ","
    	idinternal = def { "P373", "P948", "P935", "P460", "P856", "P910", "P213", "P1343", "P973", "P345", "P227", "P244","P1612", "P1472", "P1325", "P106" }
    	commonsp = def {'P18','P10','P14','P15','P41','P51','P94','P109','P117','P154','P158','P181','P207','P242','P367', 'P373','P443','P491','P692','P935','P948','P989','P990','P996','P1442','P1472','P1543','P1612','P1621','P1766','P1801','P1846','P1943','P1944'}    	
		
		-- image (P18)
		result2 = result2 .. fimage(entity)
		-- occupation (P106)
		result2 = result2 .. foccupation(entity)
		
		-- wikidata
		-- mw.logObject(entity)
		result2 = result2 .. fwikidata(Id)
    	
    	-- columns per row
    	for langCount = 1, #langTable do
	   		local sitelink = entity:getSitelink( langTable[langCount] .. 'wiki' )
			if sitelink then
				iw = langTable[langCount]
				if iw == "be_x_old" then iw = "be-tarask" end
				result2 = result2 .. '\n| style="background:#cfc;"|' .. '[[:' .. iw .. ':' .. sitelink .. '| +]]'
				ct = ct + 1
				ctt[langCount] = ctt[langCount] + 1
				if Label == '' then
					Label = sitelink
				end
			else
				result2 = result2 .. '\n| -'
			end
		end
		
		-- first cells of row
    	result1 = '|-\n|align=right|' .. index .. '\n|'
    	if srsitelink then
    		result1 = result1 .. '[[:sr:' .. srsitelink .. '|' .. Label ..']]'
    	else
    		result1 = result1 .. Label
    	end
		
		-- icon for females (Q6581072 & Q1052281)
		result1 = result1 .. femico(entity)

		local p625 = entity:formatPropertyValues( 'P625' ).value
 		if p625 ~= "" then
				result1 = result1 .. "&nbsp;[[File:Geographylogo.svg|18px|view on maps|link=https://tools.wmflabs.org/geohack/geohack.php?language=en&pagename=" .. mw.uri.encode( Label, "PATH" ) .. "&params=" .. entity.claims.P625[1].mainsnak.datavalue.value.latitude .. "_N_" .. entity.claims.P625[1].mainsnak.datavalue.value.longitude .. "_E]]"
				coords = coords + 1
		end
		local p18 = entity:formatPropertyValues( 'P18' ).value
 		if p18 ~= "" then
				images = images + 1
		end
		
		-- last cells of row
		index = index + 1

		local commons = false
		local statements = 0
		if entity.claims then
			for i, statement in pairs( entity.claims ) do
				if statement then
					if statement[1].mainsnak then
						if not idinternal[i] then
							if statement[1].mainsnak.datatype ~= 'external-id' then
                   				statements = statements+1
                   			end
               			end
               			if commonsp[i] then 
               				commons = true
               			end
					end
				end
			end
		end
		-- local statements = #entity:getProperties()

		-- todo : check for Commons sitelinks
		local commonsstr = ""
		if commons then
			commonsstr = '<span title="Wikidata item includes Commons resources">+</span>'
			-- commonsstr = "[https://commons.wikimedia.org/w/index.php?fulltext=1&search=".. mw.uri.encode( Label, "PATH" ) .. " +]"
		end
		statementst = statementst + statements
		if statements == 0 then
			bgcolor = ''
		else
			bgcolor = 'background:#cfc;'
		end
		resultTable = resultTable .. result1 .. result2  .. '|\n'
	end
	
	resultTable = resultTable .. '\n|}\n'
	return resultTable
end


return p