Module:WikidataIB: Difference between revisions

m
1 revision imported
m (1 revision imported)
 
m (1 revision imported)
 
(One intermediate revision by one other user not shown)
Line 80: Line 80:
}
}
}
}
-- This allows a internationisation module to override the above table
-- This allows an internationisation module to override the above table
if 'en' ~= mw.getContentLanguage():getCode() then
if 'en' ~= mw.getContentLanguage():getCode() then
require("Module:i18n").loadI18n("Module:WikidataIB/i18n", i18n)
require("Module:i18n").loadI18n("Module:WikidataIB/i18n", i18n)
Line 95: Line 95:
if nolinks_exists then
if nolinks_exists then
donotlink = nolinks.itemsindex
donotlink = nolinks.itemsindex
end
-- To satisfy Wikipedia:Manual of Style/Titles, certain types of items are italicised, and others are quoted.
-- The submodule [[Module:WikidataIB/titleformats]] lists the entity-ids used in 'instance of' (P31),
-- which allows this module to identify the values that should be formatted.
-- WikidataIB/titleformats exports a table p.formats, which is indexed by entity-id, and contains the value " or ''
local formats = {}
local titleformats_exists, titleformats = pcall(mw.loadData, "Module:WikidataIB/titleformats")
if titleformats_exists then
formats = titleformats.formats
end
end


Line 103: Line 113:
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- makeOrdinal needs to be internationalised along with the above:
-- makeOrdinal needs to be internationalised along with the above:
-- takes cardinal numer as a numeric and returns the ordinal as a string
-- takes cardinal number as a numeric and returns the ordinal as a string
-- we need three exceptions in English for 1st, 2nd, 3rd, 21st, .. 31st, etc.
-- we need three exceptions in English for 1st, 2nd, 3rd, 21st, .. 31st, etc.
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
Line 318: Line 328:
-- dateFormat is the handler for properties that are of type "time"
-- dateFormat is the handler for properties that are of type "time"
-- It takes timestamp, precision (6 to 11 per mediawiki), dateformat (y/dmy/mdy), BC format (BC/BCE),
-- It takes timestamp, precision (6 to 11 per mediawiki), dateformat (y/dmy/mdy), BC format (BC/BCE),
-- a plaindate switch (yes/no/adj) to en/disable "sourcing cirumstances"/use adjectival form,
-- a plaindate switch (yes/no/adj) to en/disable "sourcing circumstances"/use adjectival form,
-- any qualifiers for the property, the language, and any adjective to use like 'before'.
-- any qualifiers for the property, the language, and any adjective to use like 'before'.
-- It passes the date through the "complex date" function
-- It passes the date through the "complex date" function
Line 326: Line 336:
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
local dateFormat = function(timestamp, dprec, df, bcf, pd, qualifiers, lang, adj, model)
local dateFormat = function(timestamp, dprec, df, bcf, pd, qualifiers, lang, adj, model)
-- output formatting according to preferences (y/dmy/mdy/ymd)
df = (df or ""):lower()
-- if ymd is required, return the part of the timestamp in YYYY-MM-DD form
-- but apply Year zero#Astronomers fix: 1 BC = 0000; 2 BC = -0001; etc.
if df == "ymd" then
if timestamp:sub(1,1) == "+" then
return timestamp:sub(2,11)
else
local yr = tonumber(timestamp:sub(2,5)) - 1
yr = ("000" .. yr):sub(-4)
if yr ~= "0000" then yr = "-" .. yr end
return yr .. timestamp:sub(6,11)
end
end
-- A year can be stored like this: "+1872-00-00T00:00:00Z",
-- A year can be stored like this: "+1872-00-00T00:00:00Z",
-- which is processed here as if it were the day before "+1872-01-01T00:00:00Z",
-- which is processed here as if it were the day before "+1872-01-01T00:00:00Z",
Line 331: Line 355:
-- So fix the month 0, day 0 timestamp to become 1 January instead:
-- So fix the month 0, day 0 timestamp to become 1 January instead:
timestamp = timestamp:gsub("%-00%-00T", "-01-01T")
timestamp = timestamp:gsub("%-00%-00T", "-01-01T")
-- output formatting according to preferences (y/dmy/mdy)
df = (df or ""):lower()
-- just in case date precision is missing
-- just in case date precision is missing
dprec = dprec or 11
dprec = dprec or 11
Line 373: Line 395:
-- no point in saying that dates before 1582 are Julian - they are by default
-- no point in saying that dates before 1582 are Julian - they are by default
-- doesn't make sense for dates less precise than year
-- doesn't make sense for dates less precise than year
-- we can supress it by setting |plaindate, e.g. for use in constructing categories.
-- we can suppress it by setting |plaindate, e.g. for use in constructing categories.
local calendarmodel = ""
local calendarmodel = ""
if tonumber(year) > 1582
if tonumber(year) > 1582
Line 389: Line 411:
-- it may also be returned wrapped in a microformat, so remove that
-- it may also be returned wrapped in a microformat, so remove that
fdate = fdate:gsub("<[^>]*>", "")
fdate = fdate:gsub("<[^>]*>", "")
-- there may be leading zeros that we should remove
fdate = fdate:gsub("^0*", "")
-- if a plain date is required, then remove any links (like BC linked)
if pd then
fdate = fdate:gsub("%[%[.*|", ""):gsub("]]", "")
end
-- if 'circa', use the abbreviated form *** internationalise later ***
-- if 'circa', use the abbreviated form *** internationalise later ***
fdate = fdate:gsub('circa ', '<abbr title="circa">c.</abbr>&nbsp;')
fdate = fdate:gsub('circa ', '<abbr title="circa">c.</abbr>&nbsp;')
Line 412: Line 440:
-- it makes the empty string and nil into the (boolean) value passed as default
-- it makes the empty string and nil into the (boolean) value passed as default
-- allowing the parameter to be true or false by default.
-- allowing the parameter to be true or false by default.
-- It returns a boolean.
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Dependencies: none
-- Dependencies: none
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
local parseParam = function(param, default)
local parseParam = function(param, default)
if type(param) == "boolean" then param = tostring(param) end
if param and param ~= "" then
if param and param ~= "" then
param = param:lower()
param = param:lower()
Line 445: Line 475:
local sitelink
local sitelink
if wiki == "" then
if wiki == "" then
sitelink = mw.wikibase.sitelink(qid)
sitelink = mw.wikibase.getSitelink(qid)
else
else
sitelink = mw.wikibase.sitelink(qid, wiki)
sitelink = mw.wikibase.getSitelink(qid, wiki)
end
end
return sitelink
return sitelink
Line 474: Line 504:
local prop910 = mw.wikibase.getBestStatements(qid, "P910")[1]
local prop910 = mw.wikibase.getBestStatements(qid, "P910")[1]
if prop910 then
if prop910 then
local tmcid = prop910.mainsnak.datavalue.value.id
local tmcid = prop910.mainsnak.datavalue and prop910.mainsnak.datavalue.value.id
sitelink = _getSitelink(tmcid, "commonswiki")
sitelink = _getSitelink(tmcid, "commonswiki")
end
if not sitelink then
-- check for list's main category
local prop1754 = mw.wikibase.getBestStatements(qid, "P1754")[1]
if prop1754 then
local tmcid = prop1754.mainsnak.datavalue and prop1754.mainsnak.datavalue.value.id
sitelink = _getSitelink(tmcid, "commonswiki")
end
end
end
end
end
Line 482: Line 520:
local prop373 = mw.wikibase.getBestStatements(qid, "P373")[1]
local prop373 = mw.wikibase.getBestStatements(qid, "P373")[1]
if prop373 then
if prop373 then
sitelink = prop373.mainsnak.datavalue.value
sitelink = prop373.mainsnak.datavalue and prop373.mainsnak.datavalue.value
if sitelink then sitelink = "Category:" .. sitelink end
if sitelink then sitelink = "Category:" .. sitelink end
end
end
Line 499: Line 537:
-- Dependencies: none
-- Dependencies: none
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
local labelOrId = function(id)
local labelOrId = function(id, lang)
local label = mw.wikibase.label(id)
if lang == "default" then lang = findLang().code end
local label
if lang then
label = mw.wikibase.getLabelByLang(id, lang)
else
label = mw.wikibase.getLabel(id)
end
if label then
if label then
return mw.text.nowiki(label), true
return mw.text.nowiki(label), true
Line 529: Line 573:
postfix = postfix or ""
postfix = postfix or ""
lang = lang or "en" -- fallback to default if missing
lang = lang or "en" -- fallback to default if missing
-- see if item might need italics or quotes
local fmt = ""
for k, v in ipairs( mw.wikibase.getBestStatements(id, "P31") ) do
if v.mainsnak.datavalue and formats[v.mainsnak.datavalue.value.id] then
fmt = formats[v.mainsnak.datavalue.value.id]
break -- pick the first match
end
end
local disp
local disp
local sitelink = mw.wikibase.sitelink(id)
local sitelink = mw.wikibase.getSitelink(id)
local label, islabel
local label, islabel
if dtxt then
if dtxt then
Line 553: Line 605:
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 and use that as label
-- strip any namespace or dab from the sitelink
local pos = sitelink:find(":") or 0
local pos = sitelink:find(":") or 0
label = sitelink:sub(pos+1):gsub("%s%(.+%)$", ""):gsub(",.+$", "")
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
-- 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
if donotlink[label] then
if donotlink[label] then
disp = prefix .. label .. postfix
disp = prefix .. fmt .. label .. fmt .. postfix
else
else
disp = "[[" .. lprefix .. sitelink .. lpostfix .. "|" .. prefix .. label .. postfix .. "]]"
disp = "[[" .. lprefix .. sitelink .. lpostfix .. "|" .. prefix .. fmt .. label .. fmt .. postfix .. "]]"
end
end
elseif islabel then
elseif islabel then
-- no sitelink, label exists, so check if a redirect with that title exists
-- no sitelink, label exists, so check if a redirect with that title exists
local artitle = mw.title.new(label, 0)
local artitle = mw.title.new(label, 0) -- only nil if label has invalid chars
if artitle and artitle.redirectTarget and not donotlink[label] then
if not donotlink[label] and artitle and artitle.redirectTarget then
-- there's a redirect with the same title as the label, so let's link to that
-- there's a redirect with the same title as the label, so let's link to that
disp = "[[".. lprefix .. label .. lpostfix .. "|" .. prefix .. label .. postfix .. "]]"
disp = "[[".. lprefix .. label .. lpostfix .. "|" .. prefix .. fmt .. label .. fmt .. postfix .. "]]"
else
else
-- no sitelink, label exists, not redirect (or donotlink) so output plain label
-- either (donotlink is true) or (no sitelink, label exists, not redirect)
disp = prefix .. label .. postfix
-- so output unlinked label with italics or quotes as needed
disp = prefix .. fmt .. label .. fmt .. postfix
end -- test if article title exists as redirect on current Wiki
end -- test if article title exists as redirect on current Wiki
else
else
-- no sitelink and no label, so return whatever was returned from labelOrId for now
-- no sitelink and no label, so return whatever was returned from labelOrId for now
-- add tracking category [[Category:Articles with missing Wikidata information]]
-- add tracking category [[Category:Articles with missing Wikidata information]]
disp = prefix .. label .. postfix .. i18n.missinginfocat
-- for enwiki, just return the tracking category
if mw.wikibase.getGlobalSiteId() == "enwiki" then
disp = i18n.missinginfocat
else
disp = prefix .. label .. postfix .. i18n.missinginfocat
end
end
end
else
else
Line 596: Line 668:
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- sourced takes a table representing a statement that may or may not have references
-- sourced takes a table representing a statement that may or may not have references
-- it counts how many references are sourced to something not containing the word "wikipedia"
-- it looks for a reference sourced to something not containing the word "wikipedia"
-- it returns a boolean = true if there are any sourced references.
-- it returns a boolean = true if it finds a sourced reference.
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Dependencies: none
-- Dependencies: none
Line 605: Line 677:
for kr, vr in pairs(claim.references) do
for kr, vr in pairs(claim.references) do
local ref = mw.wikibase.renderSnaks(vr.snaks)
local ref = mw.wikibase.renderSnaks(vr.snaks)
if not ref:find("Wikipedia") then
if not ref:find("Wiki") then
return true
return true
end
end
Line 657: Line 729:
input_parm = mw.text.trim(input_parm or "")
input_parm = mw.text.trim(input_parm or "")
if input_parm == "" then input_parm = nil end
if input_parm == "" then input_parm = nil end
-- return nil if Wikidata is not available
if not mw.wikibase then return false, input_parm end


local args = frame.args
local args = frame.args
Line 668: Line 743:


-- The blacklist is passed in named parameter |suppressfields
-- The blacklist is passed in named parameter |suppressfields
local blacklist = args.suppressfields or args.spf
local blacklist = args.suppressfields or args.spf or ""


-- The whitelist is passed in named parameter |fetchwikidata
-- The whitelist is passed in named parameter |fetchwikidata
local whitelist = args.fetchwikidata or args.fwd
local whitelist = args.fetchwikidata or args.fwd or ""
if not whitelist or whitelist == "" then whitelist = "NONE" end
if whitelist == "" then whitelist = "NONE" end


-- The name of the field that this function is called from is passed in named parameter |name
-- The name of the field that this function is called from is passed in named parameter |name
local fieldname = args.name or ""
local fieldname = args.name or ""


