Line 80: |
Line 80: |
| } | | } |
| } | | } |
− | -- This allows an internationisation module to override the above table | + | -- This allows a 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 399: |
Line 389: |
| -- 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> ') | | fdate = fdate:gsub('circa ', '<abbr title="circa">c.</abbr> ') |
Line 428: |
Line 412: |
| -- 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 492: |
Line 474: |
| 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 and prop910.mainsnak.datavalue.value.id | + | local tmcid = 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 508: |
Line 482: |
| 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 and prop373.mainsnak.datavalue.value | + | sitelink = prop373.mainsnak.datavalue.value |
| if sitelink then sitelink = "Category:" .. sitelink end | | if sitelink then sitelink = "Category:" .. sitelink end |
| end | | end |
Line 525: |
Line 499: |
| -- Dependencies: none | | -- Dependencies: none |
| ------------------------------------------------------------------------------- | | ------------------------------------------------------------------------------- |
− | local labelOrId = function(id, lang) | + | local labelOrId = function(id) |
− | if lang == "default" then lang = findLang().code end
| + | local label = mw.wikibase.label(id) |
− | local label | |
− | if lang then
| |
− | label = mw.wikibase.getLabelByLang(id, lang)
| |
− | else
| |
− | label = mw.wikibase.label(id)
| |
− | end
| |
| if label then | | if label then |
| return mw.text.nowiki(label), true | | return mw.text.nowiki(label), true |
Line 561: |
Line 529: |
| 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.sitelink(id) |
Line 593: |
Line 553: |
| 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 | + | -- strip any namespace or dab from the sitelink and use that as label |
| local pos = sitelink:find(":") or 0 | | local pos = sitelink:find(":") or 0 |
− | local slink = sitelink | + | label = sitelink:sub(pos+1):gsub("%s%(.+%)$", ""):gsub(",.+$", "") |
− | 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 .. fmt .. label .. fmt .. postfix | + | disp = prefix .. label .. postfix |
| else | | else |
− | disp = "[[" .. lprefix .. sitelink .. lpostfix .. "|" .. prefix .. fmt .. label .. fmt .. postfix .. "]]" | + | disp = "[[" .. lprefix .. sitelink .. lpostfix .. "|" .. prefix .. label .. postfix .. "]]" |
| end | | end |
| elseif islabel then | | elseif islabel then |
Line 621: |
Line 567: |
| if artitle and artitle.redirectTarget and not donotlink[label] then | | if artitle and artitle.redirectTarget and not donotlink[label] 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 .. fmt .. label .. fmt .. postfix .. "]]" | + | disp = "[[".. lprefix .. label .. lpostfix .. "|" .. prefix .. label .. postfix .. "]]" |
| else | | else |
| -- no sitelink, label exists, not redirect (or donotlink) so output plain label | | -- no sitelink, label exists, not redirect (or donotlink) so output plain label |
− | disp = prefix .. fmt .. label .. fmt .. postfix | + | disp = prefix .. label .. 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 |
Line 778: |
Line 724: |
| local createicon = function(langcode, entityID, propertyID) | | local createicon = function(langcode, entityID, propertyID) |
| local icon = " [[" .. i18n["filespace"] | | local icon = " [[" .. i18n["filespace"] |
− | icon = icon .. ":OOjs UI icon edit-ltr-progressive.svg |frameless |text-top |10px |alt=" | + | icon = icon .. ":Blue pencil.svg |frameless |text-top |10px |alt=" |
| icon = icon .. i18n["editonwikidata"] | | icon = icon .. i18n["editonwikidata"] |
| icon = icon .. "|link=https://www.wikidata.org/wiki/" .. entityID | | icon = icon .. "|link=https://www.wikidata.org/wiki/" .. entityID |
Line 927: |
Line 873: |
| -- 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 939: |
Line 882: |
| -- 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 957: |
Line 898: |
| -- 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 1,062: |
Line 1,002: |
| end | | end |
| -- format display: | | -- format display: |
− | if conv then | + | if conv and usym ~= "" then |
| if range == "" then | | if range == "" then |
− | val = mw.getCurrentFrame():expandTemplate{title = "cvt", args = {amount, unit}} | + | val = mw.getCurrentFrame():expandTemplate{title = "cvt", args = {amount, usym}} |
| else | | else |
− | val = mw.getCurrentFrame():expandTemplate{title = "cvt", args = {lowb, "to", upb, unit}} | + | val = mw.getCurrentFrame():expandTemplate{title = "cvt", args = {lowb, "to", upb, usym}} |
| end | | end |
| elseif unit == "$" or unit == "£" then | | elseif unit == "$" or unit == "£" then |
Line 1,083: |
Line 1,023: |
| -- 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 -- not needed for now | + | if form ~= "dec" then form = "dms" end |
| -- | | -- |
− | -- show parameter allows just the latitude, or just the longitude, or both | + | -- show parameter allows just the latitude or longitude to be shown |
− | -- 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,209: |
Line 1,148: |
| 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 |
| -- 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 values for this property |
Line 1,240: |
Line 1,175: |
| -- 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~="novalue" then | + | if hasvalue and v.qualifiers and qualID and snak.snaktype=="value" then |
| local qsep = (args.qsep or ""):gsub('"', '') | | local qsep = (args.qsep or ""):gsub('"', '') |
| local qargs = { | | local qargs = { |
Line 1,252: |
Line 1,187: |
| ["unitabbr"] = tostring(uabbr), | | ["unitabbr"] = tostring(uabbr), |
| ["maxvals"] = 0, | | ["maxvals"] = 0, |
− | ["sorted"] = tostring(args.qsorted), | + | ["sorted"] = args.qsorted, |
| ["noicon"] = "true", | | ["noicon"] = "true", |
| ["list"] = args.qlist, | | ["list"] = args.qlist, |
Line 1,258: |
Line 1,193: |
| ["langobj"] = args.langobj, | | ["langobj"] = args.langobj, |
| ["lang"] = args.langobj.code, | | ["lang"] = args.langobj.code, |
− | ["df"] = args.qdf
| |
| } | | } |
| local qlist = {} | | local qlist = {} |
Line 1,270: |
Line 1,204: |
| local ts = v.qualifiers[v1][1].datavalue.value.time | | local ts = v.qualifiers[v1][1].datavalue.value.time |
| local dp = v.qualifiers[v1][1].datavalue.value.precision | | local dp = v.qualifiers[v1][1].datavalue.value.precision |
− | qlist[#qlist + 1] = dateFormat(ts, dp, args.qdf, args.bc, pd, "", lang, "before") | + | qlist[#qlist + 1] = dateFormat(ts, dp, args.df, args.bc, pd, "", lang, "before") |
| elseif v1 == "P1319" then | | elseif v1 == "P1319" then |
| local ts = v.qualifiers[v1][1].datavalue.value.time | | local ts = v.qualifiers[v1][1].datavalue.value.time |
| local dp = v.qualifiers[v1][1].datavalue.value.precision | | local dp = v.qualifiers[v1][1].datavalue.value.precision |
− | qlist[#qlist + 1] = dateFormat(ts, dp, args.qdf, args.bc, pd, "", lang, "after") | + | qlist[#qlist + 1] = dateFormat(ts, dp, args.df, args.bc, pd, "", lang, "after") |
| else | | else |
| local q = assembleoutput(propertyvalueandquals(v.qualifiers[v1], qargs), qargs) | | local q = assembleoutput(propertyvalueandquals(v.qualifiers[v1], qargs), qargs) |
| -- we already deal with circa via 'sourcing circumstances' | | -- we already deal with circa via 'sourcing circumstances' |
| -- either linked or unlinked *** internationalise later *** | | -- either linked or unlinked *** internationalise later *** |
− | if q ~= "circa" and not (type(q) == "string" and q:find("circa]]")) then | + | if q ~= "circa" and not q:find("circa]]") then |
| qlist[#qlist + 1] = q | | qlist[#qlist + 1] = q |
| end | | end |
Line 1,290: |
Line 1,224: |
| -- we already deal with circa via 'sourcing circumstances' | | -- we already deal with circa via 'sourcing circumstances' |
| -- either linked or unlinked *** internationalise later *** | | -- either linked or unlinked *** internationalise later *** |
− | if v1 ~= "circa" and not (type(v1) == "string" and v1:find("circa]]")) then | + | if v1 ~= "circa" and not v1:find("circa]]") then |
| qlist[#qlist + 1] = v1 | | qlist[#qlist + 1] = v1 |
| end | | end |
Line 1,315: |
Line 1,249: |
| local ts = v1[1].datavalue.value.time | | local ts = v1[1].datavalue.value.time |
| local dp = v1[1].datavalue.value.precision | | local dp = v1[1].datavalue.value.precision |
− | qlist[#qlist + 1] = dateFormat(ts, dp, args.qdf, args.bc, pd, "", lang, "before") | + | qlist[#qlist + 1] = dateFormat(ts, dp, args.df, args.bc, pd, "", lang, "before") |
| end | | end |
| end | | end |
Line 1,439: |
Line 1,373: |
| -- 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 and strings for now | + | -- We'll only deal with wikibase-items 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,481: |
Line 1,411: |
| local finished = false | | local finished = false |
| local count = 0 | | local count = 0 |
− | local prevqid = "Q0" | + | local prevqid = "" |
| repeat | | repeat |
| local prop | | local prop |
Line 1,487: |
Line 1,417: |
| 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 higher location | + | -- there is more than one parent 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 higher location has qualifier 'applies to part' (P518) | + | -- this parent 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,506: |
Line 1,429: |
| 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,660: |
Line 1,576: |
| ------------------------------------------------------------------------------- | | ------------------------------------------------------------------------------- |
| ------------------------------------------------------------------------------- | | ------------------------------------------------------------------------------- |
− | -- _getValue makes the functionality of getValue available to other modules | + | -- 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: 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(args) | + | p.getValue = function(frame) |
| + | 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(args.ps or args.parameterset or 0) | + | local paraset = tonumber(frame.args.ps or frame.args.parameterset or 0) |
| if paraset == 1 then | | if paraset == 1 then |
− | -- a common setting | + | frame.args.rank = "best" |
− | args.rank = "best"
| + | frame.args.fetchwikidata = "ALL" |
− | args.fetchwikidata = "ALL" | + | frame.args.onlysourced = "no" |
− | args.onlysourced = "no" | + | frame.args.noicon = "true" |
− | args.noicon = "true" | |
| elseif paraset == 2 then | | elseif paraset == 2 then |
− | -- equivalent to raw | + | -- second set goes here |
− | 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 |
| | | |
− | -- implement eid parameter
| + | local propertyID = mw.text.trim(frame.args[1] or "") |
− | local eid = args.eid | |
− | if eid == "" then
| |
− | return nil
| |
− | elseif eid then
| |
− | args.qid = eid
| |
− | end
| |
| | | |
− | local propertyID = mw.text.trim(args[1] or "") | + | frame.args.reqranks = setRanks(frame.args.rank) |
| | | |
− | args.reqranks = setRanks(args.rank)
| + | local entityid, props = parseInput(frame, frame.args[2], propertyID) |
− | | |
− | 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(args.qual or ""):upper() | + | local qualID = mw.text.trim(frame.args.qual or ""):upper() |
| if qualID == "" then qualID = nil end | | if qualID == "" then qualID = nil end |
| | | |
− | -- set a language object and code in the args table | + | -- set a language object and code in the frame.args table |
− | args.langobj = findLang(args.lang) | + | frame.args.langobj = findLang(frame.args.lang) |
− | args.lang = args.langobj.code | + | frame.args.lang = frame.args.langobj.code |
| | | |
| -- table 'out' stores the return value(s): | | -- table 'out' stores the return value(s): |
− | local out = propertyvalueandquals(props, args, qualID) | + | local out = propertyvalueandquals(props, frame.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, args, entityid, propertyID) | + | return assembleoutput(out, frame.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,907: |
Line 1,791: |
| -- 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) |
− | -- either the Wikibase-entity ID of a value for that qualifier (qvalue=Qzzz) | + | -- 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,938: |
Line 1,821: |
| ------------------------------------------------------------------------------- | | ------------------------------------------------------------------------------- |
| 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 = findLang(frame.args.lang).code | + | local langcode = frame.args.lang or "" |
| + | 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,955: |
Line 1,842: |
| ------------------------------------------------------------------------------- | | ------------------------------------------------------------------------------- |
| -- 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-ID. | + | -- whose value has the given entity code. |
| -- 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 2,047: |
Line 1,934: |
| | | |
| ------------------------------------------------------------------------------- | | ------------------------------------------------------------------------------- |
− | -- getPropertyIDs takes most of the usual parameters. | + | -- getPropOfProp takes two propertyIDs: prop1 and prop2 (as well as the usual parameters) |
− | -- The usual whitelisting, blacklisting, onlysourced, etc. are implemented. | + | -- If the value(s) of prop1 are of type "wikibase-item" then it returns the value(s) of prop2 |
− | -- It returns the Entity-IDs (Qids) of the values of a property if it is a Wikibase-Entity. | + | -- of each of those wikibase-items. |
− | -- Otherwise it returns nothing. | + | -- The usual whitelisting, blacklisting, onlysourced, etc. are implemented |
| ------------------------------------------------------------------------------- | | ------------------------------------------------------------------------------- |
| -- Dependencies: parseParam; setRanks; parseInput; sourced; propertyvalueandquals assembleoutput; | | -- Dependencies: parseParam; setRanks; parseInput; sourced; propertyvalueandquals assembleoutput; |
| ------------------------------------------------------------------------------- | | ------------------------------------------------------------------------------- |
− | p.getPropertyIDs = function(frame)
| + | p.getPropOfProp = function(frame) |
− | local args = frame.args
| + | frame.args.reqranks = setRanks(frame.args.rank) |
− | args.reqranks = setRanks(args.rank)
| |
− | args.langobj = findLang(args.lang)
| |
− | 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 "")
| |
− | | |
− | -- 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 maxvals = tonumber(args.maxvals) or 0
| |
− | | |
− | out = {}
| |
− | for i, v in ipairs(props) do
| |
− | local snak = v.mainsnak
| |
− | if ( snak.datatype == "wikibase-item" )
| |
− | and ( v.rank and args.reqranks[v.rank:sub(1, 1)] )
| |
− | and ( snak.snaktype == "value" )
| |
− | and ( sourced(v) or not onlysrc )
| |
− | then
| |
− | out[#out+1] = snak.datavalue.value.id
| |
− | end
| |
− | if maxvals > 0 and #out >= maxvals then break end
| |
− | end
| |
− | | |
− | 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.langobj = findLang(frame.args.lang) |
| frame.args.lang = frame.args.langobj.code | | frame.args.lang = frame.args.langobj.code |
Line 2,331: |
Line 2,175: |
| | | |
| ------------------------------------------------------------------------------- | | ------------------------------------------------------------------------------- |
− | -- qualsToTable takes most of the usual parameters. | + | -- getGlobe takes an optional qid of a Wikidata entity passed as |qid= |
− | -- The usual whitelisting, blacklisting, onlysourced, etc. are implemented.
| + | -- otherwise it uses the linked item for the current page. |
− | -- A qid may be given, and the first unnamed parameter is the property ID, which is of type wikibase item.
| + | -- If returns the Qid of the globe used in P625 (coordinate location), |
− | -- It takes a list of qualifier property IDs as |quals=
| + | -- or nil if there isn't one. |
− | -- 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 | |
| ------------------------------------------------------------------------------- | | ------------------------------------------------------------------------------- |
− | -- Dependencies: parseParam; setRanks; parseInput; sourced; | + | -- Dependencies: none |
| ------------------------------------------------------------------------------- | | ------------------------------------------------------------------------------- |
− | p.qualsToTable = function(frame)
| + | p.getGlobe = function(frame) |
− | local args = frame.args
| + | local qid = frame.args.qid or frame.args[1] or "" |
− | | |
− | 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
| |
− | for i, v in ipairs(qplist) do
| |
− | qplist[i] = mw.text.trim(v):upper() -- remove whitespace and capitalise
| |
− | end
| |
− | | |
− | local col1 = args.firstcol or ""
| |
− | if col1 ~= "" then
| |
− | col1 = col1 .. "</td><td>"
| |
− | end
| |
− | | |
− | local emptycell = args.emptycell or " "
| |
− | | |
− | -- construct a 2-D array of qualifier values in qvals
| |
− | 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 out = {}
| |
− | 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
| |
− | | |
− | | |
− | -------------------------------------------------------------------------------
| |
− | -- getGlobe takes an optional qid of a Wikidata entity passed as |qid=
| |
− | -- otherwise it uses the linked item for the current page.
| |
− | -- If returns the Qid of the globe used in P625 (coordinate location),
| |
− | -- or nil if there isn't one.
| |
− | -------------------------------------------------------------------------------
| |
− | -- Dependencies: none
| |
− | -------------------------------------------------------------------------------
| |
− | p.getGlobe = function(frame) | |
− | local qid = frame.args.qid or frame.args[1] or "" | |
| if qid == "" then qid = mw.wikibase.getEntityIdForCurrentPage() end | | if qid == "" then qid = mw.wikibase.getEntityIdForCurrentPage() end |
| local coords = mw.wikibase.getBestStatements(qid, "P625")[1] | | local coords = mw.wikibase.getBestStatements(qid, "P625")[1] |
Line 2,503: |
Line 2,255: |
| local itemID = mw.text.trim(frame.args[1] or frame.args.qid or "") | | local itemID = mw.text.trim(frame.args[1] or frame.args.qid or "") |
| if itemID == "" then return end | | if itemID == "" then return end |
− | local lang = frame.args.lang or ""
| + | local label = labelOrId(itemID) |
− | if lang == "" then lang = nil end
| |
− | local label = labelOrId(itemID, lang) | |
| return label | | return label |
| end | | end |
Line 2,762: |
Line 2,512: |
| -- getQid returns the qid, if supplied | | -- getQid returns the qid, if supplied |
| -- failing that, the Wikidata entity ID of the "category's main topic (P301)", if it exists | | -- failing that, the Wikidata entity ID of the "category's main topic (P301)", if it exists |
− | -- failing that, the Wikidata entity ID associated with the current page, if it exists | + | -- failing that, the Wikidata entity ID asociated with the curent page, if it exists |
| -- otherwise, nothing | | -- otherwise, nothing |
| ------------------------------------------------------------------------------- | | ------------------------------------------------------------------------------- |
Line 2,786: |
Line 2,536: |
| | | |
| ------------------------------------------------------------------------------- | | ------------------------------------------------------------------------------- |
− | -- followQid takes three optional parameters: qid, props, and all. | + | -- followQid takes two optional parameters: qid and props |
| -- If qid is not given, it uses the qid for the connected page | | -- If qid is not given, it uses the qid for the connected page |
| -- or returns nil if there isn't one. | | -- or returns nil if there isn't one. |
Line 2,826: |
Line 2,576: |
| return qid | | return qid |
| end | | end |
− | end
| |
− |
| |
− |
| |
− | -------------------------------------------------------------------------------
| |
− | -- globalSiteID returns the globalSiteID for the current wiki
| |
− | -- e.g. returns "enwiki" for the English Wikipedia, "enwikisource" for English Wikisource, etc.
| |
− | -------------------------------------------------------------------------------
| |
− | -- Dependencies: none
| |
− | -------------------------------------------------------------------------------
| |
− | p.globalSiteID = function(frame)
| |
− | return mw.wikibase.getGlobalSiteId()
| |
| end | | end |
| | | |
Line 3,179: |
Line 2,918: |
| else | | else |
| return false | | 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 |
| end | | end |
Line 3,218: |
Line 2,928: |
| -- List of exported functions | | -- List of exported functions |
| ------------------------------------------------------------------------------- | | ------------------------------------------------------------------------------- |
− | --[[ | + | -- getValue |
− | _getValue
| + | -- getPreferredValue |
− | getValue | + | -- getCoords |
− | getPreferredValue | + | -- getQualifierValue |
− | getCoords | + | -- getSumOfParts |
− | getQualifierValue | + | -- getValueByQual |
− | getSumOfParts | + | -- getValueByLang |
− | getValueByQual | + | -- getValueByRefSource |
− | getValueByLang | + | -- getPropOfProp |
− | getValueByRefSource | + | -- getAwardCat |
− | getPropertyIDs
| + | -- getIntersectCat |
− | getPropOfProp | + | -- getGlobe |
− | getAwardCat | + | -- getCommonsLink |
− | getIntersectCat | + | -- getSiteLink |
− | getGlobe | + | -- getLink |
− | getCommonsLink | + | -- getLabel |
− | getSiteLink | + | -- getAT |
− | getLink | + | -- getDescription |
− | getLabel | + | -- getAliases |
− | getAT | + | -- pageId |
− | getDescription | + | -- formatDate |
− | getAliases | + | -- location |
− | pageId | + | -- checkBlacklist |
− | formatDate | + | -- emptyor |
− | location | + | -- labelorid |
− | checkBlacklist | + | -- getLang |
− | emptyor | + | -- findLanguage |
− | labelorid | + | |
− | getLang | + | -- getQID |
− | getItemLangCode
| + | -- followQid |
− | findLanguage
| + | -- siteID |
− | getQID | + | -- projID |
− | followQid | + | -- formatNumber |
− | globalSiteID
| + | -- examine |
− | siteID | + | -- checkvalue |
− | projID | + | -- url2 |
− | formatNumber | + | -- getWebsite |
− | examine | + | -- getAllLabels |
− | checkvalue | + | -- getAllDescriptions |
− | url2 | + | -- getAllAliases |
− | getWebsite | + | -- showNoLinks |
− | getAllLabels | + | -- checkValidity |
− | getAllDescriptions | |
− | getAllAliases | |
− | showNoLinks | |
− | checkValidity
| |
− | getEntityFromTitle
| |
− | --]] | |
| ------------------------------------------------------------------------------- | | ------------------------------------------------------------------------------- |