Відмінності між версіями «Модуль:Wikidata1»

3836 байтів вилучено ,  1 рік тому
upgrade from https://en.wikipedia.org/w/index.php?title=Module:Wikidata&oldid=823805865
(доповнення)
(upgrade from https://en.wikipedia.org/w/index.php?title=Module:Wikidata&oldid=823805865)
}
 
--require("Module:i18n").loadI18n("Module:Wikidata/i18n", i18n)
-- Credit to http://stackoverflow.com/a/1283608/2644759
-- got idea from [[:w:Module:Wd]]
-- cc-by-sa 3.0
local module_title; if ... == nil then
local function tableMerge(t1, t2)
module_title = mw.getCurrentFrame():getTitle()
for k,v in pairs(t2) do
else
if type(v) == "table" then
module_title = ...
if type(t1[k] or false) == "table" then
tableMerge(t1[k] or {}, t2[k] or {})
else
t1[k] = v
end
else
t1[k] = v
end
end
return t1
end
require('Module:i18n').loadI18n(module_title..'/i18n', i18n)
 
local function loadI18n()
local exist, res = pcall(require, "Module:Wikidata/i18n")
if exist and next(res) ~= nil then
tableMerge(i18n, res.i18n)
end
end
 
loadI18n()
 
-- this function needs to be internationalised along with the above:
return '<span class="error">' .. (i18n.errors[code] or code) .. '</span>'
end
local function parseDateFormat(f, timestamp, addon, prefix_addon, addon_sep)
 
local year_suffix
local tstr = ""
local lang_obj = mw.language.new(wiki.langcode)
local f_parts = mw.text.split(f, 'Y', true)
for idx, f_part in pairs(f_parts) do
year_suffix = ''
if string.match(f_part, "x[mijkot]$") then
-- for non-Gregorian year
f_part = f_part .. 'Y'
elseif idx < #f_parts then
-- supress leading zeros in year
year_suffix = lang_obj:formatDate('Y', timestamp)
year_suffix = string.gsub(year_suffix, '^0+', '', 1)
end
tstr = tstr .. lang_obj:formatDate(f_part, timestamp) .. year_suffix
end
if addon ~= "" and prefix_addon then
return addon .. addon_sep .. tstr
elseif addon ~= "" then
return tstr .. addon_sep .. addon
else
return tstr
end
end
local function parseDateValue(timestamp, date_format, date_addon)
local prefix_addon = i18n["datetime"]["prefix-addon"]
timestamp = '+' .. string.sub(timestamp, 2)
addon = date_addon
end
local function d(f)
local year_suffix
local tstr = ""
local lang_obj = mw.language.new(wiki.langcode)
local f_parts = mw.text.split(f, 'Y', true)
for idx, f_part in pairs(f_parts) do
year_suffix = ''
if string.match(f_part, "x[mijkot]$") then
-- for non-Gregorian year
f_part = f_part .. 'Y'
elseif idx < #f_parts then
-- supress leading zeros in year
year_suffix = lang_obj:formatDate('Y', timestamp)
year_suffix = string.gsub(year_suffix, '^0+', '', 1)
end
tstr = tstr .. lang_obj:formatDate(f_part, timestamp) .. year_suffix
end
if addon ~= "" and prefix_addon then
return addon .. addon_sep .. tstr
elseif addon ~= "" then
return tstr .. addon_sep .. addon
else
return tstr
end
end
local _date_format = i18n["datetime"]["format"][date_format]
if _date_format ~= nil then
return dparseDateFormat(_date_format, timestamp, addon, prefix_addon, addon_sep)
else
return printError("unknown-datetime-format")
_date_format = i18n["datetime"][9]
end
return parseDateFormat(_date_format, timestamp, addon, prefix_addon, addon_sep)
local year_suffix
local tstr = ""
local lang_obj = mw.language.new(wiki.langcode)
local f_parts = mw.text.split(_date_format, 'Y', true)
for idx, f_part in pairs(f_parts) do
year_suffix = ''
if string.match(f_part, "x[mijkot]$") then
-- for non-Gregorian year
f_part = f_part .. 'Y'
elseif idx < #f_parts then
-- supress leading zeros in year
year_suffix = lang_obj:formatDate('Y', timestamp)
year_suffix = string.gsub(year_suffix, '^0+', '', 1)
end
tstr = tstr .. lang_obj:formatDate(f_part, timestamp) .. year_suffix
end
local fdate
if addon ~= "" and prefix_addon then
fdate = addon .. addon_sep .. tstr
elseif addon ~= "" then
fdate = tstr .. addon_sep .. addon
else
fdate = tstr
end
 
return fdate
else
return printError("unknown-datetime-format")
end
 
-- precision: 0 - billion years, 1 - hundred million years, ..., 6 - millennia, 7 - century, 8 - decade, 9 - year, 10 - month, 11 - day, 12 - hour, 13 - minute, 14 - second
local function printDatavalueCoordinate(data, parameter)
-- data fields: latitude [double], longitude [double], altitude [double], precision [double], globe [wikidata URI, usually http://www.wikidata.org/entity/Q2 [earth]]
if parameter then
if parameter == "globe" then data.globe = mw.ustring.match(data.globe, "Q%d+") end -- extract entity id from the globe URI
return data[parameter]
else
return data.latitude .. "/" .. data.longitude -- combine latitude and longitude, which can be decomposed using the #titleparts wiki function
end
end
 
local function normalizeDate(date)
date = mw.text.trim(date, "+")
end
 
-- precision: 0 - billion years, 1 - hundred million years, ..., 6 - millennia, 7 - century, 8 - decade, 9 - year, 10 - month, 11 - day, 12 - hour, 13 - minute, 14 - second
local function formatDate(date, precision, timezone)
precision = precision or 11
end
 
local function parseInput(frame)
local qid = frame.args.qid
if qid and (#qid == 0) then qid = nil end
local propertyID = mw.text.trim(frame.args[1] or "")
local input_parm = mw.text.trim(frame.args[2] or "")
if input_parm ~= "FETCH_WIKIDATA" then
return false, input_parm, nil, nil
end
local entity = mw.wikibase.getEntityObject(qid)
local claims
if entity and entity.claims then
claims = entity.claims[propertyID]
if not claims then
return false, "", nil, nil
end
else
return false, "", nil, nil
end
return true, entity, claims, propertyID
end
local function isType(claims, type)
return claims[1] and claims[1].mainsnak.snaktype == "value" and claims[1].mainsnak.datavalue.type == type
end
local function getValue(entity, claims, propertyID, delim, labelHook)
if labelHook == nil then
labelHook = function (qnumber)
return nil;
end
end
if isType(claims, "wikibase-entityid") then
local out = {}
for k, v in pairs(claims) do
local qnumber = "Q" .. v.mainsnak.datavalue.value["numeric-id"]
local sitelink = mw.wikibase.sitelink(qnumber)
local label = labelHook(qnumber) or mw.wikibase.label(qnumber) or qnumber
if sitelink then
out[#out + 1] = "[[" .. sitelink .. "|" .. label .. "]]"
else
out[#out + 1] = "[[:d:" .. qnumber .. "|" .. label .. "]]<abbr title='" .. i18n["errors"]["local-article-not-found"] .. "'>[*]</abbr>"
end
end
return table.concat(out, delim)
else
-- just return best values
return entity:formatPropertyValues(propertyID).value
end
end
 
------------------------------------------------------------------------------
function p.descriptionIn(frame)
local langcode = frame.args[1]
local id = frame.args[2] -- "id" must be nil, as access to other Wikidata objects is disabled in Mediawiki configuration
-- return description of a Wikidata entity in the given language or the default language of this Wikipedia site
return mw.wikibase.getEntityObject(id).descriptions[langcode or wiki.langcode].value
function p.labelIn(frame)
local langcode = frame.args[1]
local id = frame.args[2] -- "id" must be nil, as access to other Wikidata objects is disabled in Mediawiki configuration
-- return label of a Wikidata entity in the given language or the default language of this Wikipedia site
return mw.wikibase.getEntityObject(id).labels[langcode or wiki.langcode].value
-- This is used to get a value, or a comma separated list of them if multiple values exist
p.getValue = function(frame)
local delimdefault = ", " -- **internationalise later**
local propertyID = mw.text.trim(frame.args[1] or "")
local input_parmdelim = mw.text.trim(frame.args[2].delimiter or "")
delim = string.gsub(delim, '"', '')
if input_parm == "FETCH_WIKIDATA" then
if #delim == 0 then
local entity = mw.wikibase.getEntityObject()
delim = delimdefault
local claims
end
if entity and entity.claims then
claims local =go, errorOrentity, entity.claims[, propertyID] = parseInput(frame)
if not go then
end
return errorOrentity
if claims then
-- if wiki-linked value output as link if possible
if (claims[1] and claims[1].mainsnak.snaktype == "value" and claims[1].mainsnak.datavalue.type == "wikibase-entityid") then
local out = {}
for k, v in pairs(claims) do
local sitelink = mw.wikibase.sitelink("Q" .. v.mainsnak.datavalue.value["numeric-id"])
local label = mw.wikibase.label("Q" .. v.mainsnak.datavalue.value["numeric-id"])
if label == nil then label = "Q" .. v.mainsnak.datavalue.value["numeric-id"] end
 
if sitelink then
out[#out + 1] = "[[" .. sitelink .. "|" .. label .. "]]"
else
out[#out + 1] = "[[:d:Q" .. v.mainsnak.datavalue.value["numeric-id"] .. "|" .. label .. "]]<abbr title='" .. i18n["errors"]["local-article-not-found"] .. "'>[*]</abbr>"
end
end
return table.concat(out, ", ")
else
-- just return best values
return entity:formatPropertyValues(propertyID).value
end
else
return ""
end
else
return input_parm
end
return getValue(errorOrentity, claims, propertyID, delim)
end
 
-- Same as above, but uses the short name property for label if available.
p.getValueShortName = function(frame)
local go, errorOrentity, claims, propertyID = mw.text.trimparseInput(frame.args[1] or "")
if not go then
local input_parm = mw.text.trim(frame.args[2] or "")
return errorOrentity
if input_parm == "FETCH_WIKIDATA" then
end
local entity = mw.wikibase.getEntityObject()
local entity = errorOrentity
local claims
-- if wiki-linked value output as link if possible
if entity and entity.claims then
local function labelHook (qnumber)
claims = entity.claims[propertyID]
local label
end
local claimEntity = mw.wikibase.getEntity(qnumber)
if claims then
if claimEntity ~= nil then
-- if wiki-linked value output as link if possible
if claimEntity.claims.P1813 then
if (claims[1] and claims[1].mainsnak.snaktype == "value" and claims[1].mainsnak.datavalue.type == "wikibase-entityid") then
for k2, v2 in pairs(claimEntity.claims.P1813) do
local out = {}
if v2.mainsnak.datavalue.value.language == "en" then
for k, v in pairs(claims) do
local sitelink label = mw.wikibase.sitelink("Q" .. vv2.mainsnak.datavalue.value["numeric-id"]).text
local label
local claimEntity = mw.wikibase.getEntity("Q" .. v.mainsnak.datavalue.value["numeric-id"])
if claimEntity ~= nil then
if claimEntity.claims.P1813 then
for k2, v2 in pairs(claimEntity.claims.P1813) do
if v2.mainsnak.datavalue.value.language == "en" then
label = v2.mainsnak.datavalue.value.text
end
end
end
end
if label == nil or label == "" then label = mw.wikibase.label("Q" .. v.mainsnak.datavalue.value["numeric-id"]) end
if label == nil then label = "Q" .. v.mainsnak.datavalue.value["numeric-id"] end
 
if sitelink then
out[#out + 1] = "[[" .. sitelink .. "|" .. label .. "]]"
else
out[#out + 1] = "[[:d:Q" .. v.mainsnak.datavalue.value["numeric-id"] .. "|" .. label .. "]]<abbr title='" .. i18n["errors"]["local-article-not-found"] .. "'>[*]</abbr>"
end
end
return table.concat(out, ", ")
else
-- just return best vakues
return entity:formatPropertyValues(propertyID).value
end
else
return ""
end
if label == nil or label == "" then return nil end
else
return input_parmlabel
end
return getValue(errorOrentity, claims, propertyID, ", ", labelHook);
end
 
if input_parm == "FETCH_WIKIDATA" then
local entity = mw.wikibase.getEntity(itemID)
local claims = entity.claims[propertyID]
if entity and entity.claims then
claims = entity.claims[propertyID]
end
if claims then
return getValue(entity, claims, propertyID, ", ")
-- if wiki-linked value output as link if possible
if (claims[1] and claims[1].mainsnak.snaktype == "value" and claims[1].mainsnak.datavalue.type == "wikibase-entityid") then
local out = {}
for k, v in pairs(claims) do
local sitelink = mw.wikibase.sitelink("Q" .. v.mainsnak.datavalue.value["numeric-id"])
local label = mw.wikibase.label("Q" .. v.mainsnak.datavalue.value["numeric-id"])
if label == nil then label = "Q" .. v.mainsnak.datavalue.value["numeric-id"] end
 
if sitelink then
out[#out + 1] = "[[" .. sitelink .. "|" .. label .. "]]"
else
out[#out + 1] = "[[:d:Q" .. v.mainsnak.datavalue.value["numeric-id"] .. "|" .. label .. "]]<abbr title='" .. i18n["errors"]["local-article-not-found"] .. "'>[*]</abbr>"
end
end
return table.concat(out, ", ")
else
return entity:formatPropertyValues(propertyID).value
end
else
return ""
end
end
local function getQualifier(frame, outputHook)
 
p.getQualifierValue = function(frame)
local propertyID = mw.text.trim(frame.args[1] or "")
local qualifierID = mw.text.trim(frame.args[2] or "")
for k2, v2 in pairs(v.qualifiers[qualifierID]) do
if v2.snaktype == 'value' then
out[#out + 1] = outputHook(v2);
if (mw.wikibase.sitelink("Q" .. v2.datavalue.value["numeric-id"])) then
out[#out + 1] = "[[" .. mw.wikibase.sitelink("Q" .. v2.datavalue.value["numeric-id"]) .. "]]"
else
out[#out + 1] = "[[:d:Q" .. v2.datavalue.value["numeric-id"] .. "|" .. mw.wikibase.label("Q" .. v2.datavalue.value["numeric-id"]) .. "]]<abbr title='" .. i18n["errors"]["local-article-not-found"] .. "'>[*]</abbr>"
end
end
end
end
return table.concat(out, ", "), true
else
return "", false
end
else
return input_parm, false
end
end
p.getQualifierValue = function(frame)
local function outputValue(value)
local qnumber = "Q" .. value.datavalue.value["numeric-id"]
if (mw.wikibase.sitelink(qnumber)) then
return "[[" .. mw.wikibase.sitelink(qnumber) .. "]]"
else
return "[[:d:" .. qnumber .. "|" ..qnumber .. "]]<abbr title='" .. i18n["errors"]["local-article-not-found"] .. "'>[*]</abbr>"
end
end
return (getQualifier(frame, outputValue))
end
 
-- This is used to get a value like 'male' (for property p21) which won't be linked and numbers without the thousand separators
p.getRawValue = function(frame)
local go, errorOrentity, claims, propertyID = mw.text.trimparseInput(frame.args[1] or "")
if not go then
local input_parm = mw.text.trim(frame.args[2] or "")
return errorOrentity
if input_parm == "FETCH_WIKIDATA" then
local entity = mw.wikibase.getEntityObject()
local claims
if entity and entity.claims then claims = entity.claims[propertyID] end
if claims then
local result = entity:formatPropertyValues(propertyID, mw.wikibase.entity.claimRanks).value
 
-- if number type: remove thousand separators, bounds and units
if (claims[1] and claims[1].mainsnak.snaktype == "value" and claims[1].mainsnak.datavalue.type == "quantity") then
result = mw.ustring.gsub(result, "(%d),(%d)", "%1%2")
result = mw.ustring.gsub(result, "(%d)±.*", "%1")
end
return result
else
return ""
end
else
return input_parm
end
local entity = errorOrentity
local result = entity:formatPropertyValues(propertyID, mw.wikibase.entity.claimRanks).value
-- if number type: remove thousand separators, bounds and units
if isType(claims, "quantity") then
result = mw.ustring.gsub(result, "(%d),(%d)", "%1%2")
result = mw.ustring.gsub(result, "(%d)±.*", "%1")
end
return result
end
 
-- This is used to get the unit name for the numeric value returned by getRawValue
p.getUnits = function(frame)
local go, errorOrentity, claims, propertyID = mw.text.trimparseInput(frame.args[1] or "")
if not go then
local input_parm = mw.text.trim(frame.args[2] or "")
return errorOrentity
if input_parm == "FETCH_WIKIDATA" then
end
local entity = mw.wikibase.getEntityObject()
local entity = errorOrentity
local claims
local result = entity:formatPropertyValues(propertyID, mw.wikibase.entity.claimRanks).value
if entity and entity.claims then claims = entity.claims[propertyID] end
if isType(claims, "quantity") then
result = mw.ustring.sub(result, mw.ustring.find(result, " ")+1, -1)
local result = entity:formatPropertyValues(propertyID, mw.wikibase.entity.claimRanks).value
if (claims[1] and claims[1].mainsnak.snaktype == "value" and claims[1].mainsnak.datavalue.type == "quantity") then
result = mw.ustring.sub(result, mw.ustring.find(result, " ")+1, -1)
end
return result
else
return ""
end
else
return input_parm
end
return result
end
 
-- This is used to get the unit's QID to use with the numeric value returned by getRawValue
p.getUnitID = function(frame)
local propertyIDgo, errorOrentity, claims = mw.text.trimparseInput(frame.args[1] or "")
if not go then
local input_parm = mw.text.trim(frame.args[2] or "")
return errorOrentity
if input_parm == "FETCH_WIKIDATA" then
local entity = mw.wikibase.getEntityObject()
local claims
if entity and entity.claims then claims = entity.claims[propertyID] end
if claims then
local result
if (claims[1] and claims[1].mainsnak.snaktype == "value" and claims[1].mainsnak.datavalue.type == "quantity") then
-- get the url for the unit entry on Wikidata:
result = claims[1].mainsnak.datavalue.value.unit
-- and just reurn the last bit from "Q" to the end (which is the QID):
result = mw.ustring.sub(result, mw.ustring.find(result, "Q"), -1)
end
return result
else
return ""
end
else
return input_parm
end
local entity = errorOrentity
local result
if isType(claims, "quantity") then
-- get the url for the unit entry on Wikidata:
result = claims[1].mainsnak.datavalue.value.unit
-- and just reurn the last bit from "Q" to the end (which is the QID):
result = mw.ustring.sub(result, mw.ustring.find(result, "Q"), -1)
end
return result
end
 
p.getRawQualifierValue = function(frame)
local function outputHook(value)
local propertyID = mw.text.trim(frame.args[1] or "")
if value.datavalue.value["numeric-id"] then
local qualifierID = mw.text.trim(frame.args[2] or "")
return mw.wikibase.label("Q" .. value.datavalue.value["numeric-id"])
local input_parm = mw.text.trim(frame.args[3] or "")
if input_parm == "FETCH_WIKIDATA" then
local entity = mw.wikibase.getEntityObject()
if entity.claims[propertyID] ~= nil then
local out = {}
for k, v in pairs(entity.claims[propertyID]) do
for k2, v2 in pairs(v.qualifiers[qualifierID]) do
if v2.snaktype == 'value' then
if v2.datavalue.value["numeric-id"] then
out[#out + 1] = mw.wikibase.label("Q" .. v2.datavalue.value["numeric-id"])
else
out[#out + 1] = v2.datavalue.value
end
end
end
end
local ret = table.concat(out, ", ")
return string.upper(string.sub(ret, 1, 1)) .. string.sub(ret, 2)
else
return ""value.datavalue.value
end
else
return input_parm
end
local ret, gotData = getQualifier(frame, outputHook)
if gotData then
ret = string.upper(string.sub(ret, 1, 1)) .. string.sub(ret, 2)
end
return ret
end
 
-- So I'll just supply "Z" in the call to formatDate below:
p.getDateValue = function(frame)
local propertyID = mw.text.trim(frame.args[1] or "")
local input_parm = mw.text.trim(frame.args[2] or "")
local date_format = mw.text.trim(frame.args[3] or i18n["datetime"]["default-format"])
local date_addon = mw.text.trim(frame.args[4] or i18n["datetime"]["default-addon"])
local go, errorOrentity, claims = parseInput(frame)
if input_parm == "FETCH_WIKIDATA" then
if not go then
local entity = mw.wikibase.getEntityObject()
return errorOrentity
if entity.claims[propertyID] ~= nil then
end
local out = {}
local entity = errorOrentity
for k, v in pairs(entity.claims[propertyID]) do
local out = {}
if v.mainsnak.datavalue.type == 'time' then
for k, v in pairs(claims) do
local timestamp = v.mainsnak.datavalue.value.time
local dateprecision =if v.mainsnak.datavalue.value.precisiontype == 'time' then
local timestamp = v.mainsnak.datavalue.value.time
out[#out + 1] = parseDateFull(timestamp, dateprecision, date_format, date_addon)
local dateprecision = v.mainsnak.datavalue.value.precision
end
-- A year can be stored like this: "+1872-00-00T00:00:00Z",
end
-- which is processed here as if it were the day before "+1872-01-01T00:00:00Z",
return table.concat(out, ", ")
-- and that's the last day of 1871, so the year is wrong.
else
-- So fix the month 0, day 0 timestamp to become 1 January instead:
return ""
timestamp = timestamp:gsub("%-00%-00T", "-01-01T")
out[#out + 1] = parseDateFull(timestamp, dateprecision, date_format, date_addon)
end
else
return input_parm
end
return table.concat(out, ", ")
end
 
p.getQualifierDateValue = function(frame)
local propertyID = mw.text.trim(frame.args[1] or "")
local qualifierID = mw.text.trim(frame.args[2] or "")
local input_parm = mw.text.trim(frame.args[3] or "")
local date_format = mw.text.trim(frame.args[4] or i18n["datetime"]["default-format"])
local date_addon = mw.text.trim(frame.args[5] or i18n["datetime"]["default-addon"])
local function outputHook(value)
if input_parm == "FETCH_WIKIDATA" then
local entitytimestamp = mwvalue.wikibasedatavalue.getEntityObject()value.time
return parseDateValue(timestamp, date_format, date_addon)
if entity.claims[propertyID] ~= nil then
local out = {}
for k, v in pairs(entity.claims[propertyID]) do
for k2, v2 in pairs(v.qualifiers[qualifierID]) do
if v2.snaktype == 'value' then
local timestamp = v2.datavalue.value.time
out[#out + 1] = parseDateValue(timestamp, date_format, date_addon)
end
end
end
return table.concat(out, ", ")
else
return ""
end
else
return input_parm
end
return (getQualifier(frame, outputHook))
end
 
-- If a property is chosen that is not of type "commonsMedia", it will return empty text.
p.getImages = function(frame)
local propertyID = mw.text.trim(frame.args[1] or "")
local input_parm = mw.text.trim(frame.args[2] or "")
local sep = mw.text.trim(frame.args[3] or " ")
local imgsize = mw.text.trim(frame.args[4] or "frameless")
local go, errorOrentity, claims = parseInput(frame)
if input_parm == "FETCH_WIKIDATA" then
if not go then
local entity = mw.wikibase.getEntityObject()
return errorOrentity
local claims
end
if entity and entity.claims then
local entity = errorOrentity
claims = entity.claims[propertyID]
if (claims[1] and claims[1].mainsnak.datatype == "commonsMedia") then
end
iflocal claimsout then= {}
for k, v in pairs(claims) do
if (claims[1] and claims[1].mainsnak.datatype == "commonsMedia") then
local outfilename = {}v.mainsnak.datavalue.value
out[#out + 1] = "[[File:" .. filename .. "|" .. imgsize .. "]]"
for k, v in pairs(claims) do
local filename = v.mainsnak.datavalue.value
out[#out + 1] = "[[File:" .. filename .. "|" .. imgsize .. "]]"
end
return table.concat(out, sep)
else
return ""
end
else
return ""
end
return table.concat(out, sep)
else
return input_parm""
end
end
else
return input_parm
end
end
 
-- This is used to get the QIDs of all of the values of a property, as a comma separated list if multiple values exist
-- Usage: {{#invoke:Wikidata |getPropertyIDs |<PropertyID> |FETCH_WIKIDATA}}
-- Usage: {{#invoke:Wikidata |getPropertyIDs |<PropertyID> |<InputParameter> |qid=<QID>}}
 
p.getPropertyIDs = function(frame)
local go, errorOrentity, propclaims = parseInput(frame)
if not go then
return errorOrentity
end
local entity = errorOrentity
-- if wiki-linked value collect the QID in a table
if (propclaims[1] and propclaims[1].mainsnak.snaktype == "value" and propclaims[1].mainsnak.datavalue.type == "wikibase-entityid") then
local out = {}
for k, v in pairs(propclaims) do
out[#out + 1] = "Q" .. v.mainsnak.datavalue.value["numeric-id"]
end
return table.concat(out, ", ")
else
-- not a wikibase-entityid, so return empty
return ""
end
end
function p.claim(frame)
local property = frame.args[1] or ""
local id = frame.args["id"] -- "id" must be nil, as access to other Wikidata objects is disabled in Mediawiki configuration
local qualifierId = frame.args["qualifier"]
local parameter = frame.args["parameter"]
 
-- getting sitelink of a given wiki
-- get sitelink of current item if qid not supplied
function p.getSiteLink(frame)
local fqid = frame.args[1].qid
if qid == "" then qid = nil end
local entity = mw.wikibase.getEntity()
local f = mw.text.trim( frame.args[1] or "")
local entity = mw.wikibase.getEntity(qid)
if not entity then
return
250

редагувань