মডিউল:WikidataIB: সংশোধিত সংস্করণের মধ্যে পার্থক্য

বিষয়বস্তু বিয়োগ হয়েছে বিষয়বস্তু যোগ হয়েছে
সম্পাদনা সারাংশ নেই
ট্যাগ: পুনর্বহালকৃত
Mahir256 (আলোচনা | অবদান)
এটা কি আগে হত?
ট্যাগ: হাতদ্বারা প্রত্যাবর্তন পুনর্বহালকৃত
১ নং লাইন:
-- Version: 2021-02-06
-- Module to implement use of a blacklist and whitelist for infobox fields
-- Can take a named parameter |qid which is the Wikidata ID for the article
১৪ ⟶ ১৩ নং লাইন:
 
local cdate -- initialise as nil and only load _complex_date function if needed
-- [[Module:Complex date]] is loaded lazily and has the following dependencies:
-- Module:I18n/complex date, Module:ISOdate, Module:DateI18n (alternative for Module:Date),
-- Module:Calendar
-- Module:Formatnum, Module:I18n/date, Module:Yesno, Module:Linguistic, Module:Calendar
-- Module:ISOdate
-- Module:DateI18n
-- Module:No globals
-- Module:I18n/complex date
-- Module:Ordinal
-- Module:I18n/ordinal
-- Module:Yesno
-- Module:Formatnum
-- Module:Linguistic
--
-- The following, taken from https://www.mediawiki.org/wiki/Wikibase/DataModel#Dates_and_times,
-- is needed to use Module:Complex date which seemingly requires date precision as a string.
৭২ ⟶ ৬২ নং লাইন:
},
["filespace"] = "File",
["Unknown"] = "Unknownঅজানা",
["NaN"] = "Not a number",
-- set the following to the name of a tracking category,
৫৭৪ ⟶ ৫৬৪ নং লাইন:
-- shortname is boolean switch to use P1813 (short name) instead of label if true.
-- lang is the current language code.
-- uselbl is boolean switch to force display of the label instead of the sitelink (default: false)
-- linkredir is boolean switch to allow linking to a redirect (default: false)
-- formatvalue is boolean switch to allow formatting as italics or quoted (default: false)
-------------------------------------------------------------------------------
-- Dependencies: labelOrId(); donotlink[]
-------------------------------------------------------------------------------
local linkedItem = function(id, argslprefix, lpostfix, prefix, postfix, dtxt, shortname, lang)
local lprefix = (args.lp or args.lprefix or args.linkprefix or ""):gsub('"', '') -- toughen against nil values passed
local lpostfix = (args.lpostfix or ""):gsub('"', '')
local prefix = (args.prefix or ""):gsub('"', '')
local postfix = (args.postfix or ""):gsub('"', '')
lang = lang or "en" -- fallback to default if missing
local dtxt = args.dtxt
local shortname = args.shortname
local lang = args.lang or "en" -- fallback to default if missing
local uselbl = args.uselabel or args.uselbl
uselbl = parseParam(uselbl, false)
local linkredir = args.linkredir
linkredir = parseParam(linkredir, false)
local formatvalue = args.formatvalue or args.fv
formatvalue = parseParam(formatvalue, false)
-- see if item might need italics or quotes
local fmt = ""
for k, v in ipairs( mw.wikibase.getBestStatements(id, "P31") ) do
if next(formats) and formatvalue then
if v.mainsnak.datavalue and formats[v.mainsnak.datavalue.value.id] then
for k, v in ipairs( mw.wikibase.getBestStatements(id, "P31") ) do
iffmt v.mainsnak.datavalue and= formats[v.mainsnak.datavalue.value.id] then
break -- pick the first match
fmt = formats[v.mainsnak.datavalue.value.id]
break -- pick the first match
end
end
end
৬২৮ ⟶ ৬০৫ নং লাইন:
if sitelink then
if not (dtxt or shortname) then
-- strip any namespace or dab from the sitelink
-- if sitelink and label are the same except for case, no need to process further
iflocal sitelink:lower()pos ~= labelsitelink:lowerfind(":") thenor 0
--local stripslink any namespace or dab from the= sitelink
localif pos => sitelink:find(":")0 or 0then
local slinkprefix = sitelink:sub(1,pos-1)
if mw.site.namespaces[prefix] then -- that prefix is a valid namespace, so remove it
if pos > 0 then
local pfxslink = sitelink:sub(1,pos-+1)
if mw.site.namespaces[pfx] 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(",.+$", "")
-- if uselbl is false, use sitelink instead of label
if not uselbl then
-- use slink as display, 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
-- 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
elseif islabel then
-- no sitelink, label exists, so check if a redirect with that title exists, if linkredir is true
local artitle = mw.title.new(label, 0) -- only nil if label has invalid chars
-- display plain label by default
if not donotlink[label] and artitle and artitle.redirectTarget then
disp = prefix .. fmt .. label .. fmt .. postfix
-- there's a redirect with the same title as the label, so let's link to that
if linkredir then
local artitledisp = mw"[[".title.new( lprefix .. label, 0).. --lpostfix only.. nil"|" if.. prefix .. fmt .. label has.. invalidfmt .. postfix .. chars"]]"
else
if not donotlink[label] and artitle and artitle.redirectTarget then
-- either (donotlink is true) or (no sitelink, label exists, not redirect)
-- there's a redirect with the same title as the label, so let's link to that
-- so output unlinked label with italics or quotes as needed
disp = "[[".. lprefix .. label .. lpostfix .. "|" .. prefix .. fmt .. label .. fmt .. postfix .. "]]"
disp = prefix .. fmt .. label .. fmt .. postfix
end
end -- test if article title exists as redirect on current Wiki
else
-- no sitelink and no label, so return whatever was returned from labelOrId for now
-- 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
else
৬৯৭ ⟶ ৬৬৩ নং লাইন:
-------------------------------------------------------------------------------
-- sourced takes a table representing a statement that may or may not have references
-- it lookscounts forhow amany referencereferences are sourced to something not containing the word "wikipedia"
-- it returns a boolean = true if itthere findsare aany sourced referencereferences.
-------------------------------------------------------------------------------
-- Dependencies: none
৭০৬ ⟶ ৬৭২ নং লাইন:
for kr, vr in pairs(claim.references) do
local ref = mw.wikibase.renderSnaks(vr.snaks)
if not ref:find("WikiWikipedia") then
return true
end
৭৭২ ⟶ ৭৩৮ নং লাইন:
 
