Modulu:Wikidata: berrikuspenen arteko aldeak

Ezabatutako edukia Gehitutako edukia
datatype geo-shape
No edit summary
1. lerroa:
-- version 2020061520200827 from master @cawiki
 
local p = {}
65. lerroa:
["addpencil"] = false, -- adds a pencil icon linked to Wikidata statement, planned to overwrite by Wikidata Bridge
["categorylabels"] = "", -- Category:Pages with Wikidata labels not translated (void for no local category)
["categoryprop"] = "", -- Category:Pages using Wikidata property $1 (void for no local category)
["addfallback"] = {} -- additional fallback language codes
}
144 ⟶ 145 lerroa:
-- Argument is 'set' when it exists (not nil) or when it is not an empty string.
local function isSet(var)
return not (var == nil or (type(var) == 'string' and mw.text.trim(var) == ''))
end
 
209 ⟶ 210 lerroa:
local function feminineGender(id)
local claims = mw.wikibase.getBestStatements(id or mw.wikibase.getEntityIdForCurrentPage(),'P21')
iflocal gender_id = getSnak(claims, {1, "mainsnak", "datavalue"}), == nil then -- no claim"value", novalue or somevalue"id"})
if gender_id == "Q6581072" or gender_id == "Q1052281" or gender_id == "Q43445" then -- female, transgender female, female organism
return false
return true
else
local genderId = claims[1].mainsnak.datavalue.value.id
if genderId == "Q6581072" or genderId == "Q1052281" or genderId == "Q43445" then -- female, transgender female, female organism
return true
end
end
return false
248 ⟶ 245 lerroa:
end
return ret_lang .. ret_icon
end
 
-- editicon values: true/false (no=false), right, void defaults to i18n.addpencil
-- labelicon only by parameter
local function setIcons(arg, parg)
local val = arg == nil and parg or arg
local edit_icon, label_icon
if not isSet(val) then
edit_icon, label_icon = i18n.addpencil, true
elseif val == false or val == "false" or val == "no" then
edit_icon, label_icon = false, false
else
edit_icon, label_icon = val, true
end
return edit_icon, label_icon
end
 
253 ⟶ 265 lerroa:
local function addEditIcon(parameters)
local ret = ''
if i18n.addpencil and parameters.editicon and parameters.id and parameters.property then
local icon_style = parameters.editicon == "right" and ' style="float: right;"' or ''
ret = ' <span data-bridge-edit-flow="single-best-value">'
ret = ' <span class="penicon" data-bridge-edit-flow="single-best-value"' .. icon_style .. '>'
.. "[[File:Arbcom ru editing.svg|10px|baseline|"
.. string.gsub(mw.message.new('EditlinkWikibase-client-data-bridge-bailout-suggestion-go-to-repo-button'):inLanguage(parameters.lang[1]):plain(), '{{WBREPONAME}}', 'Wikidata')
.. "|link=https://www.wikidata.org/wiki/" .. parameters.id .. "?uselang=" .. parameters.lang[1] .. "#" .. parameters.property .. "]]"
.. "</span>"
if isSet(i18n.categoryprop) then
ret = ret .. "[[" .. string.gsub(i18n.categoryprop, '$1', parameters.property) .. "]]"
end
end
return ret
264 ⟶ 280 lerroa:
-- add edit icon to the last element of a table
local function addEditIconTable(thetable, parameters)
if #thetable == 0 or not i18nparameters.addpencilediticon == false then
return thetable
end
411 ⟶ 427 lerroa:
end
 
