Module:Sandbox/RexxS/WdRefs

--[[
Returns a list of all claims and references, if any, from Wikidata

]]

local p = {}

p.seeRefs = function(frame)
	-- look for named parameter qid; if it's blank make it nil
	local qid = frame.args.qid
	if qid and (#qid == 0) then
		qid = nil
	end
	
	-- look for named parameter lang
	-- it should contain a two-character ISO-639 language code
	-- if it's blank fetch the language of the local wiki
	local lang = frame.args.lang
	if (not lang) or (#lang < 2) then
		lang = mw.language.getContentLanguage().code
	end
	
	local result = "{| class='wikitable sortable'\r\n! scope='col' | Property\r\n! scope='col' | Value\r\n"
	local numclaims = 0
	local ent = mw.wikibase.getEntity(qid)
	if ent and ent.claims then
		for k1, v1 in pairs(ent.claims) do
			-- code to look for claims
			numclaims = numclaims + 1
			result = result .. "|-\r\n| " .. (mw.wikibase.getLabel(k1) or "nolabel") .. " || "
			local numvals = 0
			local val = "<pre>\r\n"
			for k2, v2 in pairs(v1) do
				numvals = numvals + 1
				local valtype = v2.mainsnak.datatype
				if valtype == "wikibase-item" then
					local label = "Q" .. v2.mainsnak.datavalue.value["numeric-id"]
					label = mw.wikibase.getLabel("Q" .. v2.mainsnak.datavalue.value["numeric-id"]) or label
					val = val .. k2 .. ". " .. label
				elseif valtype == "string" or valtype == "external-id" or valtype == "url" or valtype == "commonsMedia" then
					val = val .. k2 .. ". " .. v2.mainsnak.datavalue.value
				elseif valtype == "monolingualtext" then
					val = val .. k2 .. ". " .. v2.mainsnak.datavalue.value.text
				else
					val = val .. k2 .. ". <" .. valtype .. "> " .. ent:formatPropertyValues(k1, mw.wikibase.entity.claimRanks).value  -- expand this later
				end	
				if v2.qualifiers then
					val = val .. " -- " .. mw.wikibase.renderSnaks(v2.qualifiers)
				end
				if v2.references then
					for k3, v3 in pairs(v2.references) do
						val = val .. " ++ Ref = " .. mw.wikibase.renderSnaks(v3.snaks)
					end
					val = val .. " \r\n"
				else
					val = val .. " -- NO REFS\r\n"
				end
			end
			val = val .. "</pre>\r\n"
			result = result .. val
		end
	end
	result = result .. "|}\r\n" .. numclaims .. " claims\r\n\r\n"
	if qid then
		result = result .. "[[d:" .. qid .. "|Edit this on Wikidata]]"
	else
		result = result .. "[[d:" .. ent.id .. "|Edit this on Wikidata]]"
	end
	return result
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.