-- The blacklist is passed in named parameter |suppressfields
local blacklist = args.suppressfields or args.spf or ""
 
-- The whitelist is passed in named parameter |fetchwikidata
local whitelist = args.fetchwikidata or args.fwd or ""
if not whitelist or whitelist == "" then whitelist = "NONE" end
 
-- The name of the field that this function is called from is passed in named parameter |name
local fieldname = args.name or ""
 
if blacklist ~= "" then
-- 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 this field is on the blacklist, then return nil
if blacklist:find(fieldname) then return false, nil end
৮২৩ ⟶ ৭৮৯ নং লাইন:
-- createicon assembles the "Edit at Wikidata" pen icon.
-- It returns a wikitext string inside a span class="penicon"
-- if entityID is nil or empty, the ID associated with current page is used
-- langcode and propertyID may be nil or empty
-------------------------------------------------------------------------------
-- Dependencies: i18n[];
-------------------------------------------------------------------------------
local createicon = function(langcode, entityID, propertyID)
local icon = "&nbsp;<span class='penicon'>[["
langcode = langcode or ""
if not entityID or entityID == "" then entityID= mw.wikibase.getEntityIdForCurrentPage() end
propertyID = propertyID or ""
local icon = "&nbsp;<span class='penicon autoconfirmed-show'>[["
-- "&nbsp;<span data-bridge-edit-flow='overwrite' class='penicon'>[[" -> enable Wikidata Bridge
.. i18n["filespace"]
৮৩৮ ⟶ ৭৯৯ নং লাইন:
.. i18n["editonwikidata"]
.. "|link=https://www.wikidata.org/wiki/" .. entityID
if langcode ~= "" then icon = icon .. "?uselang=" .. langcode end
if propertyID ~= "" then icon = icon .. "#" .. propertyID end
icon = icon .. "|" .. i18n["editonwikidata"] .. "]]</span>"
return icon
৮৪৮ ⟶ ৮০৯ নং লাইন:
-- assembleoutput takes the sequence table containing the property values
-- and formats it according to switches given. It returns a string or nil.
-- It usesneeds the entityID (and optionally propertyID) to create a link in the pen icon.
-------------------------------------------------------------------------------
-- Dependencies: parseParam();
৮৯৬ ⟶ ৮৫৭ নং লাইন:
if #out > 0 then
if sorted then table.sort(out) end
-- 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)
end
৯৭২ ⟶ ৯২৬ নং লাইন:
local qnumber = dv.id
if linked then
val = linkedItem(qnumber, lpre, lpost, pre, post, dtxt, shortname, args.lang)
else -- no link wanted so check for display-text, otherwise test for lang code
local label, islabel
১,২৮০ ⟶ ১,২৩৪ নং লাইন:
args.pd = pd
 
