Module:Sandbox/Premeditated/Reliable-sources

require("strict") local Date = require('Module:Date')._Date local data = mw.loadData("Module:Sandbox/Premeditated/Reliable-sources/data") local ref_sites = data.sites local tracking_cats = data.tracking_cats local os_date = os.date("%d %B %Y")

local p = {}

local tracking_categories = '' local namespace = mw.title.getCurrentTitle.namespace local add_tracking_category = function(cat) if namespace == 0 then tracking_categories = tracking_categories .. cat end end

-- The following values are set by get_statements local the_frame			-- Used to for frame:extensionTag local the_qid			-- Used to make links to Wikidata and to get more statements if needed later local the_pid			-- Used to make links to Wikidata

-- The following value is set by getReferences sooon local ref_texts = {}

local function has_value (tab, val) for index, value in ipairs(tab) do       if value == val then return index end end return false end

local function getdomain(url) -- extract the full hostname with all subdomains local hostname = url:match '^https?://([^/]+)' or '' -- then, match the last 2 elements, separated by a dot return hostname:match '(%w+%.%w+)$' end

local function getReferences(frame, claim) local result = "" -- traverse through all references for ref in pairs(claim.references or {}) do		local refparts -- traverse through all parts of the current reference for snakkey, snakval in orderedpairs(claim.references[ref].snaks or {}, claim.references[ref]["snaks-order"]) do if refparts then refparts = refparts .. ", " else refparts = "" end -- output the label of the property of the reference part, e.g. "imported from" for P143 refparts = refparts .. tostring(mw.wikibase.label(snakkey)) .. ": "			-- output all values of this reference part, e.g. "German Wikipedia" and "English Wikipedia" if the referenced claim was imported from both sites for snakidx = 1, #snakval do if snakidx > 1 then refparts = refparts .. ", " end refparts = refparts .. getSnakValue(snakval[snakidx]) end end if refparts then result = result .. frame:extensionTag("ref", refparts) end end return result end

local function orderedpairs(array, order) if not order then return pairs(array) end

-- return iterator function local i = 0 return function i = i + 1 if order[i] then return order[i], array[order[i]] end end end

local function getSnakValue(snak, parameter) if snak.snaktype == "value" then -- call the respective snak parser if snak.datavalue.type == "string" then return snak.datavalue.value elseif snak.datavalue.type == "globecoordinate" then return printDatavalueCoordinate(snak.datavalue.value, parameter) elseif snak.datavalue.type == "quantity" then return printDatavalueQuantity(snak.datavalue.value, parameter) elseif snak.datavalue.type == "time" then return printDatavalueTime(snak.datavalue.value, parameter) elseif snak.datavalue.type == "wikibase-entityid" then return printDatavalueEntity(snak.datavalue.value, parameter) elseif snak.datavalue.type == "monolingualtext" then return printDatavalueMonolingualText(snak.datavalue.value, parameter) end end return mw.wikibase.renderSnak(snak) end

return p