Module:Sandbox/RexxS/Sources

--[[
Module to test a template for reliable sources
See:
https://en.wikipedia.org/wiki/User_talk:Adam_Harangoz%C3%B3/template
https://en.wikipedia.org/wiki/User:Adam_Harangoz%C3%B3/template_specs
https://en.wikipedia.org/wiki/User:Adam_Harangoz%C3%B3/template_properties
--]]

local p = {}

-- This piece of html implements a collapsible container. Check the classes exist on your wiki.
local collapsediv = '<div class="mw-collapsible mw-collapsed mw-content-{{#switch:{{CONTENTLANG}}|ar|arc|arz|azb|bcc|ckb|bqi|dv|fa|fa-af|glk|ha|he|kk-arab|kk-cn|ks|ku-arab|mzn|nqo|pnb|prd|ps|sd|ug|ur|ydd|yi=rtl|ltr}} plainlinks plainlinksneverexpand noarchive" style="width:100%; overflow:auto;" data-expandtext="{{int:Collapsible-expand}}" data-collapsetext="{{int:Collapsible-collapse}}">'

-- All results appear as internal links (to avoid archive links)
local illook = '<div class="mw-content-{{#switch:{{CONTENTLANG}}|ar|arc|arz|azb|bcc|ckb|bqi|dv|fa|fa-af|glk|ha|he|kk-arab|kk-cn|ks|ku-arab|mzn|nqo|pnb|prd|ps|sd|ug|ur|ydd|yi=rtl|ltr}} plainlinks plainlinksneverexpand noarchive">'

local sources = mw.loadData("Module:Sandbox/RexxS/Sources/data")

local function findLang(langcode)
	local langobj
	langcode = mw.text.trim(langcode or "")
	if mw.language.isKnownLanguageTag(langcode) then
		langobj = mw.language.new( langcode )
	else
		langcode = mw.getCurrentFrame():callParserFunction('int', {'lang'})
		if mw.language.isKnownLanguageTag(langcode) then
			langobj = mw.language.new( langcode )
		else
			langobj = mw.language.getContentLanguage()
		end
	end
	return langobj
end

function p.testlist(frame)
	local out = "" -- output text
	for langcode, langdata in pairs(sources) do
		-- just the language codes
		out = out.."\n=== "..langcode.." ==="
		for idx, src in ipairs(langdata) do
			out = out.."\n"..src[1].."; WD="..src[2].."; loc="..src[3].."<br>\n"
		end
		out = out.."<br>\n"
	end
	return out
end

--[[
Parameters:
qid
lang
--]]
function p.demo(frame)
	local args = frame.args

	local qid = args.qid or ""
	if qid == "" then qid = mw.wikibase.getEntityIdForCurrentPage() end

	local langcode = findLang(args.lang).code

	local out1 = {}
	for idx1, src in ipairs(sources[langcode]) do
		local statements = mw.wikibase.getBestStatements(qid, src[2])
		for idx2, valtbl in ipairs(statements) do
			if valtbl.mainsnak.datatype == "external-id" and valtbl.mainsnak.snaktype == "value" then
				local idurl = valtbl.mainsnak.datavalue.value:gsub("%%", "%%%%")
				out1[#out1 + 1] = "[" .. src[3]:gsub("$1", idurl) .. " " .. src[1] .. "]"
			end
		end
	end

	local locallang = ""
	if #out1 > 0 then
		locallang = illook .. frame:expandTemplate{title = "hlist", args = out1} .. "</div>"
	end

	local out2 = {}
	for srclangcode, langdata in pairs(sources) do
		if srclangcode ~= langcode then
			for idx1, src in ipairs(langdata) do
				local statements = mw.wikibase.getBestStatements(qid, src[2])
				for idx2, valtbl in ipairs(statements) do
					if valtbl.mainsnak.datatype == "external-id" and valtbl.mainsnak.snaktype == "value" then
						local idurl = valtbl.mainsnak.datavalue.value:gsub("%%", "%%%%")
						out2[#out2 + 1] = "[" .. src[3]:gsub("$1", idurl) .. " " .. src[1] .. "]"
					end
				end
			end
		end
	end

	local otherlang = ""
	if #out2 > 0 then
		if #out1 > 0 then
			otherlang = collapsediv .. frame:expandTemplate{title = "hlist", args = out2} .. "</div>"
		else
			otherlang = illook .. frame:expandTemplate{title = "hlist", args = out2} .. "</div>"
		end
	end

	return locallang .. otherlang
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.