-- allow qualifiers to have a different date format; default to year unless qualsonly is set
args.qdf = args.qdf or args.qualifierdateformat or args.df or (not qualsonly and "y")
 
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),
}
 
local lang = args.lang or findlang().code
-- all proper values of a Wikidata property will be the same type as the first
-- qualifiers don't have a mainsnak, properties do
 
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
local out = {}
local mlt = {}
 
for k, v in ipairs(objproperty) do
local hasvalue = true
১,৩৫১ ⟶ ১,২৬৪ নং লাইন:
-- See if qualifiers are to be returned:
local snak = v.mainsnak or v
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"] = 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),
}
local qlist = {}
local timestartt1, timeendt2 = "", ""
-- see if we want -- loop throughall 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.qdf, 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.qdf, args.bc, pd, "", lang, "after")
timestart = propertyvalueandquals(v1, qargs)[1] or "" -- treat only one start time as valid
else
elseif k1 == "P582" then
local timeendq = assembleoutput(propertyvalueandquals(v.qualifiers[v1], qargs)[1], or "" -- treat only one end time as validqargs)
-- we already deal with circa via 'sourcing circumstances' if the datatype was time
else
-- circa may be either linked or unlinked *** internationalise later ***
local q = assembleoutput(propertyvalueandquals(v1, qargs), qargs)
if datatype ~= "time" or q ~= "circa" and not (type(q) == "string" and 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' if the datatype was time
local t = timestart .. timeend
-- circa may be either linked or unlinked *** internationalise later ***
if datatype ~= "time" or v1 ~= "circa" and not (type(v1) == "string" and 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.qdf, 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 ***
local dsep = "&ndash;"
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
if local nextqstr = assembleoutput(qlist), thenqargs)
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
out[#out+1] = qstr
১,৪০৬ ⟶ ১,৩৬৬ নং লাইন:
out[#out] = out[#out] .. " (" .. qstr .. ")"
end
elseif t ~=> "" then
if qualsonly then
if timestartout[#out+1] == ""t1 .. dsep .. thent2
out[#out+1] = timeend
elseif timeend == "" then
out[#out+1] = timestart
else
out[#out+1] = timestart .. dsep .. timeend
end
else
out[#out] = out[#out] .. " (" .. timestartt1 .. dsep .. timeendt2 .. ")"
end
end
১,৪৯৪ ⟶ ১,৪৪৮ নং লাইন:
local uabbr = parseParam(args.unitabbr or args.uabbr, false)
local filter = (args.unit or ""):upper()
local maxvals = tonumber(args.maxvals) or 0
if filter == "" then filter = nil end
 
১,৫২৬ ⟶ ১,৪৭৯ নং লাইন:
return nil
end -- of check for string
if maxvals > 0 and #out >= maxvals then break end
end -- of loop through values of propertyID
return assembleoutput(out, frame.args, qid, propertyID)
১,৫৬৯ ⟶ ১,৫২১ নং লাইন:
end
for i2, v2 in ipairs(proptbl) do
local parttbl = v2.qualifiers and v2.qualifiers.P518
if parttbl then
-- this higher location has qualifier 'applies to part' (P518)
১,৫৯৬ ⟶ ১,৫৪৮ নং লাইন:
end
 
-- check if it's an instance of (P31) a country (Q6256) orand sovereignterminate statethe (Q3624078)chain if it is
-- and terminate the chain if it is
local inst = mw.wikibase.getAllStatements(qid, "P31")
if #inst > 0 then
for k, v in ipairs(inst) do
local instid = v.mainsnak.datavalue and v.mainsnak.datavalue.value.id
-- stop if it's a country (or a country within the United Kingdom if skip is true)
if instid == "Q6256" or instid == "Q3624078" or (skip and instid == "Q3336843") then
prop = nil -- this will ensure this is treated as top-level location
break
১,৬১৩ ⟶ ১,৫৬৪ নং লাইন:
if prop and prop.mainsnak.datavalue then
if not skip or count == 0 then
out[#out+1] = linkedItem(qid, ":", "", "", "") -- get a linked value if we can
local args = { lprefix = ":" }
out[#out+1] = linkedItem(qid, args) -- get a linked value if we can
end
qid, prevqid = prop.mainsnak.datavalue.value.id, qid
১,৮৪৬ ⟶ ১,৭৯৬ নং লাইন:
-- getCoords is used to get coordinates for display in an infobox
-- whitelist and blacklist are implemented
-- optional 'display' parameter is allowed, defaults to nil - was "inline, title"
-------------------------------------------------------------------------------
-- Dependencies: setRanks(); parseInput(); decimalPrecision();
১,৮৫৪ ⟶ ১,৮০৪ নং লাইন:
 
-- if there is a 'display' parameter supplied, use it
-- otherwise default to nothing"inline, title"
local disp = frame.args.display or ""
if disp == "" then
disp = nil -- default to not supplying display parameter, was "inline, title"
end
 
১,৯১৫ ⟶ ১,৮৬৫ নং লাইন:
-- whose value is to be returned is passed in named parameter |qual=
local qualifierID = frame.args.qual
 
-- A filter can be set like this: filter=P642==Q22674854
local filter, fprop, fval
local ftable = mw.text.split(frame.args.filter or "", "==")
if ftable[2] then
fprop = mw.text.trim(ftable[1])
fval = mw.text.trim(ftable[2])
filter = true
end
 
-- onlysourced is a boolean passed to return qualifiers
১,৯৪৯ ⟶ ১,৮৯০ নং লাইন:
for k1, v1 in pairs(props) do
if v1.mainsnak.snaktype == "value" and v1.mainsnak.datavalue.type == "wikibase-entityid" then
-- It's a wiki-linked value, so check if it's the target (in propvalue)
-- and if it has qualifiers
if v1.mainsnak.datavalue.value.id == propvalue and v1.qualifiers then
if onlysrc == false or sourced(v1) then
-- if we've got this far, we have a (sourced) claim with qualifiers
-- which matches the target, so apply the filter and find the value(s) of the qualifier we want
iflocal notquals filter= or (v1.qualifiers[fpropqualifierID] and v1.qualifiers[fprop][1].datavalue.value.id == fval) then
localif quals = v1.qualifiers[qualifierID]then
-- can't reference qualifer, so set onlysourced = "no" (not boolean)
if quals then
local qargs = frame.args
-- can't reference qualifer, so set onlysourced = "no" (args are strings, not boolean)
local qargs.onlysourced = frame.args"no"
local vals = propertyvalueandquals(quals, qargs, qid)
qargs.onlysourced = "no"
for k, v in ipairs(vals) do
local vals = propertyvalueandquals(quals, qargs, qid)
forout[#out k,+ v1] in= ipairs(vals) dov
out[#out + 1] = v
end
end
end
২,১৪৬ ⟶ ২,০৮৬ নং লাইন:
-- Dependencies: parseParam; setRanks; parseInput; sourced; propertyvalueandquals assembleoutput;
-------------------------------------------------------------------------------
p._getPropertyIDsgetPropertyIDs = function(argsframe)
local args = frame.args
args.reqranks = setRanks(args.rank)
args.langobj = findLang(args.lang)
২,১৫৪ ⟶ ২,০৯৫ নং লাইন:
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 maxvals = tonumber(args.maxvals) or 0
 
local out = {}
for i, v in ipairs(props) do
local snak = v.mainsnak
২,১৭৫ ⟶ ২,১১৬ নং লাইন:
if maxvals > 0 and #out >= maxvals then break end
end
 
return assembleoutput(out, args, qid, pid)
end
 
p.getPropertyIDs = function(frame)
local args = frame.args
return p._getPropertyIDs(args)
end
 
 
-------------------------------------------------------------------------------
-- getQualifierIDs takes most of the usual parameters.
-- The usual whitelisting, blacklisting, onlysourced, etc. are implemented.
-- It takes a property-id as the first unnamed parameter, and an optional parameter qlist
-- which is a list of qualifier property-ids to search for (default is "ALL")
-- It returns the Entity-IDs (Qids) of the values of a property if it is a Wikibase-Entity.
-- Otherwise it returns nothing.
-------------------------------------------------------------------------------
-- Dependencies: parseParam; setRanks; parseInput; sourced; propertyvalueandquals assembleoutput;
-------------------------------------------------------------------------------
p.getQualifierIDs = function(frame)
local args = frame.args
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 ""):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]+", " ") .. " "
 
local 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)
২,২৫১ ⟶ ২,১২৯ নং লাইন:
-- Dependencies: parseParam; setRanks; parseInput; sourced; propertyvalueandquals assembleoutput;
-------------------------------------------------------------------------------
p._getPropOfPropgetPropOfProp = function(argsframe)
frame.args.reqranks = setRanks(frame.args.rank)
-- parameter sets for commonly used groups of parameters
frame.args.langobj = findLang(frame.args.lang)
local paraset = tonumber(args.ps or args.parameterset or 0)
frame.args.lang = frame.args.langobj.code
if paraset == 1 then
local args = frame.args
-- a common setting
args.rank = "best"
args.fetchwikidata = "ALL"
args.onlysourced = "no"
args.noicon = "true"
elseif paraset == 2 then
-- 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
 
args.reqranks = setRanks(args.rank)
args.langobj = findLang(args.lang)
args.lang = args.langobj.code
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
local qid1, statements1 = parseInput(frame, localval, pid1)
 
if not qid1 then return localval end
local f = {}
f.args = args
local qid1, statements1 = parseInput(f, args[1], pid1)
-- parseInput nulls empty args[1] and returns args[1] if nothing on Wikidata
if not qid1 then return statements1 end
-- otherwise it returns the qid and a table for the statement
local onlysrc = parseParam(args.onlysourced or args.osd, true)
local maxvals = tonumber(args.maxvals) or 0
২,৩১০ ⟶ ২,১৬৫ নং লাইন:
end -- of loop through values of property1
return assembleoutput(out, args, qid1, pid1)
end
 
p.getPropOfProp = function(frame)
local args= frame.args
if not args.prop1 and not args.pid1 then
args = frame:getParent().args
if not args.prop1 and not args.pid1 then return i18n.errors["No property supplied"] end
end
 
return p._getPropOfProp(args)
end
 
২,৫০০ ⟶ ২,৩৪৫ নং লাইন:
if maxvals > 0 and #cat2 >= maxvals then break end
end
local out = {}
for k1, v1 in ipairs(cat1) do
for k2, v2 in ipairs(cat2) do
২,৫৮৪ ⟶ ২,৪২৯ নং লাইন:
end
elseif qtype == "url" then
ifqv = mw.wikibase.renderSnak(vqualifiers[v1][1].snaktype == "value" then)
local display = mw.ustring.match( mw.uri.decode(qv, "WIKI"), "([%w ]+)$" )
qv = mw.wikibase.renderSnak(vqualifiers[v1][1])
if display then
local display = mw.ustring.match( mw.uri.decode(qv, "WIKI"), "([%w ]+)$" )
ifqv = "[" .. qv .. " " .. display then.. "]"
qv = "[" .. qv .. " " .. display .. "]"
end
end
else
২,৭২২ ⟶ ২,৫৬৫ নং লাইন:
-- 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
২,৭৮৪ ⟶ ২,৬২৭ নং লাইন:
if not (whitelist == 'ALL' or whitelist:find(fieldname)) then return nil end
 
local qid = mw.text.trim(args.qid or "")
if qid == "" then qid = mw.wikibase.getEntityIdForCurrentPage()nil end
if not qid or not mw.wikibase.entityExists(qid) then return nil end
 
local aliasesentity = mw.wikibase.getEntity(qid).aliases
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)
২,৯৯২ ⟶ ২,৮৩৭ নং লাইন:
 
-------------------------------------------------------------------------------
-- followQid takes fourthree optional parameters: qid, props, list and all.
-- If qid is not given, it uses the qid for the connected page
-- or returns nil if there isn't one.
২,৯৯৮ ⟶ ২,৮৪৩ নং লাইন:
-- 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, separatedsparated by spaces.
-- If |list= is set to a template, the qids are passed as arguments to the template.
-- If props is not given, the qid is returned.
-------------------------------------------------------------------------------
-- Dependencies: parseParam()
-------------------------------------------------------------------------------
p._followQidfollowQid = function(argsframe)
local qid = (frame.args.qid or ""):upper()
local all = parseParam(frame.args.all, false)
local list = args.list or ""
if list == "" then list = nil end
if qid == "" then
qid = mw.wikibase.getEntityIdForCurrentPage()
৩,০১৪ ⟶ ২,৮৫৬ নং লাইন:
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
৩,০৩১ ⟶ ২,৮৭৩ নং লাইন:
end
if #out > 0 then
return table.concat(out, " ")
local ret = ""
if list then
ret = mw.getCurrentFrame():expandTemplate{title = list, args = out}
else
ret = table.concat(out, " ")
end
return ret
else
return qid
end
end
 
p.followQid = function(frame)
return p._followQid(frame.args)
end
 
৩,০৬৭ ⟶ ২,৮৯৯ নং লাইন:
-------------------------------------------------------------------------------
p.siteID = function(frame)
--[[ local txtlang = frame:preprocess( "{{int:lang}}" ) or ""
-- This deals with specific exceptions: be-tarask -> be-x-old
if txtlang == "be-tarask" then
৩,০৭৯ ⟶ ২,৯১১ নং লাইন:
ret = txtlang
end
return ret]]
return "bn"
end
 
৩,০৯১ ⟶ ২,৯২৪ নং লাইন:
-------------------------------------------------------------------------------
p.projID = function(frame)
--[[ local txtlang = frame:preprocess( "{{int:lang}}" ) or ""
-- This deals with specific exceptions: be-tarask -> be-x-old
if txtlang == "be-tarask" then
৩,১০৩ ⟶ ২,৯৩৬ নং লাইন:
ret = txtlang
end
return ret]]
return "bn"
end
 
৩,১৬০ ⟶ ২,৯৯৪ নং লাইন:
-- from the item given by the parameter 'qid'
-- or from the Wikidata item associated with the current page if qid is not supplied.
-- It only checks ranks that are requested (preferred and normal by default)
-- If property is not supplied, then P31 (instance of) is assumed.
-- It returns val if found or nothing if not found.
৩,১৮৪ ⟶ ৩,০১৭ নং লাইন:
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 )
local ranks = setRanks(args.rank)
local stats = {}
if ranks.b then
stats = mw.wikibase.getBestStatements(qid, pid)
else
stats = mw.wikibase.getAllStatements( qid, pid )
end
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
local ms = v.mainsnak
if ranks[v.rank:sub(1,1)] and ms.snaktype == "value" and ms.datavalue.value.id == val then
return val
end
৩,২১০ ⟶ ৩,০৩৬ নং লাইন:
-- 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
৩,২১৭ ⟶ ৩,০৪৩ নং লাইন:
local txt = frame.args.url or ""
if txt == "" then return nil end
-- extract any icon
local url, icon = txt:match("(.+)&nbsp;(.+)")
url = url or txt
-- make sure there's at least a space at the end
url = (url or txt) .. " "
icon = icon or ""
local prot, addr = url:match("(http[s]*://)(.+)")
-- extract any protocol like https://
prot = prot or url
local prot = url:match("(https*://).+[ \"\']")
addr = addr or ""
-- extract address
local addrdisp, n = addr:gsub("%.", "<wbr/>%.")
if prot then
addr = url:match("https*://(.+)[ \"\']") or " "
else
prot = "//"
addr = url:match("[^%p%s]+%.(.+)[ \"\']") or " "
end
-- strip trailing / from end of domain-only url and add <wbr/> before . and /
local disp, n = addr:gsub( "^([^/]+)/$", "%1" ):gsub("%/", "<wbr/>/"):gsub("%.", "<wbr/>.")
return '<span class="url">[' .. prot .. addr .. " " .. disp .. "]</span>&nbsp;" .. icon
end
৩,৩১১ ⟶ ৩,১২৭ নং লাইন:
local args = frame.args or frame:getParent().args or {}
 
local qid = args.qid or ""
if qid == "" then qid = mw.wikibase.getEntityIdForCurrentPage()nil end
 
if not qid or not mw.wikibase.entityExists(qid) then return i18n["entity-not-found"] end
local entity = mw.wikibase.getEntity(qid)
if not entity then return i18n["entity-not-found"] end
 
local labels = mw.wikibase.getEntity(qid)entity.labels
if not labels then return i18n["labels-not-found"] end
 
৩,৩৩৬ ⟶ ৩,১৫৪ নং লাইন:
local args = frame.args or frame:getParent().args or {}
 
local qid = args.qid or ""
if qid == "" then qid = mw.wikibase.getEntityIdForCurrentPage()nil end
 
if not qid or not mw.wikibase.entityExists(qid) then return i18n["entity-not-found"] end
local entity = mw.wikibase.getEntity(qid)
if not entity then return i18n["entity-not-found"] end
 
local descriptions = mw.wikibase.getEntity(qid)entity.descriptions
if not descriptions then return i18n["descriptions-not-found"] end
 
৩,৩৬১ ⟶ ৩,১৮১ নং লাইন:
local args = frame.args or frame:getParent().args or {}
 
local qid = args.qid or ""
if qid == "" then qid = mw.wikibase.getEntityIdForCurrentPage()nil end
 
if not qid or not mw.wikibase.entityExists(qid) then return i18n["entity-not-found"] end
local entity = mw.wikibase.getEntity(qid)
if not entity then return i18n["entity-not-found"] end
 
local aliases = mw.wikibase.getEntity(qid)entity.aliases
if not aliases then return i18n["aliases-not-found"] end
 
৩,৪৩২ ⟶ ৩,২৫৪ নং লাইন:
local site = args.site or ""
local showdab = parseParam(args.showdab, true)
local qid = mw.wikibase.getEntityIdForTitle(title, site)
if qid then
local prop31 = mw.wikibase.getBestStatements(qid, "P31")[1]
৩,৪৪২ ⟶ ৩,২৬৪ নং লাইন:
end
end
 
 
-------------------------------------------------------------------------------
৩,৪৫০ ⟶ ৩,২৭১ নং লাইন:
-- 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)nil if the Wikidatait does not exist.
-------------------------------------------------------------------------------
-- Dependencies: parseParam; sourced;
-------------------------------------------------------------------------------
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 defaultnil 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)
৩,৪৭২ ⟶ ৩,২৯১ নং লাইন:
if prec then return prec end
end
return default
end
 
৩,৪৯৩ ⟶ ৩,৩১১ নং লাইন:
getValueByRefSource
getPropertyIDs
getQualifierIDs
getPropOfProp
getAwardCat