if blacklist then
if blacklist ~= "" then
-- The name is compulsory when blacklist is used, so return nil if it is not supplied
-- The name is compulsory when blacklist is used, so return nil if it is not supplied
if not fieldname or fieldname == "" then return false, nil end
if fieldname == "" then return false, nil end
-- If this field is on the blacklist, then return nil
-- If this field is on the blacklist, then return nil
if blacklist:find(fieldname) then return false, nil end
if blacklist:find(fieldname) then return false, nil end
Line 718: Line 793:
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- createicon assembles the "Edit at Wikidata" pen icon.
-- createicon assembles the "Edit at Wikidata" pen icon.
-- It returns a wikitext string.
-- It returns a wikitext string inside a span class="penicon"
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Dependencies: i18n[];
-- Dependencies: i18n[];
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
local createicon = function(langcode, entityID, propertyID)
local createicon = function(langcode, entityID, propertyID)
local icon = "&nbsp;[[" .. i18n["filespace"]
local icon = "&nbsp;<span class='penicon'>[["
icon = icon .. ":Blue pencil.svg |frameless |text-top |10px |alt="
-- "&nbsp;<span data-bridge-edit-flow='overwrite' class='penicon'>[[" -> enable Wikidata Bridge
icon = icon .. i18n["editonwikidata"]
.. i18n["filespace"]
icon = icon .. "|link=https://www.wikidata.org/wiki/" .. entityID
.. ":OOjs UI icon edit-ltr-progressive.svg |frameless |text-top |10px |alt="
icon = icon .. "?uselang=" .. langcode
.. i18n["editonwikidata"]
.. "|link=https://www.wikidata.org/wiki/" .. entityID
.. "?uselang=" .. langcode
if propertyID then icon = icon .. "#" .. propertyID end
if propertyID then icon = icon .. "#" .. propertyID end
icon = icon .. "|" .. i18n["editonwikidata"] .. "]]"
icon = icon .. "|" .. i18n["editonwikidata"] .. "]]</span>"
return icon
return icon
end
end
Line 774: Line 851:
-- Zero or not a number result in no collapsing (default becomes 0).
-- Zero or not a number result in no collapsing (default becomes 0).
local collapse = tonumber(args.collapse) or 0
local collapse = tonumber(args.collapse) or 0
-- replacetext (rt) is a string that is returned instead of any non-empty Wikidata value
-- this is useful for tracking and debugging
local replacetext = mw.text.trim(args.rt or args.replacetext or "")


