Naar inhoud springen

Module:Commons sitelink

Uit Wikipedia, de vrije encyclopedie
Dit is een oude versie van deze pagina, bewerkt door MSGJ (overleg | bijdragen) op 10 sep 2022 om 13:01. (adapted from en:Module:WikidataIB)
Deze versie kan sterk verschillen van de huidige versie van deze pagina.
(wijz) ← Oudere versie | Huidige versie (wijz) | Nieuwere versie → (wijz)

Documentatie voor deze module kan aangemaakt worden op de volgende pagina: Module:Commons sitelink/doc

p.getCommonsLink = function(frame)
	local qid = frame.args.qid
		qid = (qid or ""):upper()
	if qid == "" then qid = mw.wikibase.getEntityIdForCurrentPage() end
	if not qid then return nil end
	local sitelink = _getSitelink(qid, "commonswiki")
	if not sitelink then
		-- check for topic's main category
		local prop910 = mw.wikibase.getBestStatements(qid, "P910")[1]
		if prop910 then
			local tmcid = prop910.mainsnak.datavalue and prop910.mainsnak.datavalue.value.id
			sitelink = _getSitelink(tmcid, "commonswiki")
		end
		if not sitelink then
			-- check for list's main category
			local prop1754 = mw.wikibase.getBestStatements(qid, "P1754")[1]
			if prop1754 then
				local tmcid = prop1754.mainsnak.datavalue and prop1754.mainsnak.datavalue.value.id
				sitelink = _getSitelink(tmcid, "commonswiki")
			end
		end
	end
	if not sitelink then
		-- check for Commons category (string value)
		local prop373 = mw.wikibase.getBestStatements(qid, "P373")[1]
		if prop373 then
			sitelink = prop373.mainsnak.datavalue and prop373.mainsnak.datavalue.value
			if sitelink then sitelink = "Category:" .. sitelink end
		end
	end
	return sitelink
end