Mòdul:Wikidades: diferència entre les revisions

Contingut suprimit Contingut afegit
version 20201119
getParentValues: unificació upto/uptolabelid i labelshow/showlabelid, corr. include_self
Línia 1:
-- version 2020111920201123 from master @cawiki
 
local p = {}
Línia 1.474:
 
local function uc_first(word)
if upto_valueword == nil then upto_value = ""return end
return mw.ustring.upper(mw.ustring.sub(word, 1, 1)) .. mw.ustring.sub(word, 2)
end
Linha 1.501 ⟶ 1.502:
propertyLabel,
propertyLink,
label_show,
labelShow,
labelicon0,
labelicon1,
Linha 1.511 ⟶ 1.512:
include_self)
if upto_value == nil then upto_value = "" end
local upto_link_ids = {}
for q in mw.text.gsplit(upto_value, '[^Q%d]') do
upto_link_ids[resolveEntityId(q)] = true
end
local propertySups = mw.text.split(propertySupString, '[^P%d]')
local lastlabelmaxloop = uc_first(upto_label or '')10
if labelShowupto_number then
local maxloop = tonumber(upto_number) or ((lastlabel .. upto_value) == '' and 10 or 50)
maxloop = tonumber(upto_number)
elseif next(upto_label) or next(upto_value) then
local labelFilter = {}
maxloop = 50
if labelShow then
for _, v in ipairs(mw.text.split(labelShow, "/")) do
labelFilter[uc_first(v)] = true
end
end
local labels_filter = next(label_show)
local label_self
_, label_self = getPropertyValue(id, propertyLabel, label_format, languages)
local result = {}
local id_value = id
for iter = 1, maxloop do
local link, label, labelwicon, linktext, _id, _linkid_label
for _, propertySup in pairs(propertySups) do
_idid_value, _linklink = getPropertyValue(idid_value, propertySup, prop_format, languages, labelicon1, grammatical_case)
if _idid_value and _linklink then id = _id; link = _link break end
end
if not idid_value or not link then break end
if propertyLink then
_, linktext = getPropertyValue(idid_value, propertyLink, "label", languages)
if linktext then
link = mw.ustring.gsub(link, "%[%[(.*)%|.+%]%]", "[[%1|" .. linktext .. "]]")
Linha 1.549 ⟶ 1.541:
end
_id_label, label = getPropertyValue(idid_value, propertyLabel, label_format, languages, false, "infoboxlabel")
if labelicon0 then
_, labelwicon = getPropertyValue(idid_value, propertyLabel, label_format, languages, labelicon0, "infoboxlabel")
else
labelwicon = label
end
if labelShowlabels_filter == nil or labelFilter(label_show[id_label] or label_show[label]) then
result[#result + 1] = {labelwicon, link}
labelFilterlabel_show[id_label or 'none'], label_show[label or 'none'] = nil, nil -- only first label found
if label then
labelFilter[label] = nil -- only first label found
end
end
if labelupto_label[id_label] ==or lastlabelupto_label[label] or upto_link_idsupto_value[idid_value] then
break
end
Linha 1.573 ⟶ 1.562:
end
if include_self then table.insert(result, 1, {label_self, mw.title.getCurrentTitle().text}) end
local label_self, link_self
_, label_self = getPropertyValue(id, propertyLabel, label_format, languages, labelicon0, "infoboxlabel")
table.insert(showLabelListlink_self, (_ = getLabelByLangs(substringid, languages)))
table.insert(result, 1, {label_self, link_self})
end
return result
Linha 1.624 ⟶ 1.618:
local upto_number = getArg(args.upto)
local last_only = getArg(args.last_only, false)
local labelShow = getArg(args.labelshow)
local editicon, labelicon = setIcons(args.editicon, pargs.editicon)
local include_self = getArg(args.include_self, false)
local case = getArg(args.case)
local upto_label = {}
iffor isSetq in string.gmatch(args.uptolabelid or '', 'Q%d+') thendo
upto_link_ids[local checked_q = resolveEntityId(q)] = true
upto_label, _ = getLabelByLangs(args.uptolabelid, languages) -- TODO table of label ids
if checked_q then
elseif type(upto_number) == 'string' then
upto_label[checked_q] = upto_numbertrue
end
end
elseifif type(upto_number) == 'string' then
upto_label[uc_first(upto_number)] = true
upto_number = nil
require(wiki.module_title .. '/debug').track('upto') -- replace upto by uptolabelid
end
local upto_link_idsupto_value = {}
if isSet(args.showlabelid) then
for q in string.gmatch(args.uptovalueid or args.uptolinkid or '', 'Q%d+') do
local showLabelList = {}
local checked_q = resolveEntityId(q)
for substring in mw.text.gsplit(args.showlabelid, '[^Q%d]') do
if checked_q then
table.insert(showLabelList, (getLabelByLangs(substring, languages)))
upto_value[checked_q] = true
end
end
if #showLabelList > 0 then
labelShow = table.concat(showLabelList,"/")
local labelFilterlabel_show = {}
for substringq in mwstring.text.gsplitgmatch(args.showlabelid or '', '[^Q%d]+') do
local checked_q = resolveEntityId(q)
if checked_q then
label_show[checked_q] = true
end
end
for _, v in ipairs(mw.text.split(labelShowargs.labelshow or '', "/")) do
if labelv ~= '' then
labelFilterlabel_show[uc_first(v)] = true
require(wiki.module_title .. '/debug').track('labelshow') -- replace labelshow by showlabelid
end
end
Linha 1.661 ⟶ 1.670:
propertyLabel,
propertyLink,
labelShowlabel_show,
labelicon0,
labelicon1,
upto_number,
upto_label,
upto_value,
args.uptovalueid or args.uptolinkid,
last_only,
case,
Linha 1.753 ⟶ 1.762:
local function getBestValue(id, prop)
local snak_value =return getSnak(mw.wikibase.getBestStatements(id, prop), {1, "mainsnak", "datavalue", "value"})
return snak_value
end