-- if there's anything to return, then return a list
-- if there's anything to return, then return a list
Line 781: Line 862:
if #out > 0 then
if #out > 0 then
if sorted then table.sort(out) end
if sorted then table.sort(out) end
-- if a pen icon is wanted add it the end of the last value
-- if there's something to display and a pen icon is wanted, add it the end of the last value
if not noic then
local hasdisplay = false
for i, v in ipairs(out) do
if v ~= i18n.missinginfocat then
hasdisplay = true
break
end
end
if not noic and hasdisplay then
out[#out] = out[#out] .. createicon(args.langobj.code, entityID, propertyID)
out[#out] = out[#out] .. createicon(args.langobj.code, entityID, propertyID)
end
end
Line 798: Line 886:
strout = nil -- no items had valid reference
strout = nil -- no items had valid reference
end
end
if replacetext ~= "" and strout then strout = replacetext end
return strout
return strout
end
end
Line 873: Line 962:
-- qualifiers (if any) is a nested table or nil
-- qualifiers (if any) is a nested table or nil
-- lang is given, or user language, or site language
-- lang is given, or user language, or site language
--
-- Here we can check whether args.df has a value
-- If not, use code from Module:Sandbox/RexxS/Getdateformat to set it from templates like {{Use mdy dates}}
val = dateFormat(dv.time, dv.precision, args.df, args.bc, args.pd, propval.qualifiers, args.lang, "", dv.calendarmodel)
val = dateFormat(dv.time, dv.precision, args.df, args.bc, args.pd, propval.qualifiers, args.lang, "", dv.calendarmodel)
------------------------------------
------------------------------------
Line 882: Line 974:
-- don't link if no linkpre/postfix or linkprefix is just ":"
-- don't link if no linkpre/postfix or linkprefix is just ":"
val = pre .. dv .. post
val = pre .. dv .. post
elseif dtype == "external-id" then
val = "[" .. lpre .. dv .. lpost .. " " .. pre .. dv .. post .. "]"
else
else
val = "[[" .. lpre .. dv .. lpost .. "|" .. pre .. dv .. post .. "]]"
val = "[[" .. lpre .. dv .. lpost .. "|" .. pre .. dv .. post .. "]]"
Line 898: Line 992:
-- if we have conversions, we won't have formatted numbers or scales
-- if we have conversions, we won't have formatted numbers or scales
if conv then
if conv then
uabbr = true
fnum = false
fnum = false
args.scale = "0"
args.scale = "0"
Line 983: Line 1,078:
if uabbr then
if uabbr then
-- see if there's a unit symbol (P5061)
-- see if there's a unit symbol (P5061)
local unitsymbols = mw.wikibase.getAllStatements(unitqid, "P5061")
local unitsymbols = mw.wikibase.getBestStatements(unitqid, "P5061")
-- construct fallback table
-- construct fallback table, add local lang and multiple languages
local fbtbl = mw.language.getFallbacksFor( args.lang )
local fbtbl = mw.language.getFallbacksFor( args.lang )
table.insert( fbtbl, 1, args.lang )
table.insert( fbtbl, 1, args.lang )
table.insert( fbtbl, 1, "mul" )
local found = false
local found = false
for idx1, us in ipairs(unitsymbols) do
for idx1, us in ipairs(unitsymbols) do
Line 1,002: Line 1,098:
end
end
-- format display:
-- format display:
if conv and usym ~= "" then
if conv then
if range == "" then
if range == "" then
val = mw.getCurrentFrame():expandTemplate{title = "cvt", args = {amount, usym}}
val = mw.getCurrentFrame():expandTemplate{title = "cvt", args = {amount, unit}}
else
else
val = mw.getCurrentFrame():expandTemplate{title = "cvt", args = {lowb, "to", upb, usym}}
val = mw.getCurrentFrame():expandTemplate{title = "cvt", args = {lowb, "to", upb, unit}}
end
end
elseif unit == "$" or unit == "£" then
elseif unit == "$" or unit == "£" then
Line 1,023: Line 1,119:
-- default is deg/min/sec -- decimal degrees needs |format = dec
-- default is deg/min/sec -- decimal degrees needs |format = dec
local form = (args.format or ""):lower():sub(1,3)
local form = (args.format or ""):lower():sub(1,3)
if form ~= "dec" then form = "dms" end
if form ~= "dec" then form = "dms" end -- not needed for now
--
--
-- show parameter allows just the latitude or longitude to be shown
-- show parameter allows just the latitude, or just the longitude, or both
-- to be returned as a signed decimal, ignoring the format parameter.
local show = (args.show or ""):lower()
local show = (args.show or ""):lower()
if show ~= "longlat" then show = show:sub(1,3) end
if show ~= "longlat" then show = show:sub(1,3) end
Line 1,148: Line 1,245:
local pd = args.plaindate or args.pd or "no"
local pd = args.plaindate or args.pd or "no"
args.pd = pd
args.pd = pd
-- allow qualifiers to have a different date format; default to year
args.qdf = args.qdf or args.qualifierdateformat or args.df or "y"


local lang = args.lang or findlang().code
local lang = args.lang or findlang().code
    -- qualID is a string list of wanted qualifiers or "ALL"
    qualID = qualID or ""
    -- capitalise list of wanted qualifiers and substitute "DATES"
    qualID = qualID:upper():gsub("DATES", "P580, P582")
    local allflag = (qualID == "ALL")
    -- create table of wanted qualifiers as key
    local qwanted = {}
    -- create sequence of wanted qualifiers
    local qorder = {}
    for q in mw.text.gsplit(qualID, "%p") do -- split at punctuation and iterate
        local qtrim = mw.text.trim(q)
        if qtrim ~= "" then
            qwanted[mw.text.trim(q)] = true
            qorder[#qorder+1] = qtrim
        end
    end
    -- qsep is the output separator for rendering qualifier list
    local qsep = (args.qsep or ""):gsub('"', '')
    -- qargs are the arguments to supply to assembleoutput()
    local qargs = {
        ["osd"]        = "false",
        ["linked"]      = tostring(linked),
        ["prefix"]      = args.qprefix,
        ["postfix"]    = args.qpostfix,
        ["linkprefix"]  = args.qlinkprefix or args.qlp,
        ["linkpostfix"] = args.qlinkpostfix,
        ["wdl"]        = "false",
        ["unitabbr"]    = tostring(uabbr),
        ["maxvals"]    = 0,
        ["sorted"]      = tostring(args.qsorted),
        ["noicon"]      = "true",
        ["list"]        = args.qlist,
        ["sep"]        = qsep,
        ["langobj"]    = args.langobj,
        ["lang"]        = args.langobj.code,
        ["df"]          = args.qdf,
        ["sn"]          = parseParam(args.qsn or args.qshortname, false),
    }
-- all proper values of a Wikidata property will be the same type as the first
-- all proper values of a Wikidata property will be the same type as the first
-- qualifiers don't have a mainsnak, properties do
-- qualifiers don't have a mainsnak, properties do
local datatype = objproperty[1].datatype or objproperty[1].mainsnak.datatype
local datatype = objproperty[1].datatype or objproperty[1].mainsnak.datatype
-- out[] holds the values for this property
 
-- out[] holds the a list of returned values for this property
-- mlt[] holds the language code if the datatype is monolingual text
-- mlt[] holds the language code if the datatype is monolingual text
local out = {}
local out = {}
local mlt = {}
local mlt = {}
for k, v in ipairs(objproperty) do
for k, v in ipairs(objproperty) do
local hasvalue = true
local hasvalue = true
Line 1,175: Line 1,317:
-- See if qualifiers are to be returned:
-- See if qualifiers are to be returned:
local snak = v.mainsnak or v
local snak = v.mainsnak or v
if hasvalue and v.qualifiers and qualID and snak.snaktype=="value" then
if hasvalue and v.qualifiers and qualID ~= "" and snak.snaktype~="novalue" then
local qsep = (args.qsep or ""):gsub('"', '')
            -- collect all wanted qualifier values returned in qlist, indexed by propertyID
local qargs = {
["osd"]        = "false",
["linked"]      = tostring(linked),
["prefix"]      = args.qprefix,
["postfix"]    = args.qpostfix,
["linkprefix"]  = args.qlinkprefix or args.qlp,
["linkpostfix"] = args.qlinkpostfix,
["wdl"]        = "false",
["unitabbr"]    = tostring(uabbr),
["maxvals"]    = 0,
["sorted"]      = args.qsorted,
["noicon"]      = "true",
["list"]        = args.qlist,
["sep"]        = qsep,
["langobj"]    = args.langobj,
["lang"]        = args.langobj.code,
}
local qlist = {}
local qlist = {}
local t1, t2 = "", ""
local timestart, timeend = "", ""
-- see if we want all qualifiers
            -- loop through qualifiers
if qualID == "ALL" then
            for k1, v1 in pairs(v.qualifiers) do
if v["qualifiers-order"] then
                if allflag or qwanted[k1] then
-- the values in the order table are the keys for the qualifiers table:
                    if k1 == "P1326" then
for k1, v1 in ipairs(v["qualifiers-order"]) do
                        local ts = v1[1].datavalue.value.time
if v1 == "P1326" then
                        local dp = v1[1].datavalue.value.precision
local ts = v.qualifiers[v1][1].datavalue.value.time
                        qlist[k1] = dateFormat(ts, dp, args.qdf, args.bc, pd, "", lang, "before")
local dp = v.qualifiers[v1][1].datavalue.value.precision
                    elseif k1 == "P1319" then
qlist[#qlist + 1] = dateFormat(ts, dp, args.df, args.bc, pd, "", lang, "before")
                        local ts = v1[1].datavalue.value.time
elseif v1 == "P1319" then
                        local dp = v1[1].datavalue.value.precision
local ts = v.qualifiers[v1][1].datavalue.value.time
                        qlist[k1] = dateFormat(ts, dp, args.qdf, args.bc, pd, "", lang, "after")
local dp = v.qualifiers[v1][1].datavalue.value.precision
                    elseif k1 == "P580" then
qlist[#qlist + 1] = dateFormat(ts, dp, args.df, args.bc, pd, "", lang, "after")
                        timestart = propertyvalueandquals(v1, qargs)[1] or "" -- treat only one start time as valid
else
                    elseif k1 == "P582" then
local q = assembleoutput(propertyvalueandquals(v.qualifiers[v1], qargs), qargs)
                        timeend = propertyvalueandquals(v1, qargs)[1] or "" -- treat only one end time as valid
-- we already deal with circa via 'sourcing circumstances'
                    else
-- either linked or unlinked *** internationalise later ***
                        local q = assembleoutput(propertyvalueandquals(v1, qargs), qargs)
if q ~= "circa" and not q:find("circa]]") then
                        -- we already deal with circa via 'sourcing circumstances' if the datatype was time
qlist[#qlist + 1] = q
                        -- circa may be either linked or unlinked *** internationalise later ***
end
                        if datatype ~= "time" or q ~= "circa" and not (type(q) == "string" and q:find("circa]]")) then
end
                            qlist[k1] = q
end
                        end
else
                    end
-- are there cases where qualifiers-order doesn't exist?
                end -- of test for wanted
local ql = propertyvalueandquals(v.qualifiers, qargs)
            end -- of loop through qualifiers
for k1, v1 in ipairs(ql) do
            -- set date separator
-- we already deal with circa via 'sourcing circumstances'
local t = timestart .. timeend
-- either linked or unlinked *** internationalise later ***
if v1 ~= "circa" and not v1:find("circa]]") then
qlist[#qlist + 1] = v1
end
end
end
-- see if we want date/range
elseif qualID == "DATES" then
qargs.maxvals = 1
for k1, v1 in pairs(v.qualifiers) do
if k1 == "P580" then -- P580 is "start time"
t1 = propertyvalueandquals(v1, qargs)[1] or ""
elseif k1 == "P582" then -- P582 is "end time"
t2 = propertyvalueandquals(v1, qargs)[1] or ""
end
end
-- otherwise process qualID as a list of qualifiers
else
for q in mw.text.gsplit(qualID, "%p") do -- split at punctuation and iterate
q = mw.text.trim(q):upper() -- remove whitespace and capitalise
if q == "P1326" then
-- latest date, so supply 'before' as well. Assume one date value.
for k1, v1 in pairs(v.qualifiers) do
if k1 == "P1326" then
local ts = v1[1].datavalue.value.time
local dp = v1[1].datavalue.value.precision
qlist[#qlist + 1] = dateFormat(ts, dp, args.df, args.bc, pd, "", lang, "before")
end
end
else
for k1, v1 in pairs(v.qualifiers) do
if k1 == q then
local ql = propertyvalueandquals(v1, qargs)
for k2, v2 in ipairs(ql) do
qlist[#qlist + 1] = v2
end
end
end
end
end -- of loop through list of qualifiers in qualID
end -- of testing for what qualID is
local t = t1 .. t2
-- *** internationalise date separators later ***
-- *** internationalise date separators later ***
local dsep = "&ndash;"
local dsep = "&ndash;"
if t:find("%s") or t:find("&nbsp;") then dsep = " &ndash; " end
if t:find("%s") or t:find("&nbsp;") then dsep = " &ndash; " end
if #qlist > 0 then
            -- set the order for the list of qualifiers returned; start time and end time go last
local qstr = assembleoutput(qlist, qargs)
if next(qlist) then
                local qlistout = {}
                if allflag then
                    for k2, v2 in pairs(qlist) do
                        qlistout[#qlistout+1] = v2
                    end
                else
                    for i2, v2 in ipairs(qorder) do
                        qlistout[#qlistout+1] = qlist[v2]
                    end
                end
                if t ~= "" then
                    qlistout[#qlistout+1] = timestart .. dsep .. timeend
                end
local qstr = assembleoutput(qlistout, qargs)
if qualsonly then
if qualsonly then
out[#out+1] = qstr
out[#out+1] = qstr
Line 1,275: Line 1,372:
out[#out] = out[#out] .. " (" .. qstr .. ")"
out[#out] = out[#out] .. " (" .. qstr .. ")"
end
end
elseif t > "" then
elseif t ~= "" then
if qualsonly then
if qualsonly then
out[#out+1] = t1 .. dsep .. t2
out[#out+1] = timestart .. dsep .. timeend
else
else
out[#out] = out[#out] .. " (" .. t1 .. dsep .. t2 .. ")"
out[#out] = out[#out] .. " (" .. timestart .. dsep .. timeend .. ")"
end
end
end
end
Line 1,373: Line 1,470:
-- if we've got this far, we have a (sourced) claim with qualifiers
-- if we've got this far, we have a (sourced) claim with qualifiers
-- so see if matches the required value
-- so see if matches the required value
-- We'll only deal with wikibase-items for now
-- We'll only deal with wikibase-items and strings for now
if v1q[qualID][1].datatype == "wikibase-item" then
if v1q[qualID][1].datatype == "wikibase-item" then
if checkvalue(v1q[qualID][1].datavalue.value.id) then
if checkvalue(v1q[qualID][1].datavalue.value.id) then
out[#out + 1] = rendersnak(v1, args, linked, lpre, lpost, pre, post, uabbr, filter)
end
elseif v1q[qualID][1].datatype == "string" then
if checkvalue(v1q[qualID][1].datavalue.value) then
out[#out + 1] = rendersnak(v1, args, linked, lpre, lpost, pre, post, uabbr, filter)
out[#out + 1] = rendersnak(v1, args, linked, lpre, lpost, pre, post, uabbr, filter)
end
end
Line 1,411: Line 1,512:
local finished = false
local finished = false
local count = 0
local count = 0
local prevqid = ""
local prevqid = "Q0"
repeat
repeat
local prop
local prop
Line 1,417: Line 1,518:
local proptbl = mw.wikibase.getBestStatements(qid, v1)
local proptbl = mw.wikibase.getBestStatements(qid, v1)
if #proptbl > 1 then
if #proptbl > 1 then
-- there is more than one parent location
-- there is more than one higher location
local prevP131, prevP131id
if prevqid ~= "Q0" then
prevP131 = mw.wikibase.getBestStatements(prevqid, "P131")[1]
prevP131id = prevP131
and prevP131.mainsnak.datavalue
and prevP131.mainsnak.datavalue.value.id
end
for i2, v2 in ipairs(proptbl) do
for i2, v2 in ipairs(proptbl) do
parttbl = v2.qualifiers and v2.qualifiers.P518
parttbl = v2.qualifiers and v2.qualifiers.P518
if parttbl then
if parttbl then
-- this parent location has qualifier 'applies to part' (P518)
-- this higher location has qualifier 'applies to part' (P518)
for i3, v3 in ipairs(parttbl) do
for i3, v3 in ipairs(parttbl) do
if v3.snaktype == "value" and v3.datavalue.value.id == prevqid then
if v3.snaktype == "value" and v3.datavalue.value.id == prevqid then
Line 1,429: Line 1,537:
end -- of test for matching last location
end -- of test for matching last location
end -- of loop through values of 'applies to part'
end -- of loop through values of 'applies to part'
else
-- there's no qualifier 'applies to part' (P518)
-- so check if the previous location had a P131 that matches this alternate
if qid == prevP131id then
prop = proptbl[i2]
break
end -- of test for matching previous P131
end
end
end -- of loop through parent locations
end -- of loop through parent locations
Line 1,497: Line 1,612:
until finished or count >= 10 -- limit to 10 levels to avoid infinite loops
until finished or count >= 10 -- limit to 10 levels to avoid infinite loops


-- remove the first location if not quired
-- remove the first location if not required
if not first then table.remove(out, 1) end
if not first then table.remove(out, 1) end


Line 1,576: Line 1,691:
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- getValue is used to get the value(s) of a property
-- _getValue makes the functionality of getValue available to other modules
-- The property ID is passed as the first unnamed parameter and is required.
-- A locally supplied parameter may optionaly be supplied as the second unnamed parameter.
-- The function will now also return qualifiers if parameter qual is supplied
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Dependencies: setRanks; parseInput; propertyvalueandquals; assembleoutput; parseParam; sourced;
-- Dependencies: setRanks; parseInput; propertyvalueandquals; assembleoutput; parseParam; sourced;
-- labelOrId; i18n.latestdatequalifier; format_Date; makeOrdinal; roundto; decimalPrecision; decimalToDMS;
-- labelOrId; i18n.latestdatequalifier; format_Date; makeOrdinal; roundto; decimalPrecision; decimalToDMS;
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
p.getValue = function(frame)
p._getValue = function(args)
if not frame.args[1] then
frame.args = frame:getParent().args
if not frame.args[1] then return i18n.errors["No property supplied"] end
end
 
-- parameter sets for commonly used groups of parameters
-- parameter sets for commonly used groups of parameters
local paraset = tonumber(frame.args.ps or frame.args.parameterset or 0)
local paraset = tonumber(args.ps or args.parameterset or 0)
if paraset == 1 then
if paraset == 1 then
frame.args.rank = "best"
-- a common setting
frame.args.fetchwikidata = "ALL"
args.rank = "best"
frame.args.onlysourced = "no"
args.fetchwikidata = "ALL"
frame.args.noicon = "true"
args.onlysourced = "no"
args.noicon = "true"
elseif paraset == 2 then
elseif paraset == 2 then
-- second set goes here
-- equivalent to raw
args.rank = "best"
args.fetchwikidata = "ALL"
args.onlysourced = "no"
args.noicon = "true"
args.linked = "no"
args.pd = "true"
elseif paraset == 3 then
-- third set goes here
end
end


local propertyID = mw.text.trim(frame.args[1] or "")
-- implement eid parameter
local eid = args.eid
if eid == "" then
return nil
elseif eid then
args.qid = eid
end


frame.args.reqranks = setRanks(frame.args.rank)
local propertyID = mw.text.trim(args[1] or "")


local entityid, props = parseInput(frame, frame.args[2], propertyID)
args.reqranks = setRanks(args.rank)
 
-- replacetext (rt) is a string that is returned instead of any non-empty Wikidata value
-- this is useful for tracking and debugging, so we set fetchwikidata=ALL to fill the whitelist
local replacetext = mw.text.trim(args.rt or args.replacetext or "")
if replacetext ~= "" then
args.fetchwikidata = "ALL"
end
 
local f = {}
f.args = args
local entityid, props = parseInput(f, f.args[2], propertyID)


if not entityid then
if not entityid then
return props -- either the input parameter or nothing
return props -- either the input parameter or nothing
end
end
-- qual is a string containing the property ID of the qualifier(s) to be returned
-- qual is a string containing the property ID of the qualifier(s) to be returned
-- if qual == "ALL" then all qualifiers returned
-- if qual == "ALL" then all qualifiers returned
-- if qual == "DATES" then qualifiers P580 (start time) and P582 (end time) returned
-- if qual == "DATES" then qualifiers P580 (start time) and P582 (end time) returned
-- if nothing or an empty string is passed set it nil -> no qualifiers returned
-- if nothing or an empty string is passed set it nil -> no qualifiers returned
local qualID = mw.text.trim(frame.args.qual or ""):upper()
local qualID = mw.text.trim(args.qual or ""):upper()
if qualID == "" then qualID = nil end
if qualID == "" then qualID = nil end


-- set a language object and code in the frame.args table
-- set a language object and code in the args table
frame.args.langobj = findLang(frame.args.lang)
args.langobj = findLang(args.lang)
frame.args.lang = frame.args.langobj.code
args.lang = args.langobj.code


-- table 'out' stores the return value(s):
-- table 'out' stores the return value(s):
local out = propertyvalueandquals(props, frame.args, qualID)
local out = propertyvalueandquals(props, args, qualID)


-- format the table of values and return it as a string:
-- format the table of values and return it as a string:
return assembleoutput(out, frame.args, entityid, propertyID)
return assembleoutput(out, args, entityid, propertyID)
end
 
 
-------------------------------------------------------------------------------
-- getValue is used to get the value(s) of a property
-- The property ID is passed as the first unnamed parameter and is required.
-- A locally supplied parameter may optionaly be supplied as the second unnamed parameter.
-- The function will now also return qualifiers if parameter qual is supplied
-------------------------------------------------------------------------------
-- Dependencies: _getValue; setRanks; parseInput; propertyvalueandquals; assembleoutput; parseParam; sourced;
-- labelOrId; i18n.latestdatequalifier; format_Date; makeOrdinal; roundto; decimalPrecision; decimalToDMS;
-------------------------------------------------------------------------------
p.getValue = function(frame)
local args= frame.args
if not args[1] then
args = frame:getParent().args
if not args[1] then return i18n.errors["No property supplied"] end
end
 
return p._getValue(args)
end
end


Line 1,791: Line 1,945:
-- a property ID (the unnamed parameter or 1=Pxxx)
-- a property ID (the unnamed parameter or 1=Pxxx)
-- the ID of a qualifier for that property (qualID=Pyyy)
-- the ID of a qualifier for that property (qualID=Pyyy)
-- the Wikibase-entity ID of a value for that qualifier (qvalue=Qzzz)
-- either the Wikibase-entity ID of a value for that qualifier (qvalue=Qzzz)
-- or a string value for that qualifier (qvalue=abc123)
-- The usual whitelisting, blacklisting, onlysourced, etc. are implemented
-- The usual whitelisting, blacklisting, onlysourced, etc. are implemented
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
Line 1,821: Line 1,976:
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
p.getValueByLang = function(frame)
p.getValueByLang = function(frame)
-- The language code for the qualifier we want to match is in named parameter |lang=
-- The language code for the qualifier we want to match is in named parameter |lang=
local langcode = frame.args.lang or ""
local langcode = findLang(frame.args.lang).code
if langcode == "" then
langcode = frame:callParserFunction{ name = "int", args = "lang" }
end
local function checkLanguage(id)
local function checkLanguage(id)
-- id should represent a language like "British English (Q7979)"
-- id should represent a language like "British English (Q7979)"
Line 1,842: Line 1,993:
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- getValueByRefSource gets the value of a property which has a reference "stated in" (P248)
-- getValueByRefSource gets the value of a property which has a reference "stated in" (P248)
-- whose value has the given entity code.
-- whose value has the given entity-ID.
-- The call needs:
-- The call needs:
-- a property ID (the unnamed parameter or 1=Pxxx)
-- a property ID (the unnamed parameter or 1=Pxxx)
Line 1,933: Line 2,084:




-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- getPropOfProp takes two propertyIDs: prop1 and prop2 (as well as the usual parameters)
-- getPropertyIDs takes most of the usual parameters.
-- If the value(s) of prop1 are of type "wikibase-item" then it returns the value(s) of prop2
-- The usual whitelisting, blacklisting, onlysourced, etc. are implemented.
-- of each of those wikibase-items.
-- It returns the Entity-IDs (Qids) of the values of a property if it is a Wikibase-Entity.
-- The usual whitelisting, blacklisting, onlysourced, etc. are implemented
-- Otherwise it returns nothing.
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Dependencies: parseParam; setRanks; parseInput; sourced; propertyvalueandquals assembleoutput;
-- Dependencies: parseParam; setRanks; parseInput; sourced; propertyvalueandquals assembleoutput;
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
p.getPropOfProp = function(frame)
p.getPropertyIDs = 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
local args = frame.args
local pid1 = args.prop1 or args.pid1 or ""
args.reqranks = setRanks(args.rank)
local pid2 = args.prop2 or args.pid2 or ""
args.langobj = findLang(args.lang)
local localval = mw.text.trim(args[1] or "")
args.lang = args.langobj.code
if pid1 == "" or pid2 == "" then return nil end
-- change default for noicon to true
local qid1, statements1 = parseInput(frame, localval, pid1)
args.noicon = tostring(parseParam(args.noicon or "", true))
if not qid1 then return localval end
local f = {}
f.args = args
local pid = mw.text.trim(args[1] or ""):upper()
 
-- get the qid and table of claims for the property, or nothing and the local value passed
local qid, props = parseInput(f, args[2], pid)
if not qid then return props end
if not props[1] then return nil 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
local qualID = mw.text.trim(args.qual or ""):upper()
 
if qualID == "" then qualID = nil end
out = {}
local out = {}
for i, v in ipairs(props) do
for k, v in ipairs(statements1) do
local snak = v.mainsnak
if not onlysrc or sourced(v) then
if ( snak.datatype == "wikibase-item" )
local snak = v.mainsnak
and ( v.rank and args.reqranks[v.rank:sub(1, 1)] )
if snak.datatype == "wikibase-item" and snak.snaktype == "value" then
and ( snak.snaktype == "value" )
local qid2 = snak.datavalue.value.id
and ( sourced(v) or not onlysrc )
local statements2 = {}
then
if args.reqranks.b then
out[#out+1] = snak.datavalue.value.id
statements2 = mw.wikibase.getBestStatements(qid2, pid2)
end
else
if maxvals > 0 and #out >= maxvals then break end
statements2 = mw.wikibase.getAllStatements(qid2, pid2)
end
end
 
if statements2[1] then
return assembleoutput(out, args, qid, pid)
local out2 = propertyvalueandquals(statements2, args, qualID)
end
out[#out+1] = assembleoutput(out2, args, qid2, pid2)
 
end
end -- of test for valid property1 value
end -- of test for sourced
if maxvals > 0 and #out >= maxvals then break end
end -- of loop through values of property1
return assembleoutput(out, args, qid1, pid1)
end
 


-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- getAwardCat takes most of the usual parameters. If the item has values of P166 (award received),
-- getQualifierIDs takes most of the usual parameters.
-- then it examines each of those awards for P2517 (category for recipients of this award).
-- The usual whitelisting, blacklisting, onlysourced, etc. are implemented.
-- If it exists, it returns the corresponding category,
-- It takes a property-id as the first unnamed parameter, and an optional parameter qlist
-- with the item's P734 (family name) as sort key, or no sort key if there is no family name.
-- which is a list of qualifier property-ids to search for (default is "ALL")
-- The sort key may be overridden by the parameter |sortkey (alias |sk).
-- It returns the Entity-IDs (Qids) of the values of a property if it is a Wikibase-Entity.
-- The usual whitelisting, blacklisting, onlysourced, etc. are implemented
-- Otherwise it returns nothing.
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Dependencies: parseParam; setRanks; parseInput; sourced; propertyvalueandquals assembleoutput;
-- Dependencies: parseParam; setRanks; parseInput; sourced; propertyvalueandquals assembleoutput;
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
p.getAwardCat = function(frame)
p.getQualifierIDs = 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
local args = frame.args
args.sep = " "
args.reqranks = setRanks(args.rank)
local pid1 = args.prop1 or "P166"
args.langobj = findLang(args.lang)
local pid2 = args.prop2 or "P2517"
args.lang = args.langobj.code
-- change default for noicon to true
args.noicon = tostring(parseParam(args.noicon or "", true))
local f = {}
f.args = args
local pid = mw.text.trim(args[1] or ""):upper()
 
-- get the qid and table of claims for the property, or nothing and the local value passed
local qid, props = parseInput(f, args[2], pid)
if not qid then return props end
if not props[1] then return nil end
-- get the other parameters
local onlysrc = parseParam(args.onlysourced or args.osd, true)
local maxvals = tonumber(args.maxvals) or 0
local qlist = args.qlist or ""
if qlist == "" then qlist = "ALL" end
qlist = qlist:gsub("[%p%s]+", " ") .. " "
 
out = {}
for i, v in ipairs(props) do
local snak = v.mainsnak
if ( v.rank and args.reqranks[v.rank:sub(1, 1)] )
and ( snak.snaktype == "value" )
and ( sourced(v) or not onlysrc )
then
if v.qualifiers then
for k1, v1 in pairs(v.qualifiers) do
if qlist == "ALL " or qlist:match(k1 .. " ") then
for i2, v2 in ipairs(v1) do
if v2.datatype == "wikibase-item" and v2.snaktype == "value" then
out[#out+1] = v2.datavalue.value.id
end -- of test that id exists
end -- of loop through qualifier values
end -- of test for kq in qlist
end -- of loop through qualifiers
end -- of test for qualifiers
end -- of test for rank value, sourced, and value exists
if maxvals > 0 and #out >= maxvals then break end
end -- of loop through property values
 
return assembleoutput(out, args, qid, pid)
end
 
 
-------------------------------------------------------------------------------
-- getPropOfProp takes two propertyIDs: prop1 and prop2 (as well as the usual parameters)
-- If the value(s) of prop1 are of type "wikibase-item" then it returns the value(s) of prop2
-- of each of those wikibase-items.
-- The usual whitelisting, blacklisting, onlysourced, etc. are implemented
-------------------------------------------------------------------------------
-- Dependencies: parseParam; setRanks; parseInput; sourced; propertyvalueandquals assembleoutput;
-------------------------------------------------------------------------------
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
local pid1 = args.prop1 or args.pid1 or ""
local pid2 = args.prop2 or args.pid2 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
-- locally supplied value:
local localval = mw.text.trim(args[1] or "")
local qid1, statements1 = parseInput(frame, localval, pid1)
local qid1, statements1 = parseInput(frame, localval, pid1)
if not qid1 then return localval end
if not qid1 then return localval end
-- linkprefix (strip quotes)
local onlysrc = parseParam(args.onlysourced or args.osd, true)
local lp = (args.linkprefix or args.lp or ""):gsub('"', '')
local maxvals = tonumber(args.maxvals) or 0
-- sort key (strip quotes, hyphens and periods):
local qualID = mw.text.trim(args.qual or ""):upper()
local sk = (args.sortkey or args.sk or ""):gsub('["-.]', '')
-- family name:
local famname = ""
if sk == "" then
local p734 = mw.wikibase.getBestStatements(qid1, "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 onlysrc = parseParam(args.onlysourced or args.osd, true)
local maxvals = tonumber(args.maxvals) or 0
local qualID = mw.text.trim(args.qual or ""):upper()
if qualID == "" then qualID = nil end
if qualID == "" then qualID = nil end
local out = {}
local out = {}
Line 2,037: Line 2,220:
statements2 = mw.wikibase.getAllStatements(qid2, pid2)
statements2 = mw.wikibase.getAllStatements(qid2, pid2)
end
end
if statements2[1] and statements2[1].mainsnak.snaktype == "value" then
if statements2[1] then
local qid3 = statements2[1].mainsnak.datavalue.value.id
local out2 = propertyvalueandquals(statements2, args, qualID)
local sitelink = mw.wikibase.sitelink(qid3)
out[#out+1] = assembleoutput(out2, args, qid2, pid2)
-- if there's no local sitelink, create the sitelink from English label
end
if not sitelink then
end -- of test for valid property1 value
local lbl = mw.wikibase.getLabelByLang(qid3, "en")
end -- of test for sourced
if lbl then
if maxvals > 0 and #out >= maxvals then break end
if lbl:sub(1,9) == "Category:" then
end -- of loop through values of property1
sitelink = mw.text.nowiki(lbl)
return assembleoutput(out, args, qid1, pid1)
else
sitelink = "Category:" .. mw.text.nowiki(lbl)
end
end
end
if sitelink then
if sk ~= "" then
out[#out+1] = "[[" .. lp .. sitelink .. "|" .. sk .. "]]"
elseif famname ~= "" then
out[#out+1] = "[[" .. lp .. sitelink .. "|" .. famname .. "]]"
else
out[#out+1] = "[[" .. lp .. sitelink .. "]]"
end -- of check for sort keys
end -- of test for sitelink
end -- of test for category
end -- of test for wikibase item has a value
end -- of test for sourced
if maxvals > 0 and #out >= maxvals then break end
end -- of loop through values of property1
return assembleoutput(out, args, qid1, pid1)
end
end




-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- getIntersectCat takes most of the usual parameters.
-- getAwardCat takes most of the usual parameters. If the item has values of P166 (award received),
-- then it examines each of those awards for P2517 (category for recipients of this award).
-- If it exists, it returns the corresponding category,
-- with the item's P734 (family name) as sort key, or no sort key if there is no family name.
-- The sort key may be overridden by the parameter |sortkey (alias |sk).
-- The usual whitelisting, blacklisting, onlysourced, etc. are implemented
-- 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;
-- Dependencies: parseParam; setRanks; parseInput; sourced; propertyvalueandquals assembleoutput;
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
p.getIntersectCat = function(frame)
p.getAwardCat = function(frame)
frame.args.reqranks = setRanks(frame.args.rank)
frame.args.reqranks = setRanks(frame.args.rank)
frame.args.langobj = findLang(frame.args.lang)
frame.args.langobj = findLang(frame.args.lang)
Line 2,089: Line 2,248:
local args = frame.args
local args = frame.args
args.sep = " "
args.sep = " "
args.linked = "no"
local pid1 = args.prop1 or "P166"
local pid1 = args.prop1 or "P106"
local pid2 = args.prop2 or "P2517"
local pid2 = args.prop2 or "P27"
if pid1 == "" or pid2 == "" then return nil end
if pid1 == "" or pid2 == "" then return nil end
local qid, statements1 = parseInput(frame, "", pid1)
-- locally supplied value:
if not qid then return nil end
local localval = mw.text.trim(args[1] or "")
local qid, statements2 = parseInput(frame, "", pid2)
local qid1, statements1 = parseInput(frame, localval, pid1)
if not qid then return nil end
if not qid1 then return localval 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)
-- linkprefix (strip quotes)
local lp = (args.linkprefix or args.lp or ""):gsub('"', '')
local lp = (args.linkprefix or args.lp or ""):gsub('"', '')
Line 2,109: Line 2,262:
local famname = ""
local famname = ""
if sk == "" then
if sk == "" then
local p734 = mw.wikibase.getBestStatements(qid, "P734")[1]
local p734 = mw.wikibase.getBestStatements(qid1, "P734")[1]
local p734id = p734 and p734.mainsnak.snaktype == "value" and p734.mainsnak.datavalue.value.id or ""
local p734id = p734 and p734.mainsnak.snaktype == "value" and p734.mainsnak.datavalue.value.id or ""
famname = mw.wikibase.sitelink(p734id) or ""
famname = mw.wikibase.getSitelink(p734id) or ""
-- strip namespace and disambigation
-- strip namespace and disambigation
local pos = famname:find(":") or 0
local pos = famname:find(":") or 0
famname = famname:sub(pos+1):gsub("%s%(.+%)$", "")
famname = famname:sub(pos+1):gsub("%s%(.+%)$", "")
if famname == "" then
if famname == "" then
local lbl = mw.wikibase.label(p734id)
local lbl = mw.wikibase.getLabel(p734id)
famname = lbl and mw.text.nowiki(lbl) or ""
famname = lbl and mw.text.nowiki(lbl) or ""
end
end
end
end
local cat1 = {}
local onlysrc = parseParam(args.onlysourced or args.osd, true)
local maxvals = tonumber(args.maxvals) or 0
local qualID = mw.text.trim(args.qual or ""):upper()
if qualID == "" then qualID = nil end
local out = {}
for k, v in ipairs(statements1) do
for k, v in ipairs(statements1) do
if not onlysrc or sourced(v) then
if not onlysrc or sourced(v) then
-- get the ID representing the value of the property
local snak = v.mainsnak
local pvalID = (v.mainsnak.snaktype == "value") and v.mainsnak.datavalue.value.id
if snak.datatype == "wikibase-item" and snak.snaktype == "value" then
if pvalID then
local qid2 = snak.datavalue.value.id
-- get the topic's main category (P910) for that entity
local statements2 = {}
local p910 = mw.wikibase.getBestStatements(pvalID, "P910")[1]
if args.reqranks.b then
if p910 and p910.mainsnak.snaktype == "value" then
statements2 = mw.wikibase.getBestStatements(qid2, pid2)
local tmcID = p910.mainsnak.datavalue.value.id
else
-- use sitelink or the English label for the cat
statements2 = mw.wikibase.getAllStatements(qid2, pid2)
local cat = mw.wikibase.sitelink(tmcID)
end
if not cat then
if statements2[1] and statements2[1].mainsnak.snaktype == "value" then
local lbl = mw.wikibase.getLabelByLang(tmcID, "en")
local qid3 = statements2[1].mainsnak.datavalue.value.id
local sitelink = mw.wikibase.getSitelink(qid3)
-- if there's no local sitelink, create the sitelink from English label
if not sitelink then
local lbl = mw.wikibase.getLabelByLang(qid3, "en")
if lbl then
if lbl then
if lbl:sub(1,9) == "Category:" then
if lbl:sub(1,9) == "Category:" then
cat = mw.text.nowiki(lbl)
sitelink = mw.text.nowiki(lbl)
else
else
cat = "Category:" .. mw.text.nowiki(lbl)
sitelink = "Category:" .. mw.text.nowiki(lbl)
end
end
end
end
end
end
cat1[#cat1+1] = cat
if sitelink then
end -- of test for topic's main category exists
if sk ~= "" then
end -- of test for property has vaild value
out[#out+1] = "[[" .. lp .. sitelink .. "|" .. sk .. "]]"
elseif famname ~= "" then
out[#out+1] = "[[" .. lp .. sitelink .. "|" .. famname .. "]]"
else
out[#out+1] = "[[" .. lp .. sitelink .. "]]"
end -- of check for sort keys
end -- of test for sitelink
end -- of test for category
end -- of test for wikibase item has a value
end -- of test for sourced
end -- of test for sourced
if maxvals > 0 and #cat1 >= maxvals then break end
if maxvals > 0 and #out >= maxvals then break end
end
end -- of loop through values of property1
local cat2 = {}
return assembleoutput(out, args, qid1, pid1)
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
end




-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- getGlobe takes an optional qid of a Wikidata entity passed as |qid=
-- getIntersectCat takes most of the usual parameters.
-- otherwise it uses the linked item for the current page.
-- The usual whitelisting, blacklisting, onlysourced, etc. are implemented
-- If returns the Qid of the globe used in P625 (coordinate location),
-- It takes two properties, |prop1 and |prop2 (e.g. occupation and country of citizenship)
-- or nil if there isn't one.
-- 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: none
-- Dependencies: parseParam; setRanks; parseInput; sourced; propertyvalueandquals assembleoutput;
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
p.getGlobe = function(frame)
p.getIntersectCat = function(frame)
local qid = frame.args.qid or frame.args[1] or ""
frame.args.reqranks = setRanks(frame.args.rank)
if qid == "" then qid = mw.wikibase.getEntityIdForCurrentPage() end
frame.args.langobj = findLang(frame.args.lang)
local coords = mw.wikibase.getBestStatements(qid, "P625")[1]
frame.args.lang = frame.args.langobj.code
local globeid
local args = frame.args
if coords and coords.mainsnak.snaktype == "value" then
args.sep = " "
globeid = coords.mainsnak.datavalue.value.globe:match("(Q%d+)")
args.linked = "no"
end
local pid1 = args.prop1 or "P106"
return globeid
local pid2 = args.prop2 or "P27"
end
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)
-- getCommonsLink takes an optional qid of a Wikidata entity passed as |qid=
if not qid then return nil end
-- It returns one of the following in order of preference:
-- topics like countries may have different names in categories from their label in Wikidata
-- the Commons sitelink of the linked Wikidata item;
local subs_exists, subs = pcall(mw.loadData, "Module:WikidataIB/subs")
-- the Commons sitelink of the topic's main category of the linked Wikidata item;
local join = args.join or ""
-------------------------------------------------------------------------------
local onlysrc = parseParam(args.onlysourced or args.osd, true)
-- Dependencies: _getCommonslink(); _getSitelink(); parseParam()
local maxvals = tonumber(args.maxvals) or 0
-------------------------------------------------------------------------------
-- linkprefix (strip quotes)
p.getCommonsLink = function(frame)
local lp = (args.linkprefix or args.lp or ""):gsub('"', '')
local oc = frame.args.onlycat or frame.args.onlycategories
-- sort key (strip quotes, hyphens and periods):
local fb = parseParam(frame.args.fallback or frame.args.fb, true)
local sk = (args.sortkey or args.sk or ""):gsub('["-.]', '')
return _getCommonslink(frame.args.qid, oc, fb)
-- family name:
end
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 ""
-- getSitelink takes the qid of a Wikidata entity passed as |qid=
famname = mw.wikibase.getSitelink(p734id) or ""
-- It takes an optional parameter |wiki= to determine which wiki is to be checked for a sitelink
-- strip namespace and disambigation
-- If the parameter is blank, then it uses the local wiki.
local pos = famname:find(":") or 0
-- If there is a sitelink to an article available, it returns the plain text link to the article
famname = famname:sub(pos+1):gsub("%s%(.+%)$", "")
-- If there is no sitelink, it returns nil.
if famname == "" then
-------------------------------------------------------------------------------
local lbl = mw.wikibase.getLabel(p734id)
-- Dependencies: none
famname = lbl and mw.text.nowiki(lbl) or ""
-------------------------------------------------------------------------------
end
p.getSiteLink = function(frame)
return _getSitelink(frame.args.qid, frame.args.wiki or mw.text.trim(frame.args[1] or ""))
end
 
 
-------------------------------------------------------------------------------
-- getLink has the qid of a Wikidata entity passed as the first unnamed parameter or as |qid=
-- If there is a sitelink to an article on the local Wiki, it returns a link to the article
-- with the Wikidata label as the displayed text.
-- If there is no sitelink, it returns the label as plain text.
-- If there is no label in the local language, it displays the qid instead.
-------------------------------------------------------------------------------
-- Dependencies: none
-------------------------------------------------------------------------------
p.getLink = function(frame)
local itemID = mw.text.trim(frame.args[1] or frame.args.qid or "")
if itemID == "" then return end
local sitelink = mw.wikibase.sitelink(itemID)
local label = labelOrId(itemID)
if sitelink then
return "[[:" .. sitelink .. "|" .. label .. "]]"
else
return label
end
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
-- getLabel has the qid of a Wikidata entity passed as the first unnamed parameter or as |qid=
local pvalID = (v.mainsnak.snaktype == "value") and v.mainsnak.datavalue.value.id
-- It returns the Wikidata label for the local language as plain text.
if pvalID then
-- If there is no label in the local language, it displays the qid instead.
-- get the topic's main category (P910) for that entity
-------------------------------------------------------------------------------
local p910 = mw.wikibase.getBestStatements(pvalID, "P910")[1]
-- Dependencies: none
if p910 and p910.mainsnak.snaktype == "value" then
-------------------------------------------------------------------------------
local tmcID = p910.mainsnak.datavalue.value.id
p.getLabel = function(frame)
-- use sitelink or the English label for the cat
local itemID = mw.text.trim(frame.args[1] or frame.args.qid or "")
local cat = mw.wikibase.getSitelink(tmcID)
if itemID == "" then return end
if not cat then
local label = labelOrId(itemID)
local lbl = mw.wikibase.getLabelByLang(tmcID, "en")
return label
if lbl then
end
if lbl:sub(1,9) == "Category:" then
 
cat = mw.text.nowiki(lbl)
 
else
-------------------------------------------------------------------------------
cat = "Category:" .. mw.text.nowiki(lbl)
-- getAT (Article Title)
end
-- has the qid of a Wikidata entity passed as the first unnamed parameter or as |qid=
end
-- If there is a sitelink to an article on the local Wiki, it returns the sitelink as plain text.
end
-- If there is no sitelink, it returns nothing.
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
 
 
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Dependencies: none
-- qualsToTable takes most of the usual parameters.
-- The usual whitelisting, blacklisting, onlysourced, etc. are implemented.
-- A qid may be given, and the first unnamed parameter is the property ID, which is of type wikibase item.
-- It takes a list of qualifier property IDs as |quals=
-- For a given qid and property, it creates the rows of an html table,
-- each row being a value of the property (optionally only if the property matches the value in |pval= )
-- each cell being the first value of the qualifier corresponding to the list in |quals
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
p.getAT = function(frame)
-- Dependencies: parseParam; setRanks; parseInput; sourced;
local itemID = mw.text.trim(frame.args[1] or frame.args.qid or "")
-------------------------------------------------------------------------------
if itemID == "" then return end
p.qualsToTable = function(frame)
return mw.wikibase.sitelink(itemID)
local args = frame.args
end
 
local quals = args.quals or ""
if quals == "" then return "" end
 
args.reqranks = setRanks(args.rank)
 
local propertyID = mw.text.trim(args[1] or "")
local f = {}
f.args = args
local entityid, props = parseInput(f, "", propertyID)
if not entityid then return "" end
 
args.langobj = findLang(args.lang)
args.lang = args.langobj.code


local pval = args.pval or ""


-------------------------------------------------------------------------------
local qplist = mw.text.split(quals, "%p") -- split at punctuation and make a sequential table
-- getDescription has the qid of a Wikidata entity passed as |qid=
for i, v in ipairs(qplist) do
-- (it defaults to the associated qid of the current article if omitted)
qplist[i] = mw.text.trim(v):upper() -- remove whitespace and capitalise
-- and a local parameter passed as the first unnamed parameter.
-- Any local parameter passed (other than "Wikidata" or "none") becomes the return value.
-- It returns the article description for the Wikidata entity if the local parameter is "Wikidata".
-- Nothing is returned if the description doesn't exist or "none" is passed as the local parameter.
-------------------------------------------------------------------------------
-- Dependencies: none
-------------------------------------------------------------------------------
p.getDescription = function(frame)
local desc = mw.text.trim(frame.args[1] or "")
local itemID = mw.text.trim(frame.args.qid or "")
if itemID == "" then itemID = nil end
if desc:lower() == 'wikidata' then
return mw.wikibase.description(itemID)
elseif desc:lower() == 'none' then
return nil
else
return desc
end
end
end


local col1 = args.firstcol or ""
if col1 ~= "" then
col1 = col1 .. "</td><td>"
end


-------------------------------------------------------------------------------
local emptycell = args.emptycell or "&nbsp;"
-- getAliases has the qid of a Wikidata entity passed as |qid=
-- (it defaults to the associated qid of the current article if omitted)
-- and a local parameter passed as the first unnamed parameter.
-- It implements blacklisting and whitelisting with a field name of "alias" by default.
-- Any local parameter passed becomes the return value.
-- Otherwise it returns the aliases for the Wikidata entity with the usual list options.
-- Nothing is returned if the aliases do not exist.
-------------------------------------------------------------------------------
-- Dependencies: findLang(); assembleoutput()
-------------------------------------------------------------------------------
p.getAliases = function(frame)
local args = frame.args


local fieldname = args.name or ""
-- construct a 2-D array of qualifier values in qvals
if fieldname == "" then fieldname = "alias" end
local qvals = {}
for i, v in ipairs(props) do
local skip = false
if pval ~= "" then
local pid = v.mainsnak.datavalue and v.mainsnak.datavalue.value.id
if pid ~= pval then skip = true end
end
if not skip then
local qval = {}
local vqualifiers = v.qualifiers or {}
-- go through list of wanted qualifier properties
for i1, v1 in ipairs(qplist) do
-- check for that property ID in the statement's qualifiers
local qv, qtype
if vqualifiers[v1] then
qtype = vqualifiers[v1][1].datatype
if qtype == "time" then
if vqualifiers[v1][1].snaktype == "value" then
qv = mw.wikibase.renderSnak(vqualifiers[v1][1])
qv = frame:expandTemplate{title="dts", args={qv}}
else
qv = "?"
end
elseif qtype == "url" then
qv = mw.wikibase.renderSnak(vqualifiers[v1][1])
local display = mw.ustring.match( mw.uri.decode(qv, "WIKI"), "([%w ]+)$" )
if display then
qv = "[" .. qv .. " " .. display .. "]"
end
else
qv = mw.wikibase.formatValue(vqualifiers[v1][1])
end
end
-- record either the value or a placeholder
qval[i1] = qv or emptycell
end -- of loop through list of qualifiers
-- add the list of qualifier values as a "row" in the main list
qvals[#qvals+1] = qval
end
end -- of for each value loop


local blacklist = args.suppressfields or args.spf or ""
local out = {}
if blacklist:find(fieldname) then return nil end
for i, v in ipairs(qvals) do
out[i] = "<tr><td>" .. col1 .. table.concat(qvals[i], "</td><td>") .. "</td></tr>"
end
return table.concat(out, "\n")
end


local localval = mw.text.trim(args[1] or "")
if localval ~= "" then return localval end


local whitelist = args.fetchwikidata or args.fwd or ""
-------------------------------------------------------------------------------
if whitelist == "" then whitelist = "NONE" end
-- getGlobe takes an optional qid of a Wikidata entity passed as |qid=
if not (whitelist == 'ALL' or whitelist:find(fieldname)) then return nil end
-- otherwise it uses the linked item for the current page.
 
-- If returns the Qid of the globe used in P625 (coordinate location),
local qid = mw.text.trim(args.qid or "")
-- or nil if there isn't one.
if qid == "" then qid = nil end
 
local entity = mw.wikibase.getEntity(qid)
if not entity then return nil end
local aliases = entity.aliases
if not aliases then return nil end
if not qid then qid= mw.wikibase.getEntityIdForCurrentPage() end
 
args.langobj = findLang(args.lang)
local langcode = args.langobj.code
args.lang = langcode
 
local out = {}
for k1, v1 in pairs(aliases) do
if v1[1].language == langcode then
for k1, v2 in ipairs(v1) do
out[#out+1] = v2.value
end
break
end
end
 
return assembleoutput(out, args, qid)
end
 
 
-------------------------------------------------------------------------------
-- pageId returns the page id (entity ID, Qnnn) of the current page
-- returns nothing if the page is not connected to Wikidata
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Dependencies: none
-- Dependencies: none
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
p.pageId = function(frame)
p.getGlobe = function(frame)
return mw.wikibase.getEntityIdForCurrentPage()
local qid = frame.args.qid or frame.args[1] or ""
if qid == "" then qid = mw.wikibase.getEntityIdForCurrentPage() end
local coords = mw.wikibase.getBestStatements(qid, "P625")[1]
local globeid
if coords and coords.mainsnak.snaktype == "value" then
globeid = coords.mainsnak.datavalue.value.globe:match("(Q%d+)")
end
return globeid
end
end




-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- formatDate is a wrapper to export the private function format_Date
-- getCommonsLink takes an optional qid of a Wikidata entity passed as |qid=
-- It returns one of the following in order of preference:
-- the Commons sitelink of the linked Wikidata item;
-- the Commons sitelink of the topic's main category of the linked Wikidata item;
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Dependencies: format_Date();
-- Dependencies: _getCommonslink(); _getSitelink(); parseParam()
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
p.formatDate = function(frame)
p.getCommonsLink = function(frame)
return format_Date(frame.args[1], frame.args.df, frame.args.bc)
local oc = frame.args.onlycat or frame.args.onlycategories
local fb = parseParam(frame.args.fallback or frame.args.fb, true)
return _getCommonslink(frame.args.qid, oc, fb)
end
end




-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- location is a wrapper to export the private function _location
-- getSitelink takes the qid of a Wikidata entity passed as |qid=
-- it takes the entity-id as qid or the first unnamed parameter
-- It takes an optional parameter |wiki= to determine which wiki is to be checked for a sitelink
-- optional boolean parameter first toggles the display of the first item
-- If the parameter is blank, then it uses the local wiki.
-- optional boolean parameter skip toggles the display to skip to the last item
-- If there is a sitelink to an article available, it returns the plain text link to the article
-- parameter debug=<y/n> (default 'n') adds error msg if not a location
-- If there is no sitelink, it returns nil.
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Dependencies: _location();
-- Dependencies: none
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
p.location = function(frame)
p.getSiteLink = function(frame)
local debug = (frame.args.debug or ""):sub(1, 1):lower()
return _getSitelink(frame.args.qid, frame.args.wiki or mw.text.trim(frame.args[1] or ""))
if debug == "" then debug = "n" end
local qid = mw.text.trim(frame.args.qid or frame.args[1] or ""):upper()
if qid == "" then qid=mw.wikibase.getEntityIdForCurrentPage() end
if not qid then
if debug ~= "n" then
return i18n.errors["entity-not-found"]
else
return nil
end
end
local first = mw.text.trim(frame.args.first or "")
local skip = mw.text.trim(frame.args.skip or "")
return table.concat( _location(qid, first, skip), ", " )
end
end




-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- checkBlacklist implements a test to check whether a named field is allowed
-- getLink has the qid of a Wikidata entity passed as the first unnamed parameter or as |qid=
-- returns true if the field is not blacklisted (i.e. allowed)
-- If there is a sitelink to an article on the local Wiki, it returns a link to the article
-- returns false if the field is blacklisted (i.e. disallowed)
-- with the Wikidata label as the displayed text.
-- {{#if:{{#invoke:WikidataIB |checkBlacklist |name=Joe |suppressfields=Dave; Joe; Fred}} | not blacklisted | blacklisted}}
-- If there is no sitelink, it returns the label as plain text.
-- displays "blacklisted"
-- If there is no label in the local language, it displays the qid instead.
-- {{#if:{{#invoke:WikidataIB |checkBlacklist |name=Jim |suppressfields=Dave; Joe; Fred}} | not blacklisted | blacklisted}}
-- displays "not blacklisted"
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Dependencies: none
-- Dependencies: none
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
p.checkBlacklist = function(frame)
p.getLink = function(frame)
local blacklist = frame.args.suppressfields or frame.args.spf or ""
local itemID = mw.text.trim(frame.args[1] or frame.args.qid or "")
local fieldname = frame.args.name or ""
if itemID == "" then return end
if blacklist ~= "" and fieldname ~= "" then
local sitelink = mw.wikibase.getSitelink(itemID)
if blacklist:find(fieldname) then
local label = labelOrId(itemID)
return false
if sitelink then
else
return "[[:" .. sitelink .. "|" .. label .. "]]"
return true
end
else
else
-- one of the fields is missing: let's call that "not on the list"
return label
return true
end
end
end
end
Line 2,429: Line 2,590:


-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- emptyor returns nil if its first unnamed argument is just punctuation, whitespace or html tags
-- getLabel has the qid of a Wikidata entity passed as the first unnamed parameter or as |qid=
-- otherwise it returns the argument unchanged (including leading/trailing space).
-- It returns the Wikidata label for the local language as plain text.
-- If the argument may contain "=", then it must be called explicitly:
-- If there is no label in the local language, it displays the qid instead.
-- |1=arg
-- (In that case, leading and trailing spaces are trimmed)
-- It finds use in infoboxes where it can replace tests like:
-- {{#if: {{#invoke:WikidatIB |getvalue |P99 |fwd=ALL}} | <span class="xxx">{{#invoke:WikidatIB |getvalue |P99 |fwd=ALL}}</span> | }}
-- with a form that uses just a single call to Wikidata:
-- {{#invoke |WikidataIB |emptyor |1= <span class="xxx">{{#invoke:WikidataIB |getvalue |P99 |fwd=ALL}}</span> }}
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Dependencies: none
-- Dependencies: none
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
p.emptyor = function(frame)
p.getLabel = function(frame)
local s = frame.args[1] or ""
local itemID = mw.text.trim(frame.args[1] or frame.args.qid or "")
if s == "" then return nil end
if itemID == "" then return end
local sx = s:gsub("%s", ""):gsub("<[^>]*>", ""):gsub("%p", "")
local lang = frame.args.lang or ""
if sx == "" then
if lang == "" then lang = nil end
return nil
local label = labelOrId(itemID, lang)
else
return label
return s
end
end
end




-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- labelorid is a public function to expose the output of labelOrId()
-- label has the qid of a Wikidata entity passed as the first unnamed parameter or as |qid=
-- Pass the Q-number as |qid= or as an unnamed parameter.
-- if no qid is supplied, it uses the qid associated with the current page.
-- It returns the Wikidata label for that entity or the qid if no label exists.
-- It returns the Wikidata label for the local language as plain text.
-- If there is no label in the local language, it returns nil.
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Dependencies: labelOrId
-- Dependencies: none
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
p.labelorid = function(frame)
p.label = function(frame)
return labelOrId( frame.args.qid or frame.args[1] )
local qid = mw.text.trim(frame.args[1] or frame.args.qid or "")
if qid == "" then qid = mw.wikibase.getEntityIdForCurrentPage() end
if not qid then return end
local lang = frame.args.lang or ""
if lang == "" then lang = nil end
local label, success = labelOrId(qid, lang)
if success then return label end
end
end




-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- getLang returns the MediaWiki language code of the current content.
-- getAT (Article Title)
-- If optional parameter |style=full, it returns the language name.
-- has the qid of a Wikidata entity passed as the first unnamed parameter or as |qid=
-- If there is a sitelink to an article on the local Wiki, it returns the sitelink as plain text.
-- If there is no sitelink or qid supplied, it returns nothing.
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Dependencies: none
-- Dependencies: none
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
p.getLang = function(frame)
p.getAT = function(frame)
local style = (frame.args.style or ""):lower()
local itemID = mw.text.trim(frame.args[1] or frame.args.qid or "")
local langcode = mw.language.getContentLanguage().code
if itemID == "" then return end
if style == "full" then
return mw.wikibase.getSitelink(itemID)
return mw.language.fetchLanguageName( langcode )
end
return langcode
end
end




-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- getItemLangCode takes a qid parameter (using the current page's qid if blank)
-- getDescription has the qid of a Wikidata entity passed as |qid=
-- If the item for that qid has property country (P17) it looks at the first preferred value
-- (it defaults to the associated qid of the current article if omitted)
-- If the country has an official language (P37), it looks at the first preferred value
-- and a local parameter passed as the first unnamed parameter.
-- If that official language has a language code (P424), it returns the first preferred value
-- Any local parameter passed (other than "Wikidata" or "none") becomes the return value.
-- Otherwise it returns nothing.
-- It returns the article description for the Wikidata entity if the local parameter is "Wikidata".
-- Nothing is returned if the description doesn't exist or "none" is passed as the local parameter.
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Dependencies: _getItemLangCode()
-- Dependencies: none
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
p.getItemLangCode = function(frame)
p.getDescription = function(frame)
return _getItemLangCode(frame.args.qid or frame.args[1])
local desc = mw.text.trim(frame.args[1] or "")
local itemID = mw.text.trim(frame.args.qid or "")
if itemID == "" then itemID = nil end
if desc:lower() == 'wikidata' then
return mw.wikibase.getDescription(itemID)
elseif desc:lower() == 'none' then
return nil
else
return desc
end
end
end




-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- findLanguage exports the local findLang() function
-- getAliases has the qid of a Wikidata entity passed as |qid=
-- It takes an optional language code and returns, in order of preference:
-- (it defaults to the associated qid of the current article if omitted)
-- the code if a known language;
-- and a local parameter passed as the first unnamed parameter.
-- the user's language, if set;
-- It implements blacklisting and whitelisting with a field name of "alias" by default.
-- the server's content language.
-- Any local parameter passed becomes the return value.
-- Otherwise it returns the aliases for the Wikidata entity with the usual list options.
-- Nothing is returned if the aliases do not exist.
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Dependencies: findLang
-- Dependencies: findLang(); assembleoutput()
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
p.findLanguage = function(frame)
p.getAliases = function(frame)
return findLang(frame.args.lang or frame.args[1]).code
local args = frame.args
end


local fieldname = args.name or ""
if fieldname == "" then fieldname = "alias" end


-------------------------------------------------------------------------------
local blacklist = args.suppressfields or args.spf or ""
-- getQid returns the qid, if supplied
if blacklist:find(fieldname) then return nil end
-- failing that, the Wikidata entity ID of the "category's main topic (P301)", if it exists
-- failing that, the Wikidata entity ID asociated with the curent page, if it exists
-- otherwise, nothing
-------------------------------------------------------------------------------
-- Dependencies: none
-------------------------------------------------------------------------------
p.getQid = function(frame)
local qid = (frame.args.qid or ""):upper()
-- check if a qid was passed; if so, return it:
if qid ~= "" then return qid end
-- check if there's a "category's main topic (P301)":
qid = mw.wikibase.getEntityIdForCurrentPage()
if qid then
local prop301 = mw.wikibase.getBestStatements(qid, "P301")
if prop301[1] then
local mctid = prop301[1].mainsnak.datavalue.value.id
if mctid then return mctid end
end
end
-- otherwise return the page qid (if any)
return qid
end


local localval = mw.text.trim(args[1] or "")
if localval ~= "" then return localval end
local whitelist = args.fetchwikidata or args.fwd or ""
if whitelist == "" then whitelist = "NONE" end
if not (whitelist == 'ALL' or whitelist:find(fieldname)) then return nil end
local qid = mw.text.trim(args.qid or "")
if qid == "" then qid = nil end
local entity = mw.wikibase.getEntity(qid)
if not entity then return nil end
local aliases = entity.aliases
if not aliases then return nil end
if not qid then qid= mw.wikibase.getEntityIdForCurrentPage() end
args.langobj = findLang(args.lang)
local langcode = args.langobj.code
args.lang = langcode


-------------------------------------------------------------------------------
-- followQid takes two optional parameters: qid and props
-- If qid is not given, it uses the qid for the connected page
-- or returns nil if there isn't one.
-- props is a list of properties, separated by punctuation.
-- If props is given, the Wikidata item for the qid is examined for each property in turn.
-- If that property contains a value that is another Wikibase-item, that item's qid is returned,
-- and the search terminates, unless |all=y when all of the qids are returned, sparated by spaces.
-- If props is not given, the qid is returned.
-------------------------------------------------------------------------------
-- Dependencies: parseParam()
-------------------------------------------------------------------------------
p.followQid = function(frame)
local qid = (frame.args.qid or ""):upper()
local all = parseParam(frame.args.all, false)
if qid == "" then
qid = mw.wikibase.getEntityIdForCurrentPage()
end
if not qid then return nil end
local out = {}
local out = {}
local props = (frame.args.props or ""):upper()
for k1, v1 in pairs(aliases) do
if props ~= "" then
if v1[1].language == langcode then
for p in mw.text.gsplit(props, "%p") do -- split at punctuation and iterate
for k1, v2 in ipairs(v1) do
p = mw.text.trim(p)
out[#out+1] = v2.value
for i, v in ipairs( mw.wikibase.getBestStatements(qid, p) ) do
end
local linkedid = v.mainsnak.datavalue and v.mainsnak.datavalue.value.id
break
if linkedid then
end
if all then
out[#out+1] = linkedid
else
return linkedid
end -- test for all or just the first one found
end -- test for value exists for that property
end -- loop through values of property to follow
end -- loop through list of properties to follow
end
if #out > 0 then
return table.concat(out, " ")
else
return qid
end
end
return assembleoutput(out, args, qid)
end
end




-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- siteID returns the root of the globalSiteID
-- pageId returns the page id (entity ID, Qnnn) of the current page
-- e.g. "en" for "enwiki", "enwikisource", etc.
-- returns nothing if the page is not connected to Wikidata
-- treats "en-gb" as "en", etc.
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Dependencies: none
-- Dependencies: none
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
p.siteID = function(frame)
p.pageId = function(frame)
local txtlang = frame:preprocess( "{{int:lang}}" ) or ""
return mw.wikibase.getEntityIdForCurrentPage()
-- This deals with specific exceptions: be-tarask -> be-x-old
if txtlang == "be-tarask" then
return "be_x_old"
end
local pos = txtlang:find("-")
local ret = ""
if pos then
ret = txtlang:sub(1, pos-1)
else
ret = txtlang
end
return ret
end
end




-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- projID returns the code used to link to the reader's language's project
-- formatDate is a wrapper to export the private function format_Date
-- e.g "en" for [[:en:WikidataIB]]
-- treats "en-gb" as "en", etc.
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Dependencies: none
-- Dependencies: format_Date();
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
p.projID = function(frame)
p.formatDate = function(frame)
local txtlang = frame:preprocess( "{{int:lang}}" ) or ""
return format_Date(frame.args[1], frame.args.df, frame.args.bc)
-- This deals with specific exceptions: be-tarask -> be-x-old
if txtlang == "be-tarask" then
return "be-x-old"
end
local pos = txtlang:find("-")
local ret = ""
if pos then
ret = txtlang:sub(1, pos-1)
else
ret = txtlang
end
return ret
end
end




-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- formatNumber formats a number according to the the supplied language code ("|lang=")
-- location is a wrapper to export the private function _location
-- or the default language if not supplied.
-- it takes the entity-id as qid or the first unnamed parameter
-- The number is the first unnamed parameter or "|num="
-- optional boolean parameter first toggles the display of the first item
-- optional boolean parameter skip toggles the display to skip to the last item
-- parameter debug=<y/n> (default 'n') adds error msg if not a location
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Dependencies: findLang()
-- Dependencies: _location();
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
p.formatNumber = function(frame)
p.location = function(frame)
local lang
local debug = (frame.args.debug or ""):sub(1, 1):lower()
local num = tonumber(frame.args[1] or frame.args.num) or 0
if debug == "" then debug = "n" end
lang = findLang(frame.args.lang)
local qid = mw.text.trim(frame.args.qid or frame.args[1] or ""):upper()
return lang:formatNum( num )
if qid == "" then qid=mw.wikibase.getEntityIdForCurrentPage() end
if not qid then
if debug ~= "n" then
return i18n.errors["entity-not-found"]
else
return nil
end
end
local first = mw.text.trim(frame.args.first or "")
local skip = mw.text.trim(frame.args.skip or "")
return table.concat( _location(qid, first, skip), ", " )
end
end




-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- examine dumps the property (the unnamed parameter or pid)
-- checkBlacklist implements a test to check whether a named field is allowed
-- from the item given by the parameter 'qid' (or the other unnamed parameter)
-- returns true if the field is not blacklisted (i.e. allowed)
-- or from the item corresponding to the current page if qid is not supplied.
-- returns false if the field is blacklisted (i.e. disallowed)
-- e.g. {{#invoke:WikidataIB |examine |pid=P26 |qid=Q42}}
-- {{#if:{{#invoke:WikidataIB |checkBlacklist |name=Joe |suppressfields=Dave; Joe; Fred}} | not blacklisted | blacklisted}}
-- or {{#invoke:WikidataIB |examine |P26 |Q42}} or any combination of these
-- displays "blacklisted"
-- or {{#invoke:WikidataIB |examine |P26}} for the current page.
-- {{#if:{{#invoke:WikidataIB |checkBlacklist |name=Jim |suppressfields=Dave; Joe; Fred}} | not blacklisted | blacklisted}}
-- displays "not blacklisted"
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Dependencies: none
-- Dependencies: none
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
p.examine = function( frame )
p.checkBlacklist = function(frame)
local args
local blacklist = frame.args.suppressfields or frame.args.spf or ""
if frame.args[1] or frame.args.pid or frame.args.qid then
local fieldname = frame.args.name or ""
args = frame.args
if blacklist ~= "" and fieldname ~= "" then
if blacklist:find(fieldname) then
return false
else
return true
end
else
else
args = frame:getParent().args
-- one of the fields is missing: let's call that "not on the list"
return true
end
end
 
 
-------------------------------------------------------------------------------
-- emptyor returns nil if its first unnamed argument is just punctuation, whitespace or html tags
-- otherwise it returns the argument unchanged (including leading/trailing space).
-- If the argument may contain "=", then it must be called explicitly:
-- |1=arg
-- (In that case, leading and trailing spaces are trimmed)
-- It finds use in infoboxes where it can replace tests like:
-- {{#if: {{#invoke:WikidatIB |getvalue |P99 |fwd=ALL}} | <span class="xxx">{{#invoke:WikidatIB |getvalue |P99 |fwd=ALL}}</span> | }}
-- with a form that uses just a single call to Wikidata:
-- {{#invoke |WikidataIB |emptyor |1= <span class="xxx">{{#invoke:WikidataIB |getvalue |P99 |fwd=ALL}}</span> }}
-------------------------------------------------------------------------------
-- Dependencies: none
-------------------------------------------------------------------------------
p.emptyor = function(frame)
local s = frame.args[1] or ""
if s == "" then return nil end
local sx = s:gsub("%s", ""):gsub("<[^>]*>", ""):gsub("%p", "")
if sx == "" then
return nil
else
return s
end
end
local par = {}
local pid = (args.pid or ""):upper()
local qid = (args.qid or ""):upper()
par[1] = mw.text.trim( args[1] or "" ):upper()
par[2] = mw.text.trim( args[2] or "" ):upper()
table.sort(par)
if par[2]:sub(1,1) == "P" then par[1], par[2] = par[2], par[1] end
if pid == "" then pid = par[1] end
if qid == "" then qid = par[2] end
if pid:sub(1,1) ~= "P" then return "No property supplied" end
if qid:sub(1,1) ~= "Q" then qid = mw.wikibase.getEntityIdForCurrentPage() end
if not qid then return "No item for this page" end
return "<pre>" .. mw.dumpObject( mw.wikibase.getAllStatements( qid, pid ) ) .. "</pre>"
end
end




-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- checkvalue looks for 'val' as a wikibase-item value of a property (the unnamed parameter or pid)
-- labelorid is a public function to expose the output of labelOrId()
-- from the item given by the parameter 'qid'
-- Pass the Q-number as |qid= or as an unnamed parameter.
-- or from the Wikidata item associated with the current page if qid is not supplied.
-- It returns the Wikidata label for that entity or the qid if no label exists.
-- If property is not supplied, then P31 (instance of) is assumed.
-------------------------------------------------------------------------------
-- It returns val if found or nothing if not found.
-- Dependencies: labelOrId
-- e.g. {{#invoke:WikidataIB |checkvalue |val=Q5 |pid=P31 |qid=Q42}}
-- or {{#invoke:WikidataIB |checkvalue |val=Q5 |P31 |qid=Q42}}
-- or {{#invoke:WikidataIB |checkvalue |val=Q5 |qid=Q42}}
-- or {{#invoke:WikidataIB |checkvalue |val=Q5 |P31}} for the current page.
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Dependencies: none
p.labelorid = function(frame)
-------------------------------------------------------------------------------
return (labelOrId(frame.args.qid or frame.args[1]))
p.checkvalue = function( frame )
local args
if frame.args.val then
args = frame.args
else
args = frame:getParent().args
end
local val = args.val
if not val then return nil end
local pid = mw.text.trim(args.pid or args[1] or "P31"):upper()
local qid = (args.qid or ""):upper()
if pid:sub(1,1) ~= "P" then return nil end
if qid:sub(1,1) ~= "Q" then qid = mw.wikibase.getEntityIdForCurrentPage() end
if not qid then return nil end
local stats = mw.wikibase.getAllStatements( qid, pid )
if not stats[1] then return nil end
if stats[1].mainsnak.datatype == "wikibase-item" then
for k, v in pairs( stats ) do
if v.mainsnak.snaktype == "value" and v.mainsnak.datavalue.value.id == val then
return val
end
end
end
return nil
end
end




-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- url2 takes a parameter url= that is a proper url and formats it for use in an infobox.
-- getLang returns the MediaWiki language code of the current content.
-- If no parameter is supplied, it returns nothing.
-- If optional parameter |style=full, it returns the language name.
-- This is the equivalent of Template:URL
-- 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:
-- e.g. {{#invoke:WikidataIB |url2 |url={{wdib |P856 |qid=Q23317 |fwd=ALL |osd=no}}
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Dependencies: none
-- Dependencies: none
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
p.url2 = function(frame)
p.getLang = function(frame)
local txt = frame.args.url or ""
local style = (frame.args.style or ""):lower()
if txt == "" then return nil end
local langcode = mw.language.getContentLanguage().code
local url, icon = txt:match("(.+)&nbsp;(.+)")
if style == "full" then
url = url or txt
return mw.language.fetchLanguageName( langcode )
icon = icon or ""
end
local prot, addr = url:match("(http[s]*://)(.+)")
return langcode
prot = prot or url
addr = addr or ""
local disp, n = addr:gsub("%.", "<wbr/>%.")
return '<span class="url">[' .. prot .. addr .. " " .. disp .. "]</span>&nbsp;" .. icon
end
end




-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- getWebsite fetches the Official website (P856) and formats it for use in an infobox.
-- getItemLangCode takes a qid parameter (using the current page's qid if blank)
-- This is similar to Template:Official website but with a url displayed,
-- If the item for that qid has property country (P17) it looks at the first preferred value
-- and it adds the "edit at Wikidata" pen icon beyond the microformat if enabled.
-- If the country has an official language (P37), it looks at the first preferred value
-- A local value will override the Wikidata value. "NONE" returns nothing.
-- If that official language has a language code (P424), it returns the first preferred value
-- e.g. {{#invoke:WikidataIB |getWebsite |qid= |noicon= |lang= |url= }}
-- Otherwise it returns nothing.
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Dependencies: findLang(); parseParam();
-- Dependencies: _getItemLangCode()
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
p.getWebsite = function(frame)
p.getItemLangCode = function(frame)
local url = frame.args.url or ""
return _getItemLangCode(frame.args.qid or frame.args[1])
if url:upper() == "NONE" then return nil end
end
 


local qid = frame.args.qid or ""
-------------------------------------------------------------------------------
if qid == "" then qid = mw.wikibase.getEntityIdForCurrentPage() end
-- findLanguage exports the local findLang() function
if not qid then return nil end
-- It takes an optional language code and returns, in order of preference:
-- the code if a known language;
-- the user's language, if set;
-- the server's content language.
-------------------------------------------------------------------------------
-- Dependencies: findLang
-------------------------------------------------------------------------------
p.findLanguage = function(frame)
return findLang(frame.args.lang or frame.args[1]).code
end


local urls = {}
 
local quals = {}
-------------------------------------------------------------------------------
if url == "" then
-- getQid returns the qid, if supplied
local prop856 = mw.wikibase.getBestStatements(qid, "P856")
-- failing that, the Wikidata entity ID of the "category's main topic (P301)", if it exists
for k, v in pairs(prop856) do
-- failing that, the Wikidata entity ID associated with the current page, if it exists
if v.mainsnak.snaktype == "value" then
-- otherwise, nothing
urls[#urls+1] = v.mainsnak.datavalue.value
-------------------------------------------------------------------------------
if v.qualifiers and v.qualifiers["P1065"] then
-- Dependencies: none
-- just take the first archive url (P1065)
-------------------------------------------------------------------------------
local au = v.qualifiers["P1065"][1]
p.getQid = function(frame)
if au.snaktype == "value" then
local qid = (frame.args.qid or ""):upper()
quals[#urls] = au.datavalue.value
-- check if a qid was passed; if so, return it:
end -- test for archive url having a value
if qid ~= "" then return qid end
end -- test for qualifers
-- check if there's a "category's main topic (P301)":
end -- test for website having a value
qid = mw.wikibase.getEntityIdForCurrentPage()
end -- loop through website(s)
if qid then
else
local prop301 = mw.wikibase.getBestStatements(qid, "P301")
urls[1] = url
if prop301[1] then
local mctid = prop301[1].mainsnak.datavalue.value.id
if mctid then return mctid end
end
end
end
if #urls == 0 then return nil end
-- otherwise return the page qid (if any)
 
return qid
local out = {}
end
for i, u in ipairs(urls) do
local link = quals[i] or u
local prot, addr = u:match("(http[s]*://)(.+)")
addr = addr or u
local disp, n = addr:gsub("%.", "<wbr/>%.")
out[#out+1] = '<span class="url">[' .. link .. " " .. disp .. "]</span>"
end
 
local langcode = findLang(frame.args.lang).code
local noicon = parseParam(frame.args.noicon, false)
if url == "" and not noicon then
out[#out] = out[#out] .. createicon(langcode, qid, "P856")
end
 
local ret = ""
if #out > 1 then
ret = mw.getCurrentFrame():expandTemplate{title = "ubl", args = out}
else
ret = out[1]
end
 
return ret
end




-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- getAllLabels fetches the set of labels and formats it for display as wikitext.
-- followQid takes three optional parameters: qid, props, and all.
-- It takes a parameter 'qid' for arbitrary access, otherwise it uses the current page.
-- If qid is not given, it uses the qid for the connected page
-- or returns nil if there isn't one.
-- props is a list of properties, separated by punctuation.
-- If props is given, the Wikidata item for the qid is examined for each property in turn.
-- If that property contains a value that is another Wikibase-item, that item's qid is returned,
-- and the search terminates, unless |all=y when all of the qids are returned, sparated by spaces.
-- If props is not given, the qid is returned.
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Dependencies: none
-- Dependencies: parseParam()
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
p.getAllLabels = function(frame)
p.followQid = function(frame)
local args = frame.args or frame:getParent().args or {}
local qid = (frame.args.qid or ""):upper()
local all = parseParam(frame.args.all, false)
if qid == "" then
qid = mw.wikibase.getEntityIdForCurrentPage()
end
if not qid then return nil end
local out = {}
local props = (frame.args.props or ""):upper()
if props ~= "" then
for p in mw.text.gsplit(props, "%p") do -- split at punctuation and iterate
p = mw.text.trim(p)
for i, v in ipairs( mw.wikibase.getBestStatements(qid, p) ) do
local linkedid = v.mainsnak.datavalue and v.mainsnak.datavalue.value.id
if linkedid then
if all then
out[#out+1] = linkedid
else
return linkedid
end -- test for all or just the first one found
end -- test for value exists for that property
end -- loop through values of property to follow
end -- loop through list of properties to follow
end
if #out > 0 then
return table.concat(out, " ")
else
return qid
end
end


local qid = args.qid
if qid == "" then qid = nil end


local entity = mw.wikibase.getEntity(qid)
-------------------------------------------------------------------------------
if not entity then return i18n["entity-not-found"] end
-- globalSiteID returns the globalSiteID for the current wiki
 
-- e.g. returns "enwiki" for the English Wikipedia, "enwikisource" for English Wikisource, etc.
local labels = entity.labels
-------------------------------------------------------------------------------
if not labels then return i18n["labels-not-found"] end
-- Dependencies: none
 
-------------------------------------------------------------------------------
local out = {}
p.globalSiteID = function(frame)
for k, v in pairs(labels) do
return mw.wikibase.getGlobalSiteId()
out[#out+1] = v.value .. " (" .. v.language .. ")"
end
 
return table.concat(out, "; ")
end
end




-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- getAllDescriptions fetches the set of descriptions and formats it for display as wikitext.
-- siteID returns the root of the globalSiteID
-- It takes a parameter 'qid' for arbitrary access, otherwise it uses the current page.
-- e.g. "en" for "enwiki", "enwikisource", etc.
-- treats "en-gb" as "en", etc.
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Dependencies: none
-- Dependencies: none
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
p.getAllDescriptions = function(frame)
p.siteID = function(frame)
local args = frame.args or frame:getParent().args or {}
local txtlang = frame:preprocess( "{{int:lang}}" ) or ""
-- This deals with specific exceptions: be-tarask -> be-x-old
if txtlang == "be-tarask" then
return "be_x_old"
end
local pos = txtlang:find("-")
local ret = ""
if pos then
ret = txtlang:sub(1, pos-1)
else
ret = txtlang
end
return ret
end


local qid = args.qid
if qid == "" then qid = nil end


local entity = mw.wikibase.getEntity(qid)
-------------------------------------------------------------------------------
if not entity then return i18n["entity-not-found"] end
-- projID returns the code used to link to the reader's language's project
 
-- e.g "en" for [[:en:WikidataIB]]
local descriptions = entity.descriptions
-- treats "en-gb" as "en", etc.
if not descriptions then return i18n["descriptions-not-found"] end
-------------------------------------------------------------------------------
 
-- Dependencies: none
local out = {}
-------------------------------------------------------------------------------
for k, v in pairs(descriptions) do
p.projID = function(frame)
out[#out+1] = v.value .. " (" .. v.language .. ")"
local txtlang = frame:preprocess( "{{int:lang}}" ) or ""
-- This deals with specific exceptions: be-tarask -> be-x-old
if txtlang == "be-tarask" then
return "be-x-old"
end
local pos = txtlang:find("-")
local ret = ""
if pos then
ret = txtlang:sub(1, pos-1)
else
ret = txtlang
end
end
 
return ret
return table.concat(out, "; ")
end
end




-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- getAllAliases fetches the set of aliases and formats it for display as wikitext.
-- formatNumber formats a number according to the the supplied language code ("|lang=")
-- It takes a parameter 'qid' for arbitrary access, otherwise it uses the current page.
-- or the default language if not supplied.
-- The number is the first unnamed parameter or "|num="
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Dependencies: none
-- Dependencies: findLang()
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
p.getAllAliases = function(frame)
p.formatNumber = function(frame)
local args = frame.args or frame:getParent().args or {}
local lang
local num = tonumber(frame.args[1] or frame.args.num) or 0
lang = findLang(frame.args.lang)
return lang:formatNum( num )
end


local qid = args.qid
if qid == "" then qid = nil end


local entity = mw.wikibase.getEntity(qid)
-------------------------------------------------------------------------------
if not entity then return i18n["entity-not-found"] end
-- examine dumps the property (the unnamed parameter or pid)
 
-- from the item given by the parameter 'qid' (or the other unnamed parameter)
local aliases = entity.aliases
-- or from the item corresponding to the current page if qid is not supplied.
if not aliases then return i18n["aliases-not-found"] end
-- e.g. {{#invoke:WikidataIB |examine |pid=P26 |qid=Q42}}
 
-- or {{#invoke:WikidataIB |examine |P26 |Q42}} or any combination of these
local out = {}
-- or {{#invoke:WikidataIB |examine |P26}} for the current page.
for k1, v1 in pairs(aliases) do
-------------------------------------------------------------------------------
local lang = v1[1].language
-- Dependencies: none
local val = {}
-------------------------------------------------------------------------------
for k1, v2 in ipairs(v1) do
p.examine = function( frame )
val[#val+1] = v2.value
local args
end
if frame.args[1] or frame.args.pid or frame.args.qid then
out[#out+1] = table.concat(val, ", ") .. " (" .. lang .. ")"
args = frame.args
else
args = frame:getParent().args
end
end
 
local par = {}
return table.concat(out, "; ")
local pid = (args.pid or ""):upper()
end
local qid = (args.qid or ""):upper()
 
par[1] = mw.text.trim( args[1] or "" ):upper()
 
par[2] = mw.text.trim( args[2] or "" ):upper()
-------------------------------------------------------------------------------
table.sort(par)
-- showNoLinks displays the article titles that should not be linked.
if par[2]:sub(1,1) == "P" then par[1], par[2] = par[2], par[1] end
-------------------------------------------------------------------------------
if pid == "" then pid = par[1] end
-- Dependencies: none
if qid == "" then qid = par[2] end
-------------------------------------------------------------------------------
local q1 = qid:sub(1,1)
p.showNoLinks = function(frame)
if pid:sub(1,1) ~= "P" then return "No property supplied" end
local out = {}
if q1 ~= "Q" and q1 ~= "M" then qid = mw.wikibase.getEntityIdForCurrentPage() end
for k, v in pairs(donotlink) do
if not qid then return "No item for this page" end
out[#out+1] = k
return "<pre>" .. mw.dumpObject( mw.wikibase.getAllStatements( qid, pid ) ) .. "</pre>"
end
end
table.sort( out )
 
return table.concat(out, "; ")
 
end
-------------------------------------------------------------------------------
 
-- checkvalue looks for 'val' as a wikibase-item value of a property (the unnamed parameter or pid)
 
-- from the item given by the parameter 'qid'
-------------------------------------------------------------------------------
-- or from the Wikidata item associated with the current page if qid is not supplied.
-- checkValidity checks whether the first unnamed parameter represents a valid entity-id,
-- If property is not supplied, then P31 (instance of) is assumed.
-- that is, something like Q1235 or P123.
-- It returns val if found or nothing if not found.
-- It returns the strings "true" or "false".
-- e.g. {{#invoke:WikidataIB |checkvalue |val=Q5 |pid=P31 |qid=Q42}}
-- Change false to nil to return "true" or "" (easier to test with #if:).
-- or {{#invoke:WikidataIB |checkvalue |val=Q5 |P31 |qid=Q42}}
-------------------------------------------------------------------------------
-- or {{#invoke:WikidataIB |checkvalue |val=Q5 |qid=Q42}}
-- Dependencies: none
-- or {{#invoke:WikidataIB |checkvalue |val=Q5 |P31}} for the current page.
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
function p.checkValidity(frame)
-- Dependencies: none
local id = mw.text.trim(frame.args[1] or "")
-------------------------------------------------------------------------------
if mw.wikibase.isValidEntityId(id) then
p.checkvalue = function( frame )
return true
local args
else
if frame.args.val then
return false
args = frame.args
else
args = frame:getParent().args
end
local val = args.val
if not val then return nil end
local pid = mw.text.trim(args.pid or args[1] or "P31"):upper()
local qid = (args.qid or ""):upper()
if pid:sub(1,1) ~= "P" then return nil end
if qid:sub(1,1) ~= "Q" then qid = mw.wikibase.getEntityIdForCurrentPage() end
if not qid then return nil end
local stats = mw.wikibase.getAllStatements( qid, pid )
if not stats[1] then return nil end
if stats[1].mainsnak.datatype == "wikibase-item" then
for k, v in pairs( stats ) do
if v.mainsnak.snaktype == "value" and v.mainsnak.datavalue.value.id == val then
return val
end
end
end
return nil
end
 
 
-------------------------------------------------------------------------------
-- url2 takes a parameter url= that is a proper url and formats it for use in an infobox.
-- If no parameter is supplied, it returns nothing.
-- This is the equivalent of Template:URL
-- 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:
-- e.g. {{#invoke:WikidataIB |url2 |url={{wdib |P856 |qid=Q23317 |fwd=ALL |osd=no}}
-------------------------------------------------------------------------------
-- Dependencies: none
-------------------------------------------------------------------------------
p.url2 = function(frame)
local txt = frame.args.url or ""
if txt == "" then return nil end
local url, icon = txt:match("(.+)&nbsp;(.+)")
url = url or txt
icon = icon or ""
local prot, addr = url:match("(http[s]*://)(.+)")
prot = prot or url
addr = addr or ""
local disp, n = addr:gsub("%.", "<wbr/>%.")
return '<span class="url">[' .. prot .. addr .. " " .. disp .. "]</span>&nbsp;" .. icon
end
 
 
-------------------------------------------------------------------------------
-- getWebsite fetches the Official website (P856) and formats it for use in an infobox.
-- This is similar to Template:Official website but with a url displayed,
-- and it adds the "edit at Wikidata" pen icon beyond the microformat if enabled.
-- A local value will override the Wikidata value. "NONE" returns nothing.
-- e.g. {{#invoke:WikidataIB |getWebsite |qid= |noicon= |lang= |url= }}
-------------------------------------------------------------------------------
-- Dependencies: findLang(); parseParam();
-------------------------------------------------------------------------------
p.getWebsite = function(frame)
local url = frame.args.url or ""
if url:upper() == "NONE" then return nil end
 
local qid = frame.args.qid or ""
if qid == "" then qid = mw.wikibase.getEntityIdForCurrentPage() end
if not qid then return nil end
 
local urls = {}
local quals = {}
if url == "" then
local prop856 = mw.wikibase.getBestStatements(qid, "P856")
for k, v in pairs(prop856) do
if v.mainsnak.snaktype == "value" then
urls[#urls+1] = v.mainsnak.datavalue.value
if v.qualifiers and v.qualifiers["P1065"] then
-- just take the first archive url (P1065)
local au = v.qualifiers["P1065"][1]
if au.snaktype == "value" then
quals[#urls] = au.datavalue.value
end -- test for archive url having a value
end -- test for qualifers
end -- test for website having a value
end -- loop through website(s)
else
urls[1] = url
end
if #urls == 0 then return nil end
 
local out = {}
for i, u in ipairs(urls) do
local link = quals[i] or u
local prot, addr = u:match("(http[s]*://)(.+)")
addr = addr or u
local disp, n = addr:gsub("%.", "<wbr/>%.")
out[#out+1] = '<span class="url">[' .. link .. " " .. disp .. "]</span>"
end
 
local langcode = findLang(frame.args.lang).code
local noicon = parseParam(frame.args.noicon, false)
if url == "" and not noicon then
out[#out] = out[#out] .. createicon(langcode, qid, "P856")
end
 
local ret = ""
if #out > 1 then
ret = mw.getCurrentFrame():expandTemplate{title = "ubl", args = out}
else
ret = out[1]
end
 
return ret
end
 
 
-------------------------------------------------------------------------------
-- getAllLabels fetches the set of labels and formats it for display as wikitext.
-- It takes a parameter 'qid' for arbitrary access, otherwise it uses the current page.
-------------------------------------------------------------------------------
-- Dependencies: none
-------------------------------------------------------------------------------
p.getAllLabels = function(frame)
local args = frame.args or frame:getParent().args or {}
 
local qid = args.qid
if qid == "" then qid = nil end
 
local entity = mw.wikibase.getEntity(qid)
if not entity then return i18n["entity-not-found"] end
 
local labels = entity.labels
if not labels then return i18n["labels-not-found"] end
 
local out = {}
for k, v in pairs(labels) do
out[#out+1] = v.value .. " (" .. v.language .. ")"
end
 
return table.concat(out, "; ")
end
 
 
-------------------------------------------------------------------------------
-- getAllDescriptions fetches the set of descriptions and formats it for display as wikitext.
-- It takes a parameter 'qid' for arbitrary access, otherwise it uses the current page.
-------------------------------------------------------------------------------
-- Dependencies: none
-------------------------------------------------------------------------------
p.getAllDescriptions = function(frame)
local args = frame.args or frame:getParent().args or {}
 
local qid = args.qid
if qid == "" then qid = nil end
 
local entity = mw.wikibase.getEntity(qid)
if not entity then return i18n["entity-not-found"] end
 
local descriptions = entity.descriptions
if not descriptions then return i18n["descriptions-not-found"] end
 
local out = {}
for k, v in pairs(descriptions) do
out[#out+1] = v.value .. " (" .. v.language .. ")"
end
 
return table.concat(out, "; ")
end
 
 
-------------------------------------------------------------------------------
-- getAllAliases fetches the set of aliases and formats it for display as wikitext.
-- It takes a parameter 'qid' for arbitrary access, otherwise it uses the current page.
-------------------------------------------------------------------------------
-- Dependencies: none
-------------------------------------------------------------------------------
p.getAllAliases = function(frame)
local args = frame.args or frame:getParent().args or {}
 
local qid = args.qid
if qid == "" then qid = nil end
 
local entity = mw.wikibase.getEntity(qid)
if not entity then return i18n["entity-not-found"] end
 
local aliases = entity.aliases
if not aliases then return i18n["aliases-not-found"] end
 
local out = {}
for k1, v1 in pairs(aliases) do
local lang = v1[1].language
local val = {}
for k1, v2 in ipairs(v1) do
val[#val+1] = v2.value
end
out[#out+1] = table.concat(val, ", ") .. " (" .. lang .. ")"
end
 
return table.concat(out, "; ")
end
 
 
-------------------------------------------------------------------------------
-- showNoLinks displays the article titles that should not be linked.
-------------------------------------------------------------------------------
-- Dependencies: none
-------------------------------------------------------------------------------
p.showNoLinks = function(frame)
local out = {}
for k, v in pairs(donotlink) do
out[#out+1] = k
end
table.sort( out )
return table.concat(out, "; ")
end
 
 
-------------------------------------------------------------------------------
-- checkValidity checks whether the first unnamed parameter represents a valid entity-id,
-- that is, something like Q1235 or P123.
-- It returns the strings "true" or "false".
-- Change false to nil to return "true" or "" (easier to test with #if:).
-------------------------------------------------------------------------------
-- Dependencies: none
-------------------------------------------------------------------------------
function p.checkValidity(frame)
local id = mw.text.trim(frame.args[1] or "")
if mw.wikibase.isValidEntityId(id) then
return true
else
return false
end
end
 
 
-------------------------------------------------------------------------------
-- getEntityFromTitle returns the Entity-ID (Q-number) for a given title.
-- Modification of Module:ResolveEntityId
-- The title is the first unnamed parameter.
-- The site parameter determines the site/language for the title. Defaults to current wiki.
-- The showdab parameter determines whether dab pages should return the Q-number or nil. Defaults to true.
-- Returns the Q-number or nil if it does not exist.
-------------------------------------------------------------------------------
-- Dependencies: parseParam
-------------------------------------------------------------------------------
function p.getEntityFromTitle(frame)
local args=frame.args
if not args[1] then args=frame:getParent().args end
if not args[1] then return nil end
local title = mw.text.trim(args[1])
local site = args.site or ""
local showdab = parseParam(args.showdab, true)
qid = mw.wikibase.getEntityIdForTitle(title, site)
if qid then
local prop31 = mw.wikibase.getBestStatements(qid, "P31")[1]
if not showdab and prop31 and prop31.mainsnak.datavalue.value.id == "Q4167410" then
return nil
else
return qid
end
end
end
 
-------------------------------------------------------------------------------
-- getDatePrecision returns the number representing the precision of the first best date value
-- for the given property.
-- It takes the qid and property ID
-- The meanings are given at https://www.mediawiki.org/wiki/Wikibase/DataModel#Dates_and_times
-- 0 = 1 billion years .. 6 = millennium, 7 = century, 8 = decade, 9 = year, 10 = month, 11 = day
-- Returns 0 (or the second unnamed parameter) if the Wikidata does not exist.
-------------------------------------------------------------------------------
-- Dependencies: parseParam
-------------------------------------------------------------------------------
function p.getDatePrecision(frame)
local args=frame.args
if not args[1] then args=frame:getParent().args end
local default = tonumber(args[2] or args.default) or 0
local prop = mw.text.trim(args[1] or "")
if prop == "" then return default end
local qid = args.qid or ""
if qid == "" then qid = mw.wikibase.getEntityIdForCurrentPage() end
if not qid then return default end
local onlysrc = parseParam(args.onlysourced or args.osd, true)
local stat = mw.wikibase.getBestStatements(qid, prop)
for i, v in ipairs(stat) do
local prec = (onlysrc == false or sourced(v))
and v.mainsnak.datavalue
and v.mainsnak.datavalue.value
and v.mainsnak.datavalue.value.precision
if prec then return prec end
end
end
return default
end
end


Line 2,928: Line 3,365:
-- List of exported functions
-- List of exported functions
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- getValue
--[[
-- getPreferredValue
_getValue
-- getCoords
getValue
-- getQualifierValue
getPreferredValue
-- getSumOfParts
getCoords
-- getValueByQual
getQualifierValue
-- getValueByLang
getSumOfParts
-- getValueByRefSource
getValueByQual
-- getPropOfProp
getValueByLang
-- getAwardCat
getValueByRefSource
-- getIntersectCat
getPropertyIDs
-- getGlobe
getQualifierIDs
-- getCommonsLink
getPropOfProp
-- getSiteLink
getAwardCat
-- getLink
getIntersectCat
-- getLabel
getGlobe
-- getAT
getCommonsLink
-- getDescription
getSiteLink
-- getAliases
getLink
-- pageId
getLabel
-- formatDate
label
-- location
getAT
-- checkBlacklist
getDescription
-- emptyor
getAliases
-- labelorid
pageId
-- getLang
formatDate
-- findLanguage
location
 
checkBlacklist
-- getQID
emptyor
-- followQid
labelorid
-- siteID
getLang
-- projID
getItemLangCode
-- formatNumber
findLanguage
-- examine
getQID
-- checkvalue
followQid
-- url2
globalSiteID
-- getWebsite
siteID
-- getAllLabels
projID
-- getAllDescriptions
formatNumber
-- getAllAliases
examine
-- showNoLinks
checkvalue
-- checkValidity
url2
getWebsite
getAllLabels
getAllDescriptions
getAllAliases
showNoLinks
checkValidity
getEntityFromTitle
getDatePrecision
--]]
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------