Modulu:Wikidata: berrikuspenen arteko aldeak

Ezabatutako edukia Gehitutako edukia
update from ca.wiki
No edit summary
Etiketa: Manual revert
1. lerroa:
-- version 2020061520200421 from master @cawiki
 
local p = {}
31. lerroa:
[10] = "F Y", -- precision: month
[11] = "F j, Y", -- precision: day
["hms"] = {["hours"] = "h", ["minutes"] = "m", ["seconds"] = "s"}, -- duration: xh xm xs
},
41 ⟶ 39 lerroa:
},
["cite"] = { -- citeCite web parameters
["titleurl"] = "titleurl",
["authortitle"] = "authortitle",
["datewebsite"] = "datewebsite",
["pagesaccess-date"] = "pagesaccess-date",
["languagearchive-url"] = "languagearchive-url",
["archive-date"]= "archive-date",
-- cite web parameters
["urlauthor"] = "urlauthor",
["websitepublisher"] = "websitepublisher",
["access-datequote"] = "access-datequote",
["archive-urllanguage"] = "archive-urllanguage",
["archive-date"] = "archive-date",
["publisherpages"] = "publisherpages",
["quote"] = "quote",
-- cite journal parameters
["work"] = "work",
["issue"] = "issue",
["issn"] = "issn",
["doi"] = "doi"
},
78 ⟶ 70 lerroa:
 
local untranslated -- used in infobox modules: nil or true
local _ -- variable for unused returned values, avoiding globals
 
-- Module local functions --------------------------------------------
84 ⟶ 75 lerroa:
-- Credit to http://stackoverflow.com/a/1283608/2644759, cc-by-sa 3.0
local function tableMerge(t1, t2)
for k, v in pairs(t2) do
if type(v) == "table" then
if type(t1[k] or false) == "table" then
99 ⟶ 90 lerroa:
 
local function loadI18n(lang)
local exist, resi18n_title = pcall(require, wiki.module_title .. "/i18n")
if lang ~= wiki.langcode then i18n_title = "/i18n/" .. lang end
local exist, res = pcall(require, wiki.module_title .. i18n_title)
if exist and next(res) ~= nil then
tableMerge(i18n, res.i18n)
cases = res.cases
end
if lang ~= wiki.langcode and cases.location == nil then
exist, rescases.location = pcallrequire(require, wiki.module_title .. "'/i18n/" ').cases. lang)location
cases.locationcontext = require(wiki.module_title .. '/i18n').cases.locationcontext
if exist and next(res) ~= nil then
tableMerge(i18n, res.i18n)
tableMerge(cases, res.cases)
end
end
end
158 ⟶ 148 lerroa:
return label
end
 
-- get safely a serialized snak
local function getSnak(statement, snaks)
local ret = statement
for i, v in ipairs(snaks) do
if not ret then return end
ret = ret[v]
end
return ret
end
 
176 ⟶ 156 lerroa:
for _, l in ipairs(languages) do
if l == wiki.langcode then
-- using getLabelWithLang when possible instead of getLabelByLang, do not solve redirects pending phab:T157868
label, l = mw.wikibase.getLabelWithLang(id)
else
187 ⟶ 167 lerroa:
end
return label, lang
end
 
-- getBestStatements if bestrank=true, else getAllStatements with no deprecated
local function getStatements(entityId, property, bestrank)
local claims = {}
if not (entityId and mw.ustring.match(property, "^P%d+$")) then return claims end
if bestrank then
claims = mw.wikibase.getBestStatements(entityId, property)
else
local allclaims = mw.wikibase.getAllStatements(entityId, property)
for _, c in ipairs(allclaims) do
if c.rank ~= "deprecated" then
table.insert(claims, c)
end
end
end
return claims
end
 
209 ⟶ 172 lerroa:
local function feminineGender(id)
local claims = mw.wikibase.getBestStatements(id or mw.wikibase.getEntityIdForCurrentPage(),'P21')
if #claims == 0 then
if getSnak(claims, {1, "mainsnak", "datavalue"}) == nil then -- no claim, novalue or somevalue
return false
elseif claims[1].mainsnak.datavalue == nil then -- novalue or somevalue
return false
else
222 ⟶ 187 lerroa:
-- Fetch female form of label
local function feminineForm(id, lang)
local feminine_claims = getStatementsmw.wikibase.getBestStatements(id, 'P2521') -- female form of label
for _, feminine_claim in ipairs(feminine_claims) do
if getSnak(feminine_claim, {'.mainsnak', '.datavalue', '.value', '.language'}) == lang then
return feminine_claim.mainsnak.datavalue.value.text
end
end
end
 
-- get safely a serialized snak
local function getSnak(statement, snaks)
local ret = statement
for i, v in ipairs(snaks) do
if ret == nil then return end
ret = ret[v]
end
return ret
end
 
254 ⟶ 229 lerroa:
local ret = ''
if i18n.addpencil and parameters.editicon and parameters.id and parameters.property then
ret = ' <span data-bridge-edit-flow="single-best-valueoverwrite">'
.. "[[File:Arbcom ru editing.svg|10px|baseline|"
.. mw.message.new('Editlink'):inLanguage(parameters.lang[1]):plain()
335 ⟶ 310 lerroa:
local function resolveEntityId(id)
if not id or not mw.wikibase.isValidEntityId(id) then return id end
-- if no label in Englishlocal language nor its fallbacks, maybe it is a redirect
-- not using mw.title.new(id).isRedirect as it is expensive
if mw.wikibase.getLabel(id) == nil then
-- currently getLabelByLang does not follows redirects
if mw.wikibase.getLabelByLang(id, 'en') == nil then
local entity = mw.wikibase.getEntity(id) -- expensive function
if not entity then return nil end
347 ⟶ 321 lerroa:
require(wiki.module_title .. '/debug').track('redirect/' .. id)
else
-- no redirect and no English label, fix it to avoid expensive functions
require(wiki.module_title .. '/debug').track('label')
require(wiki.module_title .. '/debug').track('label/' .. id)
370 ⟶ 344 lerroa:
end
 
-- format data typevalue string
local function printDatatypeStringprintDatavalueString(data, parameters)
if mw.ustring.find((parameters.formatting or ''), '$1', 1, true) then -- formatting = a pattern
return expandBraces(mw.ustring.gsub(parameters.formatting, '$1', {['$1'] = data}), parameters.formatting)
elseif parameters.case then
return case(parameters.case, data, parameters.lang[1])
end
local data_number = string.match(data, "^%d+")
if data_number then -- sort key by initial number and remaining string
local sortkey = string.format("%019d", data_number * 1000)
return data, sortkey .. string.sub(data, #data_number + 1)
end
return data
395 ⟶ 364 lerroa:
return '[' .. data .. ' ' .. label .. ']'
end
return printDatatypeStringprintDatavalueString(data, parameters)
end
 
-- format data type external-id
local function printDatatypeExternal(data, parameters)
if parameters.formatting == 'externalid' then
local p_stat = mw.wikibase.getBestStatements(parameters.property, 'P1630') -- formatter URL
local p_link_pattern = getSnak(p_stat, {1, "mainsnak", "datavalue", "value"})
if p_link_pattern then
local p_link = mw.ustring.gsub(p_link_pattern, '$1', {['$1'] = data})
return '[' .. p_link .. ' ' .. data .. ']'
end
end
return printDatatypeString(data, parameters)
end
 
417 ⟶ 373 lerroa:
icon = "no-icon"
end
return printDatatypeStringprintDatavalueString(data, parameters), icon
end
 
-- format data typevalue globe-coordinateglobecoordinate
local function printDatatypeCoordinateprintDatavalueCoordinate(data, formatting)
local function globes(globe_id)
local globes = {['Q3134']='callisto',['Q596']='ceres',['Q15040']='dione',['Q2']='earth',['Q3303']='enceladus',
474 ⟶ 430 lerroa:
if unit_symbol == '' then
-- fetch it
local claims = mw.wikibase.getBestStatementsfindClaims(id, 'P5061')
if #claims > 0 then
local langclaims = {}
table.insert(lang, 'mul') -- multilingual as last try
518 ⟶ 474 lerroa:
end
 
local function roundDefPrecisionroundPrecision(in_num, factorout_num)
-- rounds out_num with significant figures of in_num (default precision)
local out_num = in_num * factor
if factor/60 == math.floor(factor/60) then -- sexagesimal integer
return out_num
end
-- first, count digits after decimal mark, handling cases like '12.345e6'
local exponent, prec
548 ⟶ 500 lerroa:
end
 
-- format data typevalue quantity
local function printDatatypeQuantityprintDatavalueQuantity(data, parameters)
local amount = data.amount
amount = mw.ustring.gsub(amount, "%+", "")
local suffix = ""
local conv_amount, conv_suffix
if string.sub(parameters.formatting or '', 1, 4) == "unit" or string.sub(parameters.formatting or '', 1, 8) == "duration" or parameters.convert then
-- example "unit": "http://www.wikidata.org/entity/Q174728"
local unit_id = data.unit
unit_id = mw.ustring.sub(unit_id, mw.ustring.find(unit_id, "Q"), -1)
566 ⟶ 519 lerroa:
end
elseif string.sub(parameters.convert or '', 1, 1) == "Q" then
convert_to = resolveEntityId(parameters.convert)
elseif string.sub(parameters.formatting or '', 1, 8) == "duration" then
convert_to = 'Q11574' -- seconds
end
if convert_to and convert_to ~= unit_id then
581 ⟶ 532 lerroa:
conv_amount = math.floor(tonumber(amount_f) + 0.5)
else
local conversions = getStatementsmw.wikibase.getAllStatements(unit_id, 'P2442') -- conversion to standard unit
table.insert(conversions, mw.wikibase.getBestStatements(unit_id, 'P2370')[1]) -- conversion to SI unit
for _, conv in ipairs(conversions) do
if conv.mainsnak.snaktype == 'value' then -- no somevalue nor novalue
if conv.mainsnak.datavalue.value.unit == "http://www.wikidata.org/entity/" .. convert_to then
conv_amount = roundDefPrecisionroundPrecision(amount, amount * tonumber(conv.mainsnak.datavalue.value.amount))
break
end
603 ⟶ 554 lerroa:
local lang_obj = mw.language.new(parameters.lang[1])
local sortkey = string.format("%019d", tonumber(amount) * 1000)
if string.sub(parameters.formatting or '', 1, 8) == "duration" then
local sec = tonumber(conv_amount or amount)
if parameters.formatting == 'durationhms' or parameters.formatting == 'durationh:m:s' then
local intervals = {"hours", "minutes", "seconds"}
local sec2table = lang_obj:getDurationIntervals(sec, intervals)
sec2table["seconds"] = (sec2table["seconds"] or 0) + tonumber("." .. (tostring(sec):match("%.(%d+)") or "0")) -- add decimals
local duration = ''
for i, v in ipairs(intervals) do
if parameters.formatting == 'durationh:m:s' then
if i == 1 and sec2table[v] then
duration = duration .. sec2table[v] .. ":"
elseif i == 2 then
duration = duration .. string.format("%02d", sec2table[v] or 0) .. ":"
elseif i == 3 then
local sec_str = tostring(lang_obj:formatNum(sec2table[v] or 0))
duration = duration .. (sec2table[v] < 10 and "0" or "") .. sec_str
end
elseif sec2table[v] then
duration = duration .. lang_obj:formatNum(sec2table[v]) .. i18n.datetime.hms[v] .. (i < 3 and " " or "")
end
end
return duration
else
return lang_obj:formatDuration(sec)
end
end
if parameters.case then
amount = case(parameters.case, amount, parameters.lang[1])
646 ⟶ 571 lerroa:
end
 
-- format data typevalue time
local function printDatatypeTimeprintDatavalueTime(data, parameters)
-- Dates and times are stored in ISO 8601 format
local timestamp = data.time
725 ⟶ 650 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
739 ⟶ 661 lerroa:
end
 
-- format data value wikibase-entityid: types wikibase-item, wikibase-propertyentity
local function printDatatypeEntityprintDatavalueEntity(data, parameters)
local entity_id = data['id']
if parameters.formatting == 'raw' then
if data['entity-type'] == 'item' then
entity_id = resolveEntityId(entity_id)
end
return entity_id, entity_id
end
795 ⟶ 720 lerroa:
end
 
-- format data typevalue monolingualtext
local function printDatatypeMonolingualprintDatavalueMonolingualText(data, parameters)
-- data fields: language [string], text [string]
814 ⟶ 739 lerroa:
end
return result
end
 
local function printError(key)
return '<span class="error">' .. i18n.errors[key] .. '</span>'
end
 
-- the "qualifiers" and "snaks" field have a respective "qualifiers-order" and "snaks-order" field
-- use these as the second parameter and this function instead of the built-in "pairs" function
-- to iterate over all qualifiers and snaks in the intended order.
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
 
function findClaims(entityId, property)
if not property or not entityId then return end
if not mw.ustring.match(property, "^P%d+$") then
-- get property id for the given label
property = mw.wikibase.resolvePropertyId(property)
if not property then return end
end
local claims = mw.wikibase.getAllStatements(entityId, property)
if #claims == 0 then
claims = nil
end
return claims
end
 
local function getSnakValue(snak, parameters)
if snak.snaktype == 'value' then
-- call the respective snak parser
-- see Special:ListDatatypes
if snak.datatype == "string"'math' then
return printDatatypeString(snak.datavalue.value, parameters)
-- other data value string, tabular-data not implemented
elseif snak.datatype == "commonsMedia" then
return printDatatypeMedia(snak.datavalue.value, parameters)
elseif snak.datatype == "url" then
return printDatatypeUrl(snak.datavalue.value, parameters)
elseif snak.datatype == "external-id" then
return printDatatypeExternal(snak.datavalue.value, parameters)
elseif snak.datatype == 'math' then
return printDatatypeMath(snak.datavalue.value)
elseif snak.datatype == 'musical-notation' then
return printDatatypeMusical(snak.datavalue.value, parameters.formatting)
elseif snak.datatype == "url" then
-- other data types
return printDatatypeUrl(snak.datavalue.value, parameters)
elseif snak.datatype == 'wikibase-item' or snak.datatype == 'wikibase-property' then
elseif snak.datatype == "commonsMedia" then
return printDatatypeEntity(snak.datavalue.value, parameters)
return printDatatypeMedia(snak.datavalue.value, parameters)
elseif snak.datatype == 'monolingualtext' then
returnelseif printDatatypeMonolingual(snak.datavalue.value,type parameters)== "string" then
return printDatavalueString(snak.datavalue.value, parameters)
elseif snak.datatype == "globe-coordinate" then
returnelseif printDatatypeCoordinate(snak.datavalue.value,type parameters.formatting)== "globecoordinate" then
return printDatavalueCoordinate(snak.datavalue.value, parameters.formatting)
elseif snak.datatype == "quantity" then
returnelseif printDatatypeQuantity(snak.datavalue.value,type parameters)== "quantity" then
return printDatavalueQuantity(snak.datavalue.value, parameters)
elseif snak.datatype == "time" then
returnelseif printDatatypeTime(snak.datavalue.value,type parameters)== "time" then
return printDatavalueTime(snak.datavalue.value, parameters)
elseif snak.datavalue.type == 'wikibase-entityid' then
return printDatavalueEntity(snak.datavalue.value, parameters)
elseif snak.datavalue.type == 'monolingualtext' then
return printDatavalueMonolingualText(snak.datavalue.value, parameters)
end
elseif snak.snaktype == 'novalue' then
852 ⟶ 808 lerroa:
end
return mw.wikibase.renderSnak(snak)
end
 
local function printError(key)
return '<span class="error">' .. i18n.errors[key] .. '</span>'
end
 
888 ⟶ 840 lerroa:
end
 
local function getValueOfClaim(claim, qualifierId, parameters)
local snak, error = getQualifierSnak(claim, qualifierId, parameters)
if not snak then
return nil, nil, error
elseif snak[1] then -- a multi qualifier
local result, sortkey = {}, {}
local maxvalssortkey = tonumber(parameters.list){}
for idx in pairs(snak) do
result[#result + 1], sortkey[#sortkey + 1] = getSnakValue(snak[idx], parameters)
if maxvals and maxvals == #result then break end
end
return mw.text.listToText(result, parameters.qseparator, parameters.qconjunction), sortkey[1]
924 ⟶ 875 lerroa:
end
 
local function getReferences(claim)
-- see d:Help:Sources
local function getReferences(claim, lang)
local notproperref = {
["P143"] = true, -- imported from
938 ⟶ 888 lerroa:
local refs = {}
local validref = true
local ref_name
-- traverse through all parts of the current reference
for snakkey, snakval in pairs(claim.references[ref].snaks or {}) do
950 ⟶ 899 lerroa:
for snakidx = 1, #snakval do
if snakidx > 1 then refparts = refparts .. ", " end
refparts = refparts or '' .. getSnakValue(snakval[snakidx], {lang=lang{wiki.langcode}})
end
refs[snakkey] = refparts
refparts = nil
if snakkey == "P248" then -- stated in
ref_name = snakval[1].datavalue.value.id
end
end
end
-- get title of general template for citing web references
-- fill missing values with parent item
local template = mw.wikibase.getSitelink('Q5637226') or ""
if ref_name then
template = mw.text.split(template, ":")[2] -- split off namespace from front
local function refParent(qid, pid, formatting)
local snak = getSnak(mw.wikibase.getBestStatements(qid, pid), {1, "mainsnak"})
return snak and getSnakValue(snak, {formatting=formatting, lang=lang})
end
refs['P50'] = refs['P50'] or refParent(ref_name, 'P50', 'label') -- author
refs['P407'] = refs['P407'] or refParent(ref_name, 'P407', 'label') -- language of work
refs['P123'] = refs['P123'] or refParent(ref_name, 'P123', 'label') -- publisher
refs['P577'] = refs['P577'] or refParent(ref_name, 'P577') -- date
refs['P1433'] = refs['P1433'] or refParent(ref_name, 'P1433', 'label') -- published in
refs['P304'] = refs['P304'] or refParent(ref_name, 'P304') -- page(s)
refs['P433'] = refs['P433'] or refParent(ref_name, 'P433') -- issue
refs['P236'] = refs['P236'] or refParent(ref_name, 'P236') -- ISSN
refs['P356'] = refs['P356'] or refParent(ref_name, 'P356') -- DOI
end
-- get title of local templates for citing references
local template_web = mw.wikibase.getSitelink('Q5637226') or ""
template_web = mw.text.split(template_web, ":")[2] -- split off namespace from front
local template_journal = mw.wikibase.getSitelink('Q5624899') or ""
template_journal = mw.text.split(template_journal, ":")[2]
-- if both "reference URL" and "title" (or "stated in") are present, then use local cite web template
local citeParams = {}
if refs['P854'] and (refs['P1476'] or refs['P248']) and template_webtemplate then
local citeParams = {}
-- if both "reference URL" and "title" (or "stated in") are present, then use cite web template
citeParams[i18n['cite']['url']] = refs['P854']
if refsciteParams[i18n['P248cite']['title']] and= refs['P1476'] ==or nil thenrefs['P248']:match("^%[%[.-|(.-)%]%]")
citeParams[i18n['cite']['title']] = refs['P248']:match("^%[%[.-|(.-)%]%]")
else
citeParams[i18n['cite']['title']] = refs['P1476']
citeParams[i18n['cite']['website']] = refs['P248']
end
citeParams[i18n['cite']['author']] = refs['P50']
citeParams[i18n['cite']['languagewebsite']] = refs['P407P248']
citeParams[i18n['cite']['language']] = refs['P2439']
citeParams[i18n['cite']['publisher']] = refs['P123']
citeParams[i18n['cite']['date']] = refs['P577']
1.003 ⟶ 925 lerroa:
citeParams[i18n['cite']['archive-date']] = refs['P2960']
citeParams[i18n['cite']['quote']] = refs['P1683']
refparts = mw.getCurrentFrame():expandTemplate{title=template_webtemplate, args=citeParams}
else
elseif refs['P1433'] and (refs['P1476'] or refs['P248']) and template_journal then
-- if both "published in" and "title" (or "stated in") are present, then use cite journal template
citeParams[i18n['cite']['work']] = refs['P1433']
citeParams[i18n['cite']['title']] = refs['P1476'] or refs['P248']
citeParams[i18n['cite']['author']] = refs['P50']
citeParams[i18n['cite']['date']] = refs['P577']
citeParams[i18n['cite']['issue']] = refs['P433']
citeParams[i18n['cite']['pages']] = refs['P304']
citeParams[i18n['cite']['language']] = refs['P407']
citeParams[i18n['cite']['issn']] = refs['P236']
citeParams[i18n['cite']['doi']] = refs['P356']
refparts = mw.getCurrentFrame():expandTemplate{title=template_journal, args=citeParams}
elseif validref then
-- raw ouput
local snaksorder = claim.references[ref]["snaks-order"]
local function indexed(a)
for _, b in ipairs(snaksorder) do
if b == a then return true end
end
return false
end
for k, _ in pairs(refs or {}) do
if not indexed(k) then
table.insert(snaksorder, k)
end
end
local italics = "''"
for _k, kv in ipairsorderedpairs(snaksorderrefs or {}, claim.references[ref]["snaks-order"]) do
if refs[k] and v then
refparts = refparts and refparts .. " " or ""
refparts = refparts .. mw.ustring.gsub(getLabelByLangsmw.wikibase.getLabel(k, lang), "^%l", mw.ustring.upper) .. ": "
refparts = refparts .. italics .. refs[k]v .. italics .. "."
italics = ""
end
end
end
if refparts then result = result .. mw.getCurrentFrame():extensionTag("ref", refparts, {name=ref_name}) end
end
return result
1.053 ⟶ 951 lerroa:
listed = true
list[tostring(i)] = {}
forlocal vvalues in= stringmw.gmatchtext.split(args[type_list .. i], 'Q%d+')"/", dotrue)
for _, v in ipairs(values) do
list[tostring(i)][v] = true
list[tostring(i)][resolveEntityId(v)] = true
end
1.091 ⟶ 991 lerroa:
-- on debug console use: =p.claim{item="Q...", property="P...", ...}
function p.claim(frame)
localif is_sandboxnot =required and frame.args and isSet(frame:getParent().args.sandbox) then
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
1.116 ⟶ 1.015 lerroa:
i = i + 1
end
local formatting = isSet(args.formatting); andif args.formatting or== "" then formatting = nil end
local convert = isSet(args.convert); andif args.convert or== "" then convert = nil end
local case = args.case
local list = args.list or true; if (list == "false" or list == "no") then list = false end
if list == 'firstrank' then list = 'bestrank' end -- alias
local sorting_col = args.tablesort
local sorting_up = (args.sorting or "") ~= "-1"
1.136 ⟶ 1.034 lerroa:
["separator"] = separator, ["conjunction"] = conjunction, ["qseparator"] = separator, ["qconjunction"] = conjunction}
parameters.lang = findLang(args.lang)
-- fetch property
local claims = {}
local bestrank = (parameters.list == false or parameters.list == 'bestrank') and parameters.list ~= 'lang'
for p in string.gmatch(property, 'P%d+') do
claims = getStatements(id, p, bestrank)
if #claims > 0 then
parameters.property = p
break
end
end
if #claims == 0 then
if showerrors then return printError("property-not-found") else return default end
end
-- defaults for table
1.184 ⟶ 1.068 lerroa:
whitelist, whitelisted = setWhiteOrBlackList("whitelist", #qualifierId, args)
blacklist, blacklisted = setWhiteOrBlackList("blacklist", #qualifierId, args)
end
-- fetch property
local claims
for p in string.gmatch(property, 'P%d+') do
claims = findClaims(id, p)
if claims and claims[1] then
parameters.property = p
break
end
end
if not claims or not claims[1] then
if showerrors then return printError("property-not-found") else return default end
end
-- set feminine case if gender is requested
local itemgender = args.["itemgender"]
local idgender
if itemgender then
1.245 ⟶ 1.142 lerroa:
local sortkeys = {}
local refs = {}
local firstrank = parameters.list == "firstrank" and claims[sortindices[1]].rank or ''
local rowlist = {} -- rows to list with whitelist or blacklist
for idx in pairs(claims) do
1.250 ⟶ 1.148 lerroa:
local reference = {}
if not whitelisted then rowlist[idx] = true end
if firstrank ~= '' and firstrank ~= claim.rank then
break
end
if parameters.formatting == "table" then
local params = tableParameters(args, parameters, "0")
1.276 ⟶ 1.177 lerroa:
valueq, sortkeyq, valueraw = getValueOfParentClaim(claim, q, params)
elseif string.find(q, "^/.+") then
local claim2 = getStatementsfindClaims(id, string.sub(q, 2), bestrank)
if #claim2 > 0 then
valueq, sortkeyq, _ = getValueOfClaim(claim2[1], nil, params)
end
1.318 ⟶ 1.219 lerroa:
end
if sorting_col then
local sorting_table = mw.text.split(sorting_col, '%D+/', true)
local comparator = function(a, b)
local valuea, valueb
1.335 ⟶ 1.236 lerroa:
table.sort(sortindices, comparator)
end
local maxvals = tonumber(parameters.list)
result = {}
for idx in pairs(values) do
local valuerow = values[sortindices[idx]]
local reference = getReferences({["references"] = refs[sortindices[idx]]["col0"]}, parameters.lang)
value = valuerow["col0"]
1.372 ⟶ 1.272 lerroa:
if isSet(value) then
result[#result + 1] = value
if not parameters.list or (maxvals and maxvals == #result) then
break
end
1.386 ⟶ 1.286 lerroa:
local claim = claims[sortindices[1]]
result, result2, error = getValueOfClaim(claim, qualifierId[1], parameters)
if result and references then result = result .. getReferences(claim, parameters.lang) 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 flagcases
result = result .. addEditIcon(parameters)
end
1.397 ⟶ 1.297 lerroa:
if showerrors then result = error else result = default end
end
return result, (required and not is_sandbox)required and untranslated'' or ''untranslated
end
 
1.432 ⟶ 1.332 lerroa:
local function getPropertyValue(id, property, parameter, langs, editicon, case)
local snaks = mw.wikibase.getBestStatements(id, property)
local mysnak = getSnak(snaks, {1, "mainsnak"})
if mysnaksnaks ==and nilsnaks[1] and snaks[1].mainsnak then
mysnak = snaks[1].mainsnak
else
return
end
1.445 ⟶ 1.347 lerroa:
return entity_id, result
end
 
local function contains(tab, val)
for index, value in ipairs(tab) do
if value == val then
return true
end
end
return false
end
 
1.462 ⟶ 1.374 lerroa:
include_self)
if (upto_linkId == nil) then upto_linkId = "" end
local upto_link_ids = {}mw.text.split(upto_linkId, '[/%s]+')
forlocal qpropertySups in= mw.text.gsplitsplit(upto_linkIdpropertySupString, '[^Q/%ds]+') do
upto_link_ids[resolveEntityId(q)] = true
end
local propertySups = mw.text.split(propertySupString, '[^P%d]')
local lastlabel = uc_first(upto or '')
local maxloop = tonumber(upto) or ((lastlabel .. upto_linkId) == '' and 10 or 50)
local labelFilter = {}
if labelShow then
for _i, v in ipairs(mw.text.split(labelShow, "/")) do
labelFilter[uc_first(v)] = true
end
1.483 ⟶ 1.392 lerroa:
local result = {}
local label, link, linktext
for iter = 1, maxloop do
local link, label, linktext, _id, _linklink
for _, propertySup in pairs(propertySups) do
_id, _link = getPropertyValue(id, propertySup, prop_format, languages, editicon, grammatical_case)
if _id and _link then id = _id; link = _link break end
end
1.500 ⟶ 1.411 lerroa:
end
_, label = getPropertyValue(id, propertyLabel, label_format, languages, falseediticon, "infoboxlabel")
if labelShow == nil or labelFilter[label] then
1.510 ⟶ 1.421 lerroa:
end
if not tonumber(upto) and label == lastlabel or upto_link_ids[id] then
break
end
if contains(upto_link_ids, id) then
break
end
1.572 ⟶ 1.487 lerroa:
if isSet(args.uptolabelid) then
upto, _ = getLabelByLangsmw.wikibase.getLabel(args.uptolabelid, languages)
end
if isSet(args.showlabelid) then
local showLabelList = {}
for substring in mw.text.gsplit(args.showlabelid, '[^Q/%ds]+') do
table.insert(showLabelList, (getLabelByLangsmw.wikibase.getLabel(substring, languages)))
end
if #showLabelList > 0 then
1.595 ⟶ 1.510 lerroa:
editicon,
upto,
args.uptovalueid or args.uptolinkid,
last_only,
case,
1.616 ⟶ 1.531 lerroa:
-- Link with a parent label --------------------
function p.linkWithParentLabel(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()).linkWithParentLabel(frame)
end
1.633 ⟶ 1.548 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
local items_table = mw.text.split(items_list, "/·/", true)
1.643 ⟶ 1.558 lerroa:
-- get internal link of property/qualifier
largs.formatting = "internallink"
local link_list, _ = p.claim(largs)
local link_table = mw.text.split(link_list, "/·/", true)
-- get label of parent property
local parent_claim = getSnak(getStatementsfindClaims(items_table[1], args.parent, true), {1, "mainsnak", "datatype"})
if parent_claim == 'monolingualtext' then
largs.formatting = nil
1.659 ⟶ 1.574 lerroa:
for i, v in ipairs(items_table) do
largs.item = v
local link_label, _ = p.claim(largs)
if isSet(link_label) then
link_table[i] = mw.ustring.gsub(link_table[i] or '', "%[%[(.*)%|.+%]%]", "[[%1|" .. link_label .. "]]")
1.756 ⟶ 1.671 lerroa:
end
if not isSet(yo_pl) then
yo_pl, _ = getLabelByLangs('Q24564698', langs)
yo_sg = yo_pl
end
1.800 ⟶ 1.715 lerroa:
if label == nil then
label,local langnew_id = getLabelByLangsresolveEntityId(id, languages)
if labelnew_id then
label, lang = getLabelByLangs(new_id, languages)
if args.itemgender and feminineGender(args.itemgender) then
if label = feminineForm(id, lang) or labelthen
if args.itemgender and feminineGender(args.itemgender) then
label = feminineForm(new_id, lang) or label
end
label = mw.language.new(lang):ucfirst(mw.text.nowiki(label)) -- sanitize
end
label_icon = addLabelIcon(new_id or id, lang, languages[1], editicon)
label = mw.language.new(lang):ucfirst(mw.text.nowiki(label)) -- sanitize
end
label_icon = addLabelIcon(id, lang, languages[1], editicon)
end
end
1.813 ⟶ 1.731 lerroa:
local linked = args.linked
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 untranslated
else
1.841 ⟶ 1.759 lerroa:
function p.numStatements(frame)
local id = getEntityId(frame)
if id == nil then
return 0 end
local prop = mw.text.trim(frame.args[1])
local num = {}
if frame.args[2] then -- qualifier
local qual = mw.text.trim(frame.args[2])
local values = p.claim{item=id, property=prop, qualifier=qual, formatting='raw', separator='/·/'}
if values then
num = mw.text.split(values, '/·/')
end
else
num = mw.wikibase.getBestStatements(id, prop)
end
local args = frame.args
local prop = mw.text.trim(args[1])
local num = mw.wikibase.getBestStatements(id, prop)
return #num
end
1.861 ⟶ 1.773 lerroa:
local item = getEntityId(frame)
if item == nil then return end
local prop_dataproperties = getSnak(mw.wikibase.getBestStatements(item, property), {1, "mainsnak", "datavalue"})
if #properties == 0 then return end
return prop_data and true or nil
return properties[1].mainsnak.datavalue and true or nil
end