-- format data type commonsMedia and geo-shape
local function printDatatypeMedia(data, parameters)
local icon
if not string.find((parameters.formatting or ''), '$1', 1, true) then
icon = "no-icon"
if not string.find(data, '^Data:') then
data = mw.uri.encode(data, 'PATH') -- encode special characters in filename
end
end
return printDatatypeString(data, parameters), icon
509 ⟶ 528 lerroa:
suffix = require(wiki.module_title .. "/Units").getUnit(amount, unit_label, id, false)
else
suffix = (unit_label or id) .. addLabelIcon(id, lang, parameters.lang[1], parameters.editiconlabelicon)
end
end
631 ⟶ 650 lerroa:
if parameters.case then
amount = case(parameters.case, amount, parameters.lang[1])
elseif parameters.formatting ~= 'raw' then
else
amount = lang_obj:formatNum(tonumber(amount))
end
642 ⟶ 661 lerroa:
return conv_amount .. conv_suffix, conv_sortkey
end
elseif mw.ustring.find((parameters.formatting or ''), '$1', 1, true) then -- formatting with pattern
amount = mw.ustring.gsub(parameters.formatting, '$1', {['$1'] = amount})
end
return amount .. suffix, sortkey
725 ⟶ 746 lerroa:
elseif precision == 9 or parameters.formatting == 'Y' then -- precision is year
ret = formatTime(i18n.datetime[9], intyear)
if parameters.case then
ret = case(parameters.case, ret, parameters.lang[1])
end
ret = postFormat(ret) .. calendar_add
elseif precision == 10 then -- month
783 ⟶ 801 lerroa:
ret1 = '[[' .. sitelink .. '|' .. labelcase .. ']]'
ret2 = labelcase
elseif label and string.match(parameter ==or '', 'internallink$') orand parameternot == 'ucinternallink'mw.wikibase.getEntityIdForTitle(label) then
ret1 = '[[' .. label .. '|' .. labelcase .. ']]'
ret2 = labelcase
else
ret1 = '[[d:' .. entity_page .. '|<span style="color:#5f9cbb;">' .. (labelcase or entity_id) .. '</span>]]'
ret2 = labelcase or entity_id
end
end
return ret1 .. addLabelIcon(entity_id, lang, parameters.lang[1], parameters.editiconlabelicon), ret2
end
 
800 ⟶ 818 lerroa:
if parameters.list == "lang" and data["language"] ~= parameters.lang[1] then
return
elseif parameters.list == "notlang" and data["language"] == parameters.lang[1] then
return
elseif parameters.formatting == "language" or parameters.formatting == "text" then
845 ⟶ 865 lerroa:
end
elseif snak.snaktype == 'novalue' then
if parameters.formatting == 'raw' or parameters.shownovalue == false then return end
return mw.message.new('Wikibase-snakview-snaktypeselector-novalue'):inLanguage(parameters.lang[1]):plain()
elseif snak.snaktype == 'somevalue' then
907 ⟶ 927 lerroa:
local function getValueOfParentClaim(claim, qualifierId, parameters)
local qids = mw.text.split(qualifierId, '/', true)
local valuerawvalue, parent_claimssortkey, valuevalueraw = {}, sortkey{}, {}
local parent_raw, value_text
if qids[1] == parameters.property then
valuerawparent_raw, _, _ = getValueOfClaim(claim, nil, {["formatting"]="raw", ["lang"]=parameters.lang})
else
valuerawparent_raw, _, _ = getValueOfClaim(claim, qids[1], {["formatting"]="raw", ["lang"]=parameters.lang, ["list"]=true, ["qseparator"]='/', ["qconjunction"]='/'})
end
if string.sub(valuerawparent_raw or '', 1, 1) == "Q" then -- protection for 'no value'
local parent_qids = mw.text.split(parent_raw, '/', true)
parent_claims = mw.wikibase.getBestStatements(valueraw, qids[2])
for idx, p_qid in ipairs(parent_qids) do
if parent_claims[1] ~= nil then
local parent_claims = mw.wikibase.getBestStatements(p_qid, qids[2])
value, sortkey, _ = getValueOfClaim(parent_claims[1], nil, parameters)
if parent_claims[1] then
-- raw parent value needed for while/black lists, lang for avoiding an error on types other than entity
valueraw value[idx], _sortkey[idx], _ = getValueOfClaim(parent_claims[1], nil, {["formatting"]="raw", ["lang"]=parameters.lang})
-- raw parent value needed for while/black lists, lang for avoiding an error on types other than entity
valueraw[idx], _, _ = getValueOfClaim(parent_claims[1], nil, {["formatting"]="raw", ["lang"]=parameters.lang})
end
end
end
returnif value,[1] sortkey, valuerawthen
value_text = mw.text.listToText(value, parameters.qseparator, parameters.qconjunction)
end
return value_text, sortkey[1], valueraw[1]
end
 
