Module:WikidataIB and Module:WikidataIB/sandbox1: Difference between pages
From HandWiki
(Difference between pages)
imported>Jworkorg m (1 revision imported) |
imported>Jworkorg m (1 revision imported) |
||
Line 1: | Line 1: | ||
-- Version: 2020- | -- Version: 2020-09-22 | ||
-- Module to implement use of a blacklist and whitelist for infobox fields | -- Module to implement use of a blacklist and whitelist for infobox fields | ||
-- Can take a named parameter |qid which is the Wikidata ID for the article | -- Can take a named parameter |qid which is the Wikidata ID for the article | ||
Line 565: | Line 565: | ||
-- shortname is boolean switch to use P1813 (short name) instead of label if true. | -- shortname is boolean switch to use P1813 (short name) instead of label if true. | ||
-- lang is the current language code. | -- lang is the current language code. | ||
------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | ||
-- Dependencies: labelOrId(); donotlink[] | -- Dependencies: labelOrId(); donotlink[] | ||
------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | ||
local linkedItem = function(id, lprefix, lpostfix, prefix, postfix, dtxt, shortname, lang | local linkedItem = function(id, lprefix, lpostfix, prefix, postfix, dtxt, shortname, lang) | ||
lprefix = lprefix or "" -- toughen against nil values passed | lprefix = lprefix or "" -- toughen against nil values passed | ||
lpostfix = lpostfix or "" | lpostfix = lpostfix or "" | ||
Line 607: | Line 606: | ||
if sitelink then | if sitelink then | ||
if not (dtxt or shortname) then | if not (dtxt or shortname) then | ||
-- strip any namespace or dab from the sitelink | |||
local pos = sitelink:find(":") or 0 | |||
local slink = sitelink | |||
if pos > 0 then | |||
local prefix = sitelink:sub(1,pos-1) | |||
if mw.site.namespaces[prefix] then -- that prefix is a valid namespace, so remove it | |||
slink = sitelink:sub(pos+1) | |||
end | end | ||
end | |||
-- remove stuff after commas or inside parentheses - ie. dabs | |||
slink = slink:gsub("%s%(.+%)$", ""):gsub(",.+$", "") | |||
-- use that as label, preserving label case - find("^%u") is true for 1st char uppercase | |||
if label:find("^%u") then | |||
label = slink:gsub("^(%l)", string.upper) | |||
else | |||
label = slink:gsub("^(%u)", string.lower) | |||
end | end | ||
end | end | ||
Line 806: | Line 799: | ||
------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | ||
local createicon = function(langcode, entityID, propertyID) | local createicon = function(langcode, entityID, propertyID) | ||
local icon = " | local icon = " [[" | ||
-- " | -- "<span data-bridge-edit-flow='overwrite' class='penicon'> [[" -> enable Wikidata Bridge | ||
.. i18n["filespace"] | .. i18n["filespace"] | ||
.. ":OOjs UI icon edit-ltr-progressive.svg |frameless |text-top |10px |alt=" | .. ":OOjs UI icon edit-ltr-progressive.svg |frameless |text-top |10px |alt=" | ||
Line 814: | Line 807: | ||
.. "?uselang=" .. langcode | .. "?uselang=" .. langcode | ||
if propertyID then icon = icon .. "#" .. propertyID end | if propertyID then icon = icon .. "#" .. propertyID end | ||
icon = icon .. "|" .. i18n["editonwikidata"] .. "]] | icon = icon .. "|" .. i18n["editonwikidata"] .. "]]" | ||
return icon | return icon | ||
end | end | ||
Line 927: | Line 920: | ||
local shortname = args.shortname or args.sn | local shortname = args.shortname or args.sn | ||
shortname = parseParam(shortname, false) | shortname = parseParam(shortname, false) | ||
local snak = propval.mainsnak or propval | local snak = propval.mainsnak or propval | ||
local dtype = snak.datatype | local dtype = snak.datatype | ||
Line 948: | Line 939: | ||
local qnumber = dv.id | local qnumber = dv.id | ||
if linked then | if linked then | ||
val = linkedItem(qnumber, lpre, lpost, pre, post, dtxt, shortname, args.lang | val = linkedItem(qnumber, lpre, lpost, pre, post, dtxt, shortname, args.lang) | ||
else -- no link wanted so check for display-text, otherwise test for lang code | else -- no link wanted so check for display-text, otherwise test for lang code | ||
local label, islabel | local label, islabel | ||
Line 2,204: | Line 2,195: | ||
-- Dependencies: parseParam; setRanks; parseInput; sourced; propertyvalueandquals assembleoutput; | -- Dependencies: parseParam; setRanks; parseInput; sourced; propertyvalueandquals assembleoutput; | ||
------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | ||
p. | p.getPropOfProp = 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.langobj = findLang(args.lang) | |||
args.lang = args.langobj.code | |||
local pid1 = args.prop1 or args.pid1 or "" | local pid1 = args.prop1 or args.pid1 or "" | ||
local pid2 = args.prop2 or args.pid2 or "" | local pid2 = args.prop2 or args.pid2 or "" | ||
local localval = mw.text.trim(args[1] or "") | local localval = mw.text.trim(args[1] or "") | ||
if pid1 == "" or pid2 == "" then return nil end | if pid1 == "" or pid2 == "" then return nil end | ||
local qid1, statements1 = parseInput(frame, localval, pid1) | |||
local qid1, statements1 = parseInput( | |||
if not qid1 then return localval end | if not qid1 then return localval end | ||
local onlysrc = parseParam(args.onlysourced or args.osd, true) | local onlysrc = parseParam(args.onlysourced or args.osd, true) | ||
local maxvals = tonumber(args.maxvals) or 0 | local maxvals = tonumber(args.maxvals) or 0 | ||
Line 2,263: | Line 2,231: | ||
end -- of loop through values of property1 | end -- of loop through values of property1 | ||
return assembleoutput(out, args, qid1, pid1) | return assembleoutput(out, args, qid1, pid1) | ||
end | end | ||
Line 2,958: | Line 2,916: | ||
-- Dependencies: parseParam() | -- Dependencies: parseParam() | ||
------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | ||
p. | p.followQid = function(frame) | ||
local qid = (args.qid or ""):upper() | local qid = (frame.args.qid or ""):upper() | ||
local all = parseParam(args.all, false) | local all = parseParam(frame.args.all, false) | ||
if qid == "" then | if qid == "" then | ||
qid = mw.wikibase.getEntityIdForCurrentPage() | qid = mw.wikibase.getEntityIdForCurrentPage() | ||
Line 2,966: | Line 2,924: | ||
if not qid then return nil end | if not qid then return nil end | ||
local out = {} | local out = {} | ||
local props = (args.props or ""):upper() | local props = (frame.args.props or ""):upper() | ||
if props ~= "" then | if props ~= "" then | ||
for p in mw.text.gsplit(props, "%p") do -- split at punctuation and iterate | for p in mw.text.gsplit(props, "%p") do -- split at punctuation and iterate | ||
Line 2,987: | Line 2,945: | ||
return qid | return qid | ||
end | end | ||
end | end | ||
Line 3,156: | Line 3,110: | ||
-- but it keeps the "edit at Wikidata" pen icon out of the microformat. | -- but it keeps the "edit at Wikidata" pen icon out of the microformat. | ||
-- Usually it will take its url parameter directly from a Wikidata call: | -- Usually it will take its url parameter directly from a Wikidata call: | ||
-- e.g. {{#invoke:WikidataIB |url2 |url={{wdib |P856 |qid=Q23317 |fwd=ALL |osd=no | -- e.g. {{#invoke:WikidataIB |url2 |url={{wdib |P856 |qid=Q23317 |fwd=ALL |osd=no}} | ||
------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | ||
-- Dependencies: none | -- Dependencies: none | ||
Line 3,169: | Line 3,123: | ||
prot = prot or url | prot = prot or url | ||
addr = addr or "" | addr = addr or "" | ||
local disp, n = addr:gsub("%.", "<wbr/>%.") | |||
local disp, n = addr:gsub( | |||
return '<span class="url">[' .. prot .. addr .. " " .. disp .. "]</span> " .. icon | return '<span class="url">[' .. prot .. addr .. " " .. disp .. "]</span> " .. icon | ||
end | end |