মডিউল:WikidataIB: সংশোধিত সংস্করণের মধ্যে পার্থক্য
বিষয়বস্তু বিয়োগ হয়েছে বিষয়বস্তু যোগ হয়েছে
Bodhisattwa (আলোচনা | অবদান) সম্পাদনা সারাংশ নেই ট্যাগ: পুনর্বহালকৃত |
এটা কি আগে হত? ট্যাগ: হাতদ্বারা প্রত্যাবর্তন পুনর্বহালকৃত |
||
১ নং লাইন:
-- 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:Formatnum, Module:I18n/date, Module:Yesno, Module:Linguistic, Module:Calendar
-- 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"] = "
["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.
-------------------------------------------------------------------------------
-- Dependencies: labelOrId(); donotlink[]
-------------------------------------------------------------------------------
local linkedItem = function(id,
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
break -- pick the first match
end
end
৬২৮ ⟶ ৬০৫ নং লাইন:
if sitelink then
if not (dtxt or shortname) then
-- strip any namespace or dab from the sitelink
local
if mw.site.namespaces[prefix] then -- that prefix is a valid namespace, so remove it
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
local artitle = mw.title.new(label, 0) -- only nil if label has invalid chars
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
else
-- either (donotlink is true) or (no sitelink, label exists, not redirect)
-- 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
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
end
else
৬৯৭ ⟶ ৬৬৩ নং লাইন:
-------------------------------------------------------------------------------
-- sourced takes a table representing a statement that may or may not have references
-- it
-- it returns a boolean = true if
-------------------------------------------------------------------------------
-- Dependencies: none
৭০৬ ⟶ ৬৭২ নং লাইন:
for kr, vr in pairs(claim.references) do
local ref = mw.wikibase.renderSnaks(vr.snaks)
if not ref:find("
return true
end
৭৭২ ⟶ ৭৩৮ নং লাইন:
-- The blacklist is passed in named parameter |suppressfields
local blacklist = args.suppressfields or args.spf
-- The whitelist is passed in named parameter |fetchwikidata
local whitelist = args.fetchwikidata or args.fwd
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
-- 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"
-------------------------------------------------------------------------------
-- Dependencies: i18n[];
-------------------------------------------------------------------------------
local createicon = function(langcode, entityID, propertyID)
local icon = " <span class='penicon'>[["
-- " <span data-bridge-edit-flow='overwrite' class='penicon'>[[" -> enable Wikidata Bridge
.. i18n["filespace"]
৮৩৮ ⟶ ৭৯৯ নং লাইন:
.. i18n["editonwikidata"]
.. "|link=https://www.wikidata.org/wiki/" .. entityID
if propertyID
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
-------------------------------------------------------------------------------
-- Dependencies: parseParam();
৮৯৬ ⟶ ৮৫৭ নং লাইন:
if #out > 0 then
if sorted then table.sort(out) end
-- if
if not noic 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
args.qdf = args.qdf or args.qualifierdateformat or args.df or
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
-- 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
local qsep = (args.qsep or ""):gsub('"', '')
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
-- see if we want
if qualID == "ALL" then
if v["qualifiers-order"] then
-- the values in the order table are the keys for the qualifiers table:
for k1, v1 in ipairs(v["qualifiers-order"]) do
if v1 == "P1326" then
local ts = v.qualifiers[v1][1].datavalue.value.time
local dp = v.qualifiers[v1][1].datavalue.value.precision
qlist[#qlist + 1] = dateFormat(ts, dp, args.qdf, args.bc, pd, "", lang, "before")
elseif v1 == "P1319" then
local ts = v.qualifiers[v1][1].datavalue.value.time
local dp = v.qualifiers[v1][1].datavalue.value.precision
qlist[#qlist + 1] = dateFormat(ts, dp, args.qdf, args.bc, pd, "", lang, "after")
else
local
-- we already deal with circa via 'sourcing circumstances' if the datatype was time
-- circa may be either linked or unlinked *** internationalise later ***
if datatype ~= "time" or q ~= "circa" and not (type(q) == "string" and q:find("circa]]")) then
qlist[#qlist + 1] = q
end
end
end
else
-- are there cases where qualifiers-order doesn't exist?
local ql = propertyvalueandquals(v.qualifiers, qargs)
for k1, v1 in ipairs(ql) do
-- we already deal with circa via 'sourcing circumstances' if the datatype was time
-- 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 = "–"
if t:find("%s") or t:find(" ") then dsep = " – " end
if #qlist > 0 then
if qualsonly then
out[#out+1] = qstr
১,৪০৬ ⟶ ১,৩৬৬ নং লাইন:
out[#out] = out[#out] .. " (" .. qstr .. ")"
end
elseif t
if qualsonly then
else
out[#out] = out[#out] .. " (" ..
end
end
১,৪৯৪ ⟶ ১,৪৪৮ নং লাইন:
local uabbr = parseParam(args.unitabbr or args.uabbr, false)
local filter = (args.unit or ""):upper()
if filter == "" then filter = nil end
১,৫২৬ ⟶ ১,৪৭৯ নং লাইন:
return nil
end -- of check for string
end -- of loop through values of propertyID
return assembleoutput(out, frame.args, qid, propertyID)
১,৫৬৯ ⟶ ১,৫২১ নং লাইন:
end
for i2, v2 in ipairs(proptbl) do
if parttbl then
-- this higher location has qualifier 'applies to part' (P518)
১,৫৯৬ ⟶ ১,৫৪৮ নং লাইন:
end
-- check if it's an instance of (P31) a country (Q6256)
local inst = mw.wikibase.getAllStatements(qid, "P31")
if #inst > 0 then
for k, v in ipairs(inst) do
local instid =
-- stop if it's a country (or a country within the United Kingdom if skip is true)
if instid == "Q6256
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
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
-------------------------------------------------------------------------------
-- Dependencies: setRanks(); parseInput(); decimalPrecision();
১,৮৫৪ ⟶ ১,৮০৪ নং লাইন:
-- if there is a 'display' parameter supplied, use it
-- otherwise default to
local disp = frame.args.display or ""
if disp == "" then
disp =
end
১,৯১৫ ⟶ ১,৮৬৫ নং লাইন:
-- whose value is to be returned is passed in named parameter |qual=
local qualifierID = frame.args.qual
-- 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
-- can't reference qualifer, so set onlysourced = "no" (not boolean)
local qargs = frame.args
local vals = propertyvalueandquals(quals, qargs, qid)
for k, v in ipairs(vals) do
end
end
২,১৪৬ ⟶ ২,০৮৬ নং লাইন:
-- Dependencies: parseParam; setRanks; parseInput; sourced; propertyvalueandquals assembleoutput;
-------------------------------------------------------------------------------
p.
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 ""
-- get the qid and table of claims for the property, or nothing and the local value passed
২,১৬৩ ⟶ ২,১০৪ নং লাইন:
local maxvals = tonumber(args.maxvals) or 0
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)
২,২৫১ ⟶ ২,১২৯ নং লাইন:
-- Dependencies: parseParam; setRanks; parseInput; sourced; propertyvalueandquals assembleoutput;
-------------------------------------------------------------------------------
p.
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
local qid1, statements1 = parseInput(frame, localval, pid1)
if not qid1 then return localval end
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
২,৫০০ ⟶ ২,৩৪৫ নং লাইন:
if maxvals > 0 and #cat2 >= maxvals then break end
end
for k1, v1 in ipairs(cat1) do
for k2, v2 in ipairs(cat2) do
২,৫৮৪ ⟶ ২,৪২৯ নং লাইন:
end
elseif qtype == "url" then
local display = mw.ustring.match( mw.uri.decode(qv, "WIKI"), "([%w ]+)$" )
if display then
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
-------------------------------------------------------------------------------
-- 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 =
local
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
-- 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,
-- If props is not given, the qid is returned.
-------------------------------------------------------------------------------
-- Dependencies: parseParam()
-------------------------------------------------------------------------------
p.
local qid = (frame.args.qid or ""):upper()
local all = parseParam(frame.args.all, false)
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, " ")
else
return qid
end
end
৩,০৬৭ ⟶ ২,৮৯৯ নং লাইন:
-------------------------------------------------------------------------------
p.siteID = function(frame)
-- 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)
-- 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.
-- 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 )
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
৩,২১০ ⟶ ৩,০৩৬ নং লাইন:
-- 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
local url, icon = txt:match("(.+) (.+)")
url = url or txt
icon = icon or ""
local prot, addr = url:match("(http[s]*://)(.+)")
prot = prot or url
addr = addr or ""
local
return '<span class="url">[' .. prot .. addr .. " " .. disp .. "]</span> " .. icon
end
৩,৩১১ ⟶ ৩,১২৭ নং লাইন:
local args = frame.args or frame:getParent().args or {}
local qid = args.qid
if qid == "" then qid =
local entity = mw.wikibase.getEntity(qid)
if not entity then return i18n["entity-not-found"] end
local labels =
if not labels then return i18n["labels-not-found"] end
৩,৩৩৬ ⟶ ৩,১৫৪ নং লাইন:
local args = frame.args or frame:getParent().args or {}
local qid = args.qid
if qid == "" then qid =
local entity = mw.wikibase.getEntity(qid)
if not entity then return i18n["entity-not-found"] end
local descriptions =
if not descriptions then return i18n["descriptions-not-found"] end
৩,৩৬১ ⟶ ৩,১৮১ নং লাইন:
local args = frame.args or frame:getParent().args or {}
local qid = args.qid
if qid == "" then qid =
local entity = mw.wikibase.getEntity(qid)
if not entity then return i18n["entity-not-found"] end
local aliases =
if not aliases then return i18n["aliases-not-found"] end
৩,৪৩২ ⟶ ৩,২৫৪ নং লাইন:
local site = args.site or ""
local showdab = parseParam(args.showdab, true)
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
-------------------------------------------------------------------------------
-- Dependencies: parseParam
-------------------------------------------------------------------------------
function p.getDatePrecision(frame)
local args=frame.args
if not args[1] then args=frame:getParent().args end
local prop = mw.text.trim(args[1] or "")
if prop == "" then return
local qid = args.qid or ""
if qid == "" then qid = mw.wikibase.getEntityIdForCurrentPage() end
local onlysrc = parseParam(args.onlysourced or args.osd, true)
local stat = mw.wikibase.getBestStatements(qid, prop)
৩,৪৭২ ⟶ ৩,২৯১ নং লাইন:
if prec then return prec end
end
end
৩,৪৯৩ ⟶ ৩,৩১১ নং লাইন:
getValueByRefSource
getPropertyIDs
getPropOfProp
getAwardCat
|