976 ⟶ 1.003 lerroa:
refs['P236'] = refs['P236'] or refParent(ref_name, 'P236') -- ISSN
refs['P356'] = refs['P356'] or refParent(ref_name, 'P356') -- DOI
-- Qid, title, access-date, pages
ref_name = ref_name .. (refs['P1476'] or '') .. (refs['P813'] or '') .. (refs['P304'] or '')
end
1.046 ⟶ 1.075 lerroa:
 
-- Set whitelist or blacklist values
local function setWhiteOrBlackList(type_list, num_qual, args)
local lists = {['whitelist']={}, ['blacklist']={}, ['ignorevalue']={}, ['selectvalue']={}}
local listed = false
local list = {}
for i = 0, num_qual do
for k, _ in pairs(lists) do
if isSet(args[type_list .. i]) then
if isSet(args[k .. i]) then
listed = true
list lists[k][tostring(i)] = {}
local pattern = 'Q%d+'
for v in string.gmatch(args[type_list .. i], 'Q%d+') do
if string.sub(args[k .. i], 1, 1) ~= 'Q' then
list[tostring(i)][resolveEntityId(v)] = true
pattern = '[^%p%s]+'
end
for q in string.gmatch(args[k .. i], pattern) do
lists[k][tostring(i)][resolveEntityId(q)] = true
end
end
end
end
return lists['whitelist'], lists['blacklist'], lists['ignorevalue'], lists['selectvalue']
return list, listed
end
 
1.071 ⟶ 1.104 lerroa:
end
 
local function getEntityId(frameargs, pargs, unnamed)
local argspargs = frame.argspargs or frame{}
local pargs = frame.args and frame:getParent().args
local id = args.item or args.from or (unnamed and mw.text.trim(args[1] or '') or nil)
if not isSet(id) and pargs then
id = pargs.item or pargs.from or (unnamed and mw.text.trim(pargs[1] or '') or nil)
end
1.086 ⟶ 1.118 lerroa:
end
return id
end
 
local function getArg(value, default, aliases)
if type(value) == 'boolean' then return value
elseif value == "false" or value == "no" then return false
elseif value == "true" or value == "yes" then return true
elseif value and aliases and aliases[value] then return aliases[value]
elseif isSet(value) then return value
elseif default then return default
else return nil
end
end
 
