Modul:Benutzer:Count Count/Wikidata helper

Die Dokumentation für dieses Modul kann unter Modul:Benutzer:Count Count/Wikidata helper/Doku erstellt werden

p = {}

--[[

This modules include help functionality for Wikidata that are not primarily used in articles directly or in templates, but rather talk and project pages.

]]

function tablesize(T)
   local n = 0
   for _ in pairs(T) do n = n + 1 end
   return n
end

--[[
  wdmatrix, creates a table with links to articles for given wikidata items on given languages
  and the number of languages that has link to the items
  parameters
  ==========
  objects: (mandatory) a comma separated list of qids 
  langs: (mandatory) a comma separated list of language codes
  
  example
  =======
  {{#invoke:Wikidatahelper|wdmatrix|objects=Q210723,Q187140,Q2100893,Q18451251,Q4876106,Q4876107,Q16839444,Q386215|langs=en,es,de,sv}} 
]]

function p.wdmatrix(frame)
	local langs = frame.args['langs'] 
	local langstable = {}
	if langs then langstable = mw.text.split(langs,',') end
	local nlangs = tablesize(langstable)

	local objs = frame.args['objects']
	local objstable = {}
	if objs then objstable = mw.text.split(objs,',') end
	local nobjs = tablesize(objstable)

	local sitelinks = {}
	local res = '{| class="wikitable"\n|-\n'
	res = res .. '!colspan=2| !!colspan=' .. nlangs+1 .. '|Languages\n|-\n!Wikidata items||Label||#'
	for j = 1,nlangs do res = res .. '!!' .. langstable[j] .. 'wiki' end
	for i = 1,nobjs do
		local entity = mw.wikibase.getEntity(objstable[i]);
		if entity then
           	local n = 0
           	if entity.sitelinks then n = tablesize(entity.sitelinks) end
      		res = res .. '\n|-\n'

			res = res .. '| [[:d:' .. objstable[i] .. ']] || ' .. (entity:getLabel() or '-') .. ' || align="right" |' .. n
      		for j = 1,nlangs do
       			local link = '-'
       			if entity.sitelinks then
       				for _, q in pairs(entity.sitelinks) do
	  				 	if q.site == langstable[j]..'wiki' then
	  				 		link = '[[:' .. langstable[j] .. ':' .. entity:getSitelink(q.site) .. '|' .. entity:getSitelink(q.site) .. ']]'
	  					 end
	  				end
	  			end
	  			res = res .. '||' .. link
			end 
	  	end
	end
	res = res .. '\n|}'
	return res
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.