"पटलम्:WikidataIB" इत्यस्य संस्करणे भेदः

Content deleted Content added
Enwiki
अङ्कनानि : जङ्गमदूरवाण्या सम्पादितम् जङ्गमदूरवाण्या जालसम्पादनम्
Update from enwiki
 
पङ्क्तिः १४:
local cdate = require("Module:Complex date")._complex_date
-- [[Module:Complex date]] has the following dependencies:
-- Module:i18nI18n/complex date, Module:ISOdate, Module:DateI18n (alternative for Module:Date), Module:Formatnum,
-- 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.
पङ्क्तिः ८१:
}
-- This allows a internationisation module to override the above table
if 'en' ~= mw.getContentLanguage():getCode() then
require("Module:i18n").loadI18n("Module:WikidataIB/i18n", i18n)
require("Module:i18n").loadI18n("Module:WikidataIB/i18n", i18n)
end
 
-- This piece of html implements a collapsible container. Check the classes exist on your wiki.
Line ३०७ ⟶ ३०९:
bcf = (bcf or ""):upper()
-- plaindate only needs the first letter (y/n/a)
pd = (pd or ""):sub(1,1):lower()
if pd == "" or pd == "n" or pd == "f" or pd == "0" then pd = false end
-- in case language isn't passed
Line ३७६ ⟶ ३७८:
return default
end
end
 
 
-------------------------------------------------------------------------------
-- _getSitelink takes the qid of a Wikidata entity passed as |qid=
-- It takes an optional parameter |wiki= to determine which wiki is to be checked for a sitelink
-- If the parameter is blank, then it uses the local wiki.
-- If there is a sitelink to an article available, it returns the plain text link to the article
-- If there is no sitelink, it returns nil.
-------------------------------------------------------------------------------
-- Dependencies: none
-------------------------------------------------------------------------------
local _getSitelink = function(qid, wiki)
qid = (qid or ""):upper()
if qid == "" then return nil end
wiki = wiki or ""
local sitelink
if wiki == "" then
sitelink = mw.wikibase.sitelink(qid)
else
sitelink = mw.wikibase.sitelink(qid, wiki)
end
return sitelink
end
 
 
-------------------------------------------------------------------------------
-- _getCommonslink takes an optional qid of a Wikidata entity passed as |qid=
-- It returns one of the following in order of preference:
-- the Commons sitelink of the linked Wikidata item;
-- the Commons sitelink of the topic's main category of the linked Wikidata item;
-- the Commons category.
-- If the optional parameter onlycat is true/yes/1 then only categories are returned
-- defaults to false.
-------------------------------------------------------------------------------
-- Dependencies: _getSitelink(); parseParam()
-------------------------------------------------------------------------------
local _getCommonslink = function(qid, onlycat, fallback)
qid = (qid or ""):upper()
if qid == "" then qid = mw.wikibase.getEntityIdForCurrentPage() end
if not qid then return nil end
onlycat = parseParam(onlycat, false)
local sitelink = _getSitelink(qid, "commonswiki")
if onlycat and sitelink and sitelink:sub(1,9) ~= "Category:" then sitelink = nil end
if not sitelink then
-- check for topic's main category
local prop910 = mw.wikibase.getBestStatements(qid, "P910")[1]
if prop910 then
local tmcid = prop910.mainsnak.datavalue.value.id
sitelink = _getSitelink(tmcid, "commonswiki")
end
end
if not sitelink and fallback then
-- check for Commons category (string value)
local prop373 = mw.wikibase.getBestStatements(qid, "P373")[1]
if prop373 then
sitelink = prop373.mainsnak.datavalue.value
if sitelink then sitelink = "Category:" .. sitelink end
end
end
return sitelink
end
 
Line ५४९ ⟶ ६१२:
-- If a non-blank input parameter was supplied return it
if input_parm then return false, input_parm end
 
-- We can filter out non-valid properties
if property_id:sub(1,1):upper() ~="P" or property_id == "P0" then return false, nil end
 
-- Otherwise see if this field is on the whitelist:
Line ५८६ ⟶ ६५२:
icon = icon .. "|link=https://www.wikidata.org/wiki/" .. entityID
icon = icon .. "?uselang=" .. langcode
if propertyID then icon = icon .. "#" .. propertyID end
icon = icon .. "|" .. i18n["editonwikidata"] .. "]]"
return icon
end
Line ७१८ ⟶ ७८५:
-- qualifiers (if any) is a nested table or nil
-- lang is given, or user language, or site language
val = dateFormat(dv.time, dv.precision, args.df, args.bc, args.pd, propval.qualifiers, args.lang)
------------------------------------
-- data types which are strings:
Line ७४४ ⟶ ८११:
if conv then
fnum = false
args.scale = "0"
end
--
Line ८२९ ⟶ ८९६:
local fbtbl = mw.language.getFallbacksFor( args.lang )
table.insert( fbtbl, 1, args.lang )
local found = false
for idx1, us in ipairs(unitsymbols) do
for idx2, fblang in ipairs(fbtbl) do
Line ९८९ ⟶ १,०५६:
-- to disable/enable "sourcing cirumstances" or use adjectival form for the plain date
local pd = args.plaindate or args.pd or "no"
args.pd = pd
 
local lang = args.lang
Line १,०४३ ⟶ १,१११:
end
else
local ql = propertyvalueandquals(v1v.qualifiers, qargs)
for k1, v1 in ipairs(ql) do
if k1 == "P1326" then
Line १,०९१ ⟶ १,१५९:
local t = t1 .. t2
-- *** internationalise date separators later ***
if t:find("%s") or t:find(" ") thenlocal dsep = " – " else dsep = "–" end
if t:find("%s") or t:find(" ") then dsep = " – " end
if #qlist > 0 then
local qstr = assembleoutput(qlist, qargs)
Line १,१०० ⟶ १,१६९:
end
elseif t > "" then
-- *** internationalise date separators later ***
local dsep = "–"
if t:find("%s") or t:find(" ") then dsep = " – " end
if qualsonly then
out[#out+1] = t1 .. dsep .. t2
Line १,१२२ ⟶ १,१८८:
local fbtbl = mw.language.getFallbacksFor( langcode )
table.insert( fbtbl, 1, langcode )
local bestval = ""
local found = false
for idx1, lang1 in ipairs(fbtbl) do
for idx2, lang2 in ipairs(mlt) do
Line १,२०० ⟶ १,२६६:
end -- of check for matching required value and has qualifiers
else
return "not string"nil
end -- of check for string
end -- of loop through values of propertyID
Line १,२५० ⟶ १,३१६:
-- This is top-level location, so get short name except when this is the first item
-- Use full label if there's no short name or this is the first item
propslocal prop1813 = mw.wikibase.getAllStatements(qid, "P1813")
-- if there's a short name and this isn't the only item
if propsprop1813[1] and (#out > 0)then
local shortname
-- short name is monolingual text, so look for match to the local language
-- choose the shortest 'short name' in that language
for k, v in pairs(propsprop1813) do
if v.mainsnak.datavalue.value.language == langcode then
local name = v.mainsnak.datavalue.value.text
Line १,३९६ ⟶ १,४६२:
return props -- either local parameter or nothing
else
local dv = props[1].mainsnak.datavalue.value
local lat, long, prec = dv.latitude, dv.longitude, dv.precision
lat = decimalPrecision(lat, prec)
Line १,५२९ ⟶ १,५९५:
langcode = frame:callParserFunction{ name = "int", args = "lang" }
end
local function checkLanguage(id)
-- id should represent a language like "British English (Q7979)"
-- it should have string property "Wikimedia language code (P424)"
Line १,६०८ ⟶ १,६७४:
local fbtbl = mw.language.getFallbacksFor( langcode )
table.insert( fbtbl, 1, langcode )
local bestval = ""
local found = false
for idx1, lang1 in ipairs(fbtbl) do
for idx2, lang2 in ipairs(mlt) do
Line १,६३२ ⟶ १,६९८:
return props -- no property or local parameter supplied
end -- of test for success
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
local coords = mw.wikibase.getBestStatements(qid, "P625")[1]
local globeid
if coords and coords.mainsnak.snaktype == "value" then
globeid = coords.mainsnak.datavalue.value.globe:match("(Q%d+)")
end
return globeid
end
 
 
-------------------------------------------------------------------------------
-- getCommonsLink takes an optional qid of a Wikidata entity passed as |qid=
-- It returns one of the following in order of preference:
-- the Commons sitelink of the linked Wikidata item;
-- the Commons sitelink of the topic's main category of the linked Wikidata item;
-------------------------------------------------------------------------------
-- Dependencies: _getCommonslink(); _getSitelink(); parseParam()
-------------------------------------------------------------------------------
p.getCommonsLink = function(frame)
local oc = frame.args.onlycat or frame.args.onlycategories
local fb = parseParam(frame.args.fallback or frame.args.fb, true)
return _getCommonslink(frame.args.qid, oc, fb)
end
 
 
-------------------------------------------------------------------------------
-- getSitelink takes the qid of a Wikidata entity passed as |qid=
-- It takes an optional parameter |wiki= to determine which wiki is to be checked for a sitelink
-- If the parameter is blank, then it uses the local wiki.
-- If there is a sitelink to an article available, it returns the plain text link to the article
-- If there is no sitelink, it returns nil.
-------------------------------------------------------------------------------
-- Dependencies: none
-------------------------------------------------------------------------------
p.getSiteLink = function(frame)
return _getSitelink(frame.args.qid, frame.args.wiki or mw.text.trim(frame.args[1] or ""))
end
 
Line १,७०७ ⟶ १,८२२:
return desc
end
end
 
 
-------------------------------------------------------------------------------
-- getAliases has the qid of a Wikidata entity passed as |qid=
-- (it defaults to the associated qid of the current article if omitted)
-- and a local parameter passed as the first unnamed parameter.
-- It implements blacklisting and whitelisting with a field name of "alias" by default.
-- Any local parameter passed becomes the return value.
-- Otherwise it returns the aliases for the Wikidata entity with the usual list options.
-- Nothing is returned if the aliases do not exist.
-------------------------------------------------------------------------------
-- Dependencies: findLang(); assembleoutput()
-------------------------------------------------------------------------------
p.getAliases = function(frame)
local args = frame.args
 
local fieldname = args.name or ""
if fieldname == "" then fieldname = "alias" end
 
local blacklist = args.suppressfields or args.spf or ""
if blacklist:find(fieldname) then return nil end
 
local localval = mw.text.trim(args[1] or "")
if localval ~= "" then return localval end
 
local whitelist = args.fetchwikidata or args.fwd or ""
if whitelist == "" then whitelist = "NONE" end
if not (whitelist == 'ALL' or whitelist:find(fieldname)) then return nil end
 
local qid = mw.text.trim(args.qid or "")
if qid == "" then qid = nil end
 
local entity = mw.wikibase.getEntity(qid)
if not entity then return nil end
local aliases = entity.aliases
if not aliases then return nil end
if not qid then qid= mw.wikibase.getEntityIdForCurrentPage() end
 
args.langobj = findLang(args.lang)
local langcode = args.langobj.code
args.lang = langcode
 
local out = {}
for k1, v1 in pairs(aliases) do
if v1[1].language == langcode then
for k1, v2 in ipairs(v1) do
out[#out+1] = v2.value
end
break
end
end
 
return assembleoutput(out, args, qid)
end
 
Line १,९९६ ⟶ २,१६५:
if qid:sub(1,1) ~= "Q" then qid = mw.wikibase.getEntityIdForCurrentPage() end
if not qid then return "No item for this page" end
return "<pre>" .. mw.dumpObject( mw.wikibase.getAllStatements( qid, pid ) ) .. "</pre>"
end
 
Line २,०८४ ⟶ २,२५३:
local quals = {}
if url == "" then
local propsprop856 = mw.wikibase.getBestStatements(qid, "P856")
for k, v in pairs(propsprop856) do
if v.mainsnak.snaktype == "value" then
urls[#urls+1] = v.mainsnak.datavalue.value
Line २,१४६ ⟶ २,३१५:
if not labels then return i18n["labels-not-found"] end
 
local out = {}
for k, v in pairs(labels) do
out[#out+1] = v.value .. " (" .. v.language .. ")"
Line २,१७३ ⟶ २,३४२:
if not descriptions then return i18n["descriptions-not-found"] end
 
local out = {}
for k, v in pairs(descriptions) do
out[#out+1] = v.value .. " (" .. v.language .. ")"
Line २,१८३ ⟶ २,३५२:
 
-------------------------------------------------------------------------------
-- getAllAliases fetches the set of descriptionsaliases and formats it for display as wikitext.
-- It takes a parameter 'qid' for arbitrary access, otherwise it uses the current page.
-------------------------------------------------------------------------------
Line २,२०० ⟶ २,३६९:
if not aliases then return i18n["aliases-not-found"] end
 
local out = {}
for k1, v1 in pairs(aliases) do
local lang = v1[1].language
Line २,२३० ⟶ २,३९९:
-- getAT
-- getDescription
-- getAliases
-- pageId
-- formatDate
Line २,२४७ ⟶ २,४१७:
-- url2
-- getWebsite
-- getAllLabels
-- getAllDescriptions
-- getAllAliases
-------------------------------------------------------------------------------
"https://sa.wikipedia.org/wiki/पटलम्:WikidataIB" इत्यस्माद् प्रतिप्राप्तम्