1.091 ⟶ 1.134 lerroa:
-- on debug console use: =p.claim{item="Q...", property="P...", ...}
function p.claim(frame)
local is_sandboxargs = frame.args andor isSet(frame:getParent().args.sandbox) -- via invoke or require
local pargs = frame.args and frame:getParent().args or {}
local is_sandbox = isSet(pargs.sandbox)
if not required and is_sandbox then
return require(wiki.module_title .. "/" .. mw.message.new('Sandboxlink-subpage-name'):inLanguage(wiki.langcode):plain()).claim(frame)
end
local args = frame.args or frame -- via invoke or require
--If a value is already set, use it
if isSet(args.value) then
1.106 ⟶ 1.150 lerroa:
-- arguments
local idparameters = getEntityId(frame){}
parameters.id = getEntityId(args, pargs)
if id == nil then return end
if parameters.id == nil then return end
local property = string.upper(args.property or "")
parameters.property = string.upper(args.property or "")
local qualifierId = {}
qualifierId[1] = isSetgetArg(args.qualifier) and string.upper(args.qualifier) or nil""))
local i = 2
while isSet(args["qualifier" .. i]) do
1.116 ⟶ 1.161 lerroa:
i = i + 1
end
local parameters.formatting = isSetgetArg(args.formatting) and args.formatting or nil
local parameters.convert = isSetgetArg(args.convert) and args.convert or nil
local parameters.case = args.case
local parameters.list = getArg(args.list or, true; if (list, {firstrank== "false" or list == "no"'bestrank'}) then list = false end
parameters.shownovalue = getArg(args.shownovalue, true)
if list == 'firstrank' then list = 'bestrank' end -- alias
parameters.separator = getArg(args.separator)
parameters.conjunction = getArg(args.conjunction, parameters.separator)
parameters.qseparator = parameters.separator
parameters.qconjunction = parameters.conjunction
local sorting_col = args.tablesort
local sorting_up = (args.sorting or "") ~= "-1"
local separator = isSet(args.separator) and args.separator
local conjunction = isSet(args.conjunction) and args.conjunction or separator
local rowformat = args.rowformat
local references = args.references
1.130 ⟶ 1.177 lerroa:
local default = args.default
if default then showerrors = nil end
local editicon = not (args.editicon == "false" or args.editicon == "no" or formatting == "raw")
local parameters = {["id"] = id, ["property"] = property, ["formatting"] = formatting, ["convert"] = convert,
["list"] = list, ["case"] = case, ["editicon"] = editicon,
["separator"] = separator, ["conjunction"] = conjunction, ["qseparator"] = separator, ["qconjunction"] = conjunction}
parameters.lang = findLang(args.lang)
if parameters.formatting == "raw" then
parameters.editicon, parameters.labelicon = false, false
else
parameters.editicon, parameters.labelicon = setIcons(args.editicon, pargs.editicon) -- needs loadI18n by findLand
end
-- fetch property
local claims = {}
local bestrank = (parameters.list == false or parameters.list == 'bestrank') and parameters.list ~= 'lang'
for p in string.gmatch(parameters.property, 'P%d+') do
claims = getStatements(parameters.id, p, bestrank)
if #claims > 0 then
parameters.property = p
1.153 ⟶ 1.200 lerroa:
-- defaults for table
local preformat, postformat = "", ""
local whitelisted, blacklisted = false, false
local whitelist, blacklist, ignorevalue, selectvalue = {}, {}, {}, {}
if parameters.formatting == "table" then
parameters.separator = parameters.separator or "<br />"
1.182 ⟶ 1.229 lerroa:
-- set whitelist and blacklist values
whitelist, whitelistedblacklist, ignorevalue, selectvalue = setWhiteOrBlackList("whitelist", #qualifierId, args)
local next = next
blacklist, blacklisted = setWhiteOrBlackList("blacklist", #qualifierId, args)
if next(whitelist) ~= nil then whitelisted = true end
end
1.191 ⟶ 1.239 lerroa:
if itemgender then
if string.match(itemgender, "^P%d+$") then
local snak_id = getSnak(mw.wikibase.getBestStatements(parameters.id, itemgender), {1, "mainsnak", "datavalue", "value", "id"})
if snak_id then
idgender = snak_id
1.211 ⟶ 1.259 lerroa:
end
if gender_requested then
if feminineGender(idgender or parameters.id) then
parameters.gender = "feminineform"
end
1.230 ⟶ 1.278 lerroa:
table.sort(sortindices, comparator)
local result, result2, result_query
local error
if parameters.list or parameters.formatting == "table" then
1.269 ⟶ 1.317 lerroa:
params = tableParameters(args, parameters, j)
local valueq, sortkeyq, valueraw
if qual == parameters.property then -- hack for getting the property with another formatting, i.e. colformat1=raw
valueq, sortkeyq, _ = getValueOfClaim(claim, nil, params)
else
1.276 ⟶ 1.324 lerroa:
valueq, sortkeyq, valueraw = getValueOfParentClaim(claim, q, params)
elseif string.find(q, "^/.+") then
local claim2 = getStatements(parameters.id, string.sub(q, 2), bestrank)
if #claim2 > 0 then
valueq, sortkeyq, _ = getValueOfClaim(claim2[1], nil, params)
1.288 ⟶ 1.336 lerroa:
values[#values]["col" .. j] = valueq
sortkeys[#sortkeys]["col" .. j] = sortkeyq or valueq
if whitelist[j] or blacklist[j] or ignorevalue[j] or selectvalue[j] then
valueq = valueraw or getValueOfClaim(claim, qual, {["formatting"]="raw", ["lang"]=params.lang})
if whitelist[j] and whitelist[j][valueq or ""] then
1.294 ⟶ 1.342 lerroa:
elseif blacklist[j] and blacklist[j][valueq or ""] then
rowlist[#values] = false
elseif ignorevalue[j] and ignorevalue[j][valueq or ""] then
values[#values]["col" .. j] = nil
elseif selectvalue[j] and not selectvalue[j][valueq or ""] then
values[#values]["col" .. j] = nil
end
end
1.347 ⟶ 1.399 lerroa:
else
local rowformatting = rowformat .. "$" -- fake end character added for easy gsub
value = mw.ustring.gsub(rowformatting, "$0", {["$0"] = value})
value = mw.ustring.gsub(value, "$R0", reference) -- add reference
for i, _ in ipairs(qualifierId) do
local valueq = valuerow["col" .. i]
if args["rowsubformat" .. i] and isSet(valueq) then
-- add fake end character $
-- gsub $i not followed by a number so $1 doesn't match $10, $11...
1.378 ⟶ 1.430 lerroa:
end
-- in a table, add edit icon on last element
if parameters.formatting == 'table' and parameters.editicon then
result = addEditIconTable(result, parameters)
end
if args.query == 'num' then
result_query = 0
for _, v in pairs(rowlist) do
result_query = result_query + (v and 1 or 0)
end
end
result = preformat .. mw.text.listToText(result, parameters.separator, parameters.conjunction) .. postformat
1.387 ⟶ 1.445 lerroa:
result, result2, error = getValueOfClaim(claim, qualifierId[1], parameters)
if result and references then result = result .. getReferences(claim, parameters.lang) end
if args.query == 'num' then result_query = 1 end
end
if isSet(result) then
if i18n.addpencil and not (parameters.formatting == 'table' or (result2 and result2 == 'no-icon')) then
-- add edit icon, except table added previously and except explicit no-icon internal flag
result = result .. addEditIcon(parameters)
1.397 ⟶ 1.456 lerroa:
if showerrors then result = error else result = default end
end
returnif result,args.query == 'untranslated' and (required and not is_sandbox) and untranslated or ''then
result_query = untranslated
end
 
-- This is used to get the TA98 (Terminologia Anatomica first edition 1998) values like 'A01.1.00.005' (property P1323)
-- which are then linked to http://www.unifr.ch/ifaa/Public/EntryPage/TA98%20Tree/Entity%20TA98%20EN/01.1.00.005%20Entity%20TA98%20EN.htm
-- uses the newer mw.wikibase calls instead of directly using the snaks
-- formatPropertyValues returns a table with the P1323 values concatenated with ", " so we have to split them out into a table in order to construct the return string
p.getTAValue = function(frame)
local ent = mw.wikibase.getEntity()
local props = ent:formatPropertyValues('P1323')
local out = {}
local t = {}
for k, v in pairs(props) do
if k == 'value' then
t = mw.text.split( v, ", ")
for k2, v2 in pairs(t) do
out[#out + 1] = "[http://www.unifr.ch/ifaa/Public/EntryPage/TA98%20Tree/Entity%20TA98%20EN/" .. string.sub(v2, 2) .. "%20Entity%20TA98%20EN.htm " .. v2 .. "]"
end
end
end
return result, result_query or ''
local ret = table.concat(out, "<br> ")
if #ret == 0 then
ret = "Invalid TA"
end
return ret
end
 
1.430 ⟶ 1.468 lerroa:
end
 
local function getPropertyValue(id, property, parameter, langs, editicon, labelicon, case)
local snaks = mw.wikibase.getBestStatements(id, property)
local mysnak = getSnak(snaks, {1, "mainsnak"})
1.441 ⟶ 1.479 lerroa:
if mysnak.datavalue then
entity_id = "Q" .. tostring(mysnak.datavalue.value['numeric-id'])
result, _ = getSnakValue(mysnak, {formatting=parameter, lang=langs, editicon=editicon, labelicon=labelicon, case=case})
end
1.456 ⟶ 1.494 lerroa:
labelShow,
editicon,
labelicon,
upto,
upto_linkId,
1.487 ⟶ 1.526 lerroa:
local link, label, linktext, _id, _link
for _, propertySup in pairs(propertySups) do
_id, _link = getPropertyValue(id, propertySup, prop_format, languages, editicon, labelicon, grammatical_case)
if _id and _link then id = _id; link = _link break end
end
1.500 ⟶ 1.539 lerroa:
end
_, label = getPropertyValue(id, propertyLabel, label_format, languages, false, false, "infoboxlabel")
if labelShow == nil or labelFilter[label] then
result[#result + 1] = {label, link}
if label then
labelFilter[label] = nil -- only first label found
end
1.552 ⟶ 1.591 lerroa:
-- Returns pairs of instance label and property value fetching a recursive tree
function p.getParentValues(frame)
iflocal notargs required and= frame.args andor frame:getParent().args.sandbox then-- via invoke or require
local pargs = frame.args and frame:getParent().args or {}
if not required and isSet(pargs.sandbox) then
return require(wiki.module_title .. "/" .. mw.message.new('Sandboxlink-subpage-name'):inLanguage(wiki.langcode):plain()).getParentValues(frame)
end
local argsid = frame.getEntityId(args, or frame -- via invoke or requirepargs)
local id = getEntityId(frame)
if id == nil then return end
local languages = findLang(args.lang)
local propertySup = getArg(args.property; if not isSet(propertySup) then propertySup =, "P131" end) --administrative entity
local propertyLabel = getArg(args.label; if not isSet(propertyLabel) then propertyLabel =, "P31" end) --instance
local propertyLink = getArg(args.valuetext; if propertyLink == "" then propertyLink = nil end --internallink)
local property_format = getArg(args.formatting; if property_format == "" then property_format = nil end)
local label_format = getArg(args.labelformat; if not isSet(label_format) then label_format =, "label" end)
local upto = getArg(args.upto; if upto == "" then upto = nil end)
local last_only = getArg(args.last_only, == "true" or args.last_only == "yes"false)
local labelShow = getArg(args.labelshow; if labelShow == "" then labelShow = nil end)
local editicon, labelicon = not setIcons(args.editicon, == "false" or argspargs.editicon == "no")
local include_self = getArg(args.include_self, == "true" or args.include_self == "yes"false)
local case = getArg(args.case; if case == "" then case = nil end)
if isSet(args.uptolabelid) then
1.594 ⟶ 1.634 lerroa:
labelShow,
editicon,
labelicon,
upto,
args.uptovalueid or args.uptolinkid,
1.616 ⟶ 1.657 lerroa:
-- Link with a parent label --------------------
function p.linkWithParentLabel(frame)
iflocal notpargs required and= frame.args and isSet(frame:getParent().args.sandbox) thenor {}
if not required and isSet(pargs.sandbox) then
return require(wiki.module_title .. "/" .. mw.message.new('Sandboxlink-subpage-name'):inLanguage(wiki.langcode):plain()).linkWithParentLabel(frame)
end
1.633 ⟶ 1.675 lerroa:
-- get id value of property/qualifier
local largs = mw.clone(args)
largs.list = tonumber(args.list) and args.list or "true"
largs.formatting = "raw"
largs.separator = "/·/"
largs.editicon = "false"
local items_list, _ = p.claim(largs)
if not isSet(items_list) then return end
1.653 ⟶ 1.695 lerroa:
else
largs.formatting = "label"
largs.list = "false"
end
largs.property = args.parent
1.664 ⟶ 1.706 lerroa:
end
end
args.editicon, _ = not setIcons(args.editicon, == "false" or argspargs.editicon == "no")
args.id = getEntityId(frameargs, pargs)
args.lang = findLang(args.lang)
return mw.text.listToText(link_table) .. addEditIcon(args)
1.672 ⟶ 1.714 lerroa:
-- Calculate number of years old ----------------------------
function p.yearsOld(frame)
if not required and frame.args and isSet(frame:getParent().args.sandbox) then
return require(wiki.module_title .. "/" .. mw.message.new('Sandboxlink-subpage-name'):inLanguage(wiki.langcode):plain()).yearsOld(frame)
end
local args = frame.args or frame -- via invoke or require
local idpargs = getEntityId(frame.args and frame:getParent().args or {}
local id = getEntityId(args, pargs)
if id == nil then return end
local lang = mw.language.new('en')
1.779 ⟶ 1.823 lerroa:
-- Gets a label in a given language (content language by default) or its fallbacks, optionnally linked.
function p.getLabel(frame)
iflocal notargs required and= frame.args andor frame:getParent().args.sandbox then-- via invoke or require
local pargs = frame.args and frame:getParent().args or {}
if not required and isSet(pargs.sandbox) then
return require(wiki.module_title .. "/" .. mw.message.new('Sandboxlink-subpage-name'):inLanguage(wiki.langcode):plain()).getLabel(frame)
end
local argsid = frame.getEntityId(args, or frame -- via invoke orpargs, require1)
local id = getEntityId(frame, true)
if id == nil then return end
local languages = findLang(args.lang)
local editicon = not (args.editicon == "false" or args.editicon == "no") and mw.wikibase.isValidEntityId(id)
local labelicon = false
if mw.wikibase.isValidEntityId(id) then
_, labelicon = setIcons(args.editicon, pargs.editicon)
end
local label_icon = ''
1.792 ⟶ 1.841 lerroa:
label = args.label
else
local languages = findLang(args.lang)
-- exceptions or labels fixed
local exist, labels = pcall(require, wiki.module_title .. "/labels" .. (languages[1] == wiki.langcode and '' or '/' .. languages[1]))
1.807 ⟶ 1.855 lerroa:
label = mw.language.new(lang):ucfirst(mw.text.nowiki(label)) -- sanitize
end
label_icon = addLabelIcon(id, lang, languages[1], editiconlabelicon)
end
end
local linked = args.linked
local ret2 = required and untranslated or ''
if isSet(linked) and linked ~= "no" then
local article = mw.wikibase.getSitelink(id) or ("d:Special:EntityPage/" .. id)
return "[[" .. article .. "|" .. (label or id) .. "]]" .. label_icon, not required and '' or untranslatedret2
else
return (label or id) .. label_icon, not required and '' or untranslatedret2
end
end
1.825 ⟶ 1.874 lerroa:
-- Copied from Module:Wikibase
function p.getSiteLink(frame)
local idargs = getEntityId(frame,.args 1)or frame -- via invoke or require
local pargs = frame.args and frame:getParent().args or {}
if id == nil then
local id = getEntityId(args, pargs, 1)
return
if id == nil then return end
end
return mw.wikibase.getSitelink(id, mw.text.trim(frame.args[2] or ''))
end
1.840 ⟶ 1.889 lerroa:
-- Number of statements
function p.numStatements(frame)
local idargs = getEntityId(frame).args or frame -- via invoke or require
local pargs = frame.args and frame:getParent().args or {}
local id = getEntityId(args, pargs)
if id == nil then return 0 end
local prop = mw.text.trim(frame.args[1] or '')
local num = {}
if not isSet(prop) and frame.args[2] then -- qualifier
args = {}
local qual = mw.text.trim(frame.args[2])
for k, v in pairs(pargs) do
args[k] = v
end
for k, v in pairs(frame.args) do
args[k] = v
end
args.query = 'num'
_, num = p.claim(args)
return num
elseif args[2] then -- qualifier
local qual = mw.text.trim(args[2])
local values = p.claim{item=id, property=prop, qualifier=qual, formatting='raw', separator='/·/'}
if values then
1.858 ⟶ 1.920 lerroa:
-- Returns true if property datavalue is found excluding novalue/somevalue
function p.validProperty(frame)
local propertyargs = mw.text.trim(frame.args[1]) or frame -- via invoke or require
local itempargs = getEntityId(frame.args and frame:getParent().args or {}
local item = getEntityId(args, pargs)
if item == nil then return end
local property = mw.text.trim(args[1])
local prop_data = getSnak(mw.wikibase.getBestStatements(item, property), {1, "mainsnak", "datavalue"})
return prop_data and true or nil
end
 
function p.editAtWikidata(frame)
local args = frame.args or frame -- via invoke or require
local pargs = frame.args and frame:getParent().args or {}
local value = isSet(args[1])
if value then return end
local param = {}
param.id = getEntityId(args, pargs)
param.property = args.property
param.lang = findLang(args.lang)
param.editicon, _ = setIcons(args.editicon)
return addEditIcon(param)
end
 
function p.formatNum(frame)
local num = tonumber(mw.text.trim(frame.args[1]))
local lang = findLang(mw.text.trim(frame.args[2]))
return mw.language.new(lang[1]):formatNum(num)
end