Changes

Jump to navigation Jump to search
m
1 revision imported
else
local ccat = mw.wikibase.getBestStatements(id, "P373")[1]
if ccat and ccat.mainsnak.datavalue then
ccat = ccat.mainsnak.datavalue.value
disp = "[[" .. lprefix .. "Category:" .. ccat .. lpostfix .. "|" .. prefix .. label .. postfix .. "]]"
until finished or count >= 10 -- limit to 10 levels to avoid infinite loops
if not first then table.remove(out, 1) end
-- we might have duplicate text for consecutive locations, so remove them
if #out > 2 then
local plain = {}
for i, v in ipairs(out) do
-- strip any links
plain[i] = v:gsub("^%[%[[^|]*|", ""):gsub("]]$", "")
end
local idx = 2
repeat
if plain[idx] == plain[idx-1] then
-- duplicate found
local removeidx = 0
if (plain[idx] ~= out[idx]) and (plain[idx-1] == out[idx-1]) then
-- only second one is linked, so drop the first
removeidx = idx - 1
elseif (plain[idx] == out[idx]) and (plain[idx-1] ~= out[idx-1]) then
-- only first one is linked, so drop the second
removeidx = idx
else
-- pick one
removeidx = idx - (os.time()%2)
end
table.remove(out, removeidx)
table.remove(plain, removeidx)
else
idx = idx +1
end
until idx >= #out
end
return out
end
local qid3 = statements2[1].mainsnak.datavalue.value.id
local sitelink = mw.wikibase.sitelink(qid3)
-- if there's no local sitelink , create the sitelink from English label if not sitelink then local lbl = sitelink or mw.wikibase.labelgetLabelByLang(qid3, "en") if lbl then if lbl:sub(1,9) == "Category:" then sitelink = mw.text.nowiki(lbl) else sitelink = "Category:" .. mw.text.nowiki(lbl) end end end
if sitelink then
if sk ~= "" then
end -- of loop through values of property1
return assembleoutput(out, args, qid1, pid1)
end
 
 
-------------------------------------------------------------------------------
-- getIntersectCat takes most of the usual parameters.
-- The usual whitelisting, blacklisting, onlysourced, etc. are implemented
-- It takes two properties, |prop1 and |prop2 (e.g. occupation and country of citizenship)
-- Each property's value is a wiki-base entity
-- For each value of the first parameter (ranks implemented) it fetches the value's main category
-- and then each value of the second parameter (possibly substituting a simpler description)
-- then it returns all of the categories representing the intersection of those properties,
-- (e.g. Category:Actors from Canada). A joining term may be supplied (e.g. |join=from).
-- The item's P734 (family name) is the sort key, or no sort key if there is no family name.
-- The sort key may be overridden by the parameter |sortkey (alias |sk).
-------------------------------------------------------------------------------
-- Dependencies: parseParam; setRanks; parseInput; sourced; propertyvalueandquals assembleoutput;
-------------------------------------------------------------------------------
p.getIntersectCat = function(frame)
frame.args.reqranks = setRanks(frame.args.rank)
frame.args.langobj = findLang(frame.args.lang)
frame.args.lang = frame.args.langobj.code
local args = frame.args
args.sep = " "
args.linked = "no"
local pid1 = args.prop1 or "P106"
local pid2 = args.prop2 or "P27"
if pid1 == "" or pid2 == "" then return nil end
local qid, statements1 = parseInput(frame, "", pid1)
if not qid then return nil end
local qid, statements2 = parseInput(frame, "", pid2)
if not qid then return nil end
-- topics like countries may have different names in categories from their label in Wikidata
local subs_exists, subs = pcall(mw.loadData, "Module:WikidataIB/subs")
local join = args.join or ""
local onlysrc = parseParam(args.onlysourced or args.osd, true)
local maxvals = tonumber(args.maxvals) or 0
-- linkprefix (strip quotes)
local lp = (args.linkprefix or args.lp or ""):gsub('"', '')
-- sort key (strip quotes, hyphens and periods):
local sk = (args.sortkey or args.sk or ""):gsub('["-.]', '')
-- family name:
local famname = ""
if sk == "" then
local p734 = mw.wikibase.getBestStatements(qid, "P734")[1]
local p734id = p734 and p734.mainsnak.snaktype == "value" and p734.mainsnak.datavalue.value.id or ""
famname = mw.wikibase.sitelink(p734id) or ""
-- strip namespace and disambigation
local pos = famname:find(":") or 0
famname = famname:sub(pos+1):gsub("%s%(.+%)$", "")
if famname == "" then
local lbl = mw.wikibase.label(p734id)
famname = lbl and mw.text.nowiki(lbl) or ""
end
end
local cat1 = {}
for k, v in ipairs(statements1) do
if not onlysrc or sourced(v) then
-- get the ID representing the value of the property
local pvalID = (v.mainsnak.snaktype == "value") and v.mainsnak.datavalue.value.id
if pvalID then
-- get the topic's main category (P910) for that entity
local p910 = mw.wikibase.getBestStatements(pvalID, "P910")[1]
if p910 and p910.mainsnak.snaktype == "value" then
local tmcID = p910.mainsnak.datavalue.value.id
-- use sitelink or the English label for the cat
local cat = mw.wikibase.sitelink(tmcID)
if not cat then
local lbl = mw.wikibase.getLabelByLang(tmcID, "en")
if lbl then
if lbl:sub(1,9) == "Category:" then
cat = mw.text.nowiki(lbl)
else
cat = "Category:" .. mw.text.nowiki(lbl)
end
end
end
cat1[#cat1+1] = cat
end -- of test for topic's main category exists
end -- of test for property has vaild value
end -- of test for sourced
if maxvals > 0 and #cat1 >= maxvals then break end
end
local cat2 = {}
for k, v in ipairs(statements2) do
if not onlysrc or sourced(v) then
local cat = rendersnak(v, args)
if subs[cat] then cat = subs[cat] end
cat2[#cat2+1] = cat
end
if maxvals > 0 and #cat2 >= maxvals then break end
end
out = {}
for k1, v1 in ipairs(cat1) do
for k2, v2 in ipairs(cat2) do
if sk ~= "" then
out[#out+1] = "[[" .. lp .. v1 .. " " .. join .. " " .. v2 .. "|" .. sk .. "]]"
elseif famname ~= "" then
out[#out+1] = "[[" .. lp .. v1 .. " " .. join .. " " .. v2 .. "|" .. famname .. "]]"
else
out[#out+1] = "[[" .. lp .. v1 .. " " .. join .. " " .. v2 .. "]]"
end -- of check for sort keys
end
end
args.noicon = "true"
return assembleoutput(out, args, qid, pid1)
end

Navigation menu