Mô đun:WikidataIB và Mô đun:WikidataIB/sandbox: Khác biệt giữa các trang
(Khác biệt giữa các trang)
Không có tóm lược sửa đổi |
n Đã nhập 1 phiên bản |
||
| Dòng 1: | Dòng 1: | ||
-- Version: | -- Version: 2023-07-10 | ||
-- Module to implement use of a blacklist and whitelist for infobox fields | -- 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 | -- Can take a named parameter |qid which is the Wikidata ID for the article | ||
| Dòng 11: | Dòng 11: | ||
-- whitelist is passed in named parameter |fetchwikidata (or |fwd) | -- whitelist is passed in named parameter |fetchwikidata (or |fwd) | ||
require("strict") | |||
local p = {} | local p = {} | ||
| Dòng 41: | Dòng 42: | ||
["errors"] = | ["errors"] = | ||
{ | { | ||
["property-not-found"] = " | ["property-not-found"] = "Property not found.", | ||
["No property supplied"] = " | ["No property supplied"] = "No property supplied", | ||
["entity-not-found"] = " | ["entity-not-found"] = "Wikidata entity not found.", | ||
["unknown-claim-type"] = " | ["unknown-claim-type"] = "Unknown claim type.", | ||
["unknown-entity-type"] = " | ["unknown-entity-type"] = "Unknown entity type.", | ||
["qualifier-not-found"] = " | ["qualifier-not-found"] = "Qualifier not found.", | ||
["site-not-found"] = " | ["site-not-found"] = "Wikimedia project not found.", | ||
["labels-not-found"] = " | ["labels-not-found"] = "No labels found.", | ||
["descriptions-not-found"] = " | ["descriptions-not-found"] = "No descriptions found.", | ||
["aliases-not-found"] = " | ["aliases-not-found"] = "No aliases found.", | ||
["unknown-datetime-format"] = " | ["unknown-datetime-format"] = "Unknown datetime format.", | ||
["local-article-not-found"] = " | ["local-article-not-found"] = "Article is available on Wikidata, but not on Wikipedia", | ||
["dab-page"] = " ( | ["dab-page"] = " (dab)", | ||
}, | }, | ||
["months"] = | ["months"] = | ||
| Dòng 60: | Dòng 61: | ||
"July", "August", "September", "October", "November", "December" | "July", "August", "September", "October", "November", "December" | ||
}, | }, | ||
["century"] = " | ["century"] = "century", | ||
["BC"] = " | ["BC"] = "BC", | ||
["BCE"] = " | ["BCE"] = "BCE", | ||
["filespace"] = " | ["ordinal"] = | ||
["Unknown"] = " | { | ||
["NaN"] = " | [1] = "st", | ||
[2] = "nd", | |||
[3] = "rd", | |||
["default"] = "th" | |||
}, | |||
["filespace"] = "File", | |||
["Unknown"] = "Unknown", | |||
["NaN"] = "Not a number", | |||
-- set the following to the name of a tracking category, | -- set the following to the name of a tracking category, | ||
-- e.g. "[[Category:Articles with missing Wikidata information]]", or "" to disable: | -- e.g. "[[Category:Articles with missing Wikidata information]]", or "" to disable: | ||
["missinginfocat"] = "[[ | ["missinginfocat"] = "[[Category:Articles with missing Wikidata information]]", | ||
["editonwikidata"] = " | ["editonwikidata"] = "Edit this on Wikidata", | ||
["latestdatequalifier"] = function (date) return " | ["latestdatequalifier"] = function (date) return "before " .. date end, | ||
-- some languages, e.g. Bosnian use a period as a suffix after each number in a date | -- some languages, e.g. Bosnian use a period as a suffix after each number in a date | ||
["datenumbersuffix"] = "", | ["datenumbersuffix"] = "", | ||
| Dòng 76: | Dòng 84: | ||
["multipliers"] = { | ["multipliers"] = { | ||
[0] = "", | [0] = "", | ||
[3] = " | [3] = " thousand", | ||
[6] = " | [6] = " million", | ||
[9] = " | [9] = " billion", | ||
[12] = " | [12] = " trillion", | ||
} | } | ||
} | } | ||
| Dòng 113: | Dòng 121: | ||
------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | ||
-- | -- | ||
------------------------------------------------------------------------------- | |||
-- makeOrdinal needs to be internationalised along with the above: | |||
-- takes cardinal number as a numeric and returns the ordinal as a string | |||
-- we need three exceptions in English for 1st, 2nd, 3rd, 21st, .. 31st, etc. | |||
------------------------------------------------------------------------------- | |||
-- Dependencies: none | |||
------------------------------------------------------------------------------- | |||
local makeOrdinal = function(cardinal) | |||
local ordsuffix = i18n.ordinal.default | |||
if cardinal % 10 == 1 then | |||
ordsuffix = i18n.ordinal[1] | |||
elseif cardinal % 10 == 2 then | |||
ordsuffix = i18n.ordinal[2] | |||
elseif cardinal % 10 == 3 then | |||
ordsuffix = i18n.ordinal[3] | |||
end | |||
-- In English, 1, 21, 31, etc. use 'st', but 11, 111, etc. use 'th' | |||
-- similarly for 12 and 13, etc. | |||
if (cardinal % 100 == 11) or (cardinal % 100 == 12) or (cardinal % 100 == 13) then | |||
ordsuffix = i18n.ordinal.default | |||
end | |||
return tostring(cardinal) .. ordsuffix | |||
end | |||
------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | ||
-- findLang takes a "langcode" parameter if supplied and valid | -- findLang takes a "langcode" parameter if supplied and valid | ||
| Dòng 127: | Dòng 160: | ||
langobj = mw.language.new( langcode ) | langobj = mw.language.new( langcode ) | ||
else | else | ||
langcode = mw.getCurrentFrame(): | langcode = mw.getCurrentFrame():callParserFunction('int', {'lang'}) | ||
if mw.language.isKnownLanguageTag(langcode) then | if mw.language.isKnownLanguageTag(langcode) then | ||
langobj = mw.language.new( langcode ) | langobj = mw.language.new( langcode ) | ||
| Dòng 471: | Dòng 504: | ||
local _getCommonslink = function(qid, onlycat, fallback) | local _getCommonslink = function(qid, onlycat, fallback) | ||
qid = (qid or ""):upper() | qid = (qid or ""):upper() | ||
if qid == "" then | if qid == "" then qid = mw.wikibase.getEntityIdForCurrentPage() end | ||
if not qid then return nil end | |||
end | |||
if not qid then return nil end | |||
onlycat = parseParam(onlycat, false) | onlycat = parseParam(onlycat, false) | ||
if fallback == "" then fallback = nil end | if fallback == "" then fallback = nil end | ||
| Dòng 559: | Dòng 586: | ||
local postfix = (args.postfix or ""):gsub('"', '') | local postfix = (args.postfix or ""):gsub('"', '') | ||
local dtxt = args.dtxt | local dtxt = args.dtxt | ||
local shortname = args.shortname | local shortname = args.shortname or args.sn | ||
local lang = args.lang or "en" -- fallback to default if missing | local lang = args.lang or "en" -- fallback to default if missing | ||
local uselbl = args.uselabel or args.uselbl | local uselbl = args.uselabel or args.uselbl | ||
| Dòng 1.087: | Dòng 1.114: | ||
local unitsymbols = mw.wikibase.getBestStatements(unitqid, "P5061") | local unitsymbols = mw.wikibase.getBestStatements(unitqid, "P5061") | ||
-- construct fallback table, add local lang and multiple languages | -- construct fallback table, add local lang and multiple languages | ||
local fbtbl = mw.language.getFallbacksFor( args.lang ) | local fbtbl = mw.language.getFallbacksFor( args.lang, mw.language.FALLBACK_STRICT ) | ||
table.insert( fbtbl, 1, args.lang ) | table.insert( fbtbl, 1, args.lang ) | ||
table.insert( fbtbl, | table.insert( fbtbl, "mul" ) | ||
table.insert( fbtbl, "en" ) | |||
local found = false | local found = false | ||
for idx1, us in ipairs(unitsymbols) do | for idx1, us in ipairs(unitsymbols) do | ||
| Dòng 1.098: | Dòng 1.126: | ||
break | break | ||
end | end | ||
end -- loop through fallback table | |||
if found then break end | if found then break end | ||
end -- loop through values of P5061 | end -- loop through values of P5061 | ||
if found then usep, unit = " ", usym end | if found then usep, unit = " ", usym end | ||
| Dòng 1.111: | Dòng 1.139: | ||
val = mw.getCurrentFrame():expandTemplate{title = "cvt", args = {lowb, "to", upb, unit}} | val = mw.getCurrentFrame():expandTemplate{title = "cvt", args = {lowb, "to", upb, unit}} | ||
end | end | ||
elseif unit == "$" or unit == "£" then | elseif unit == "$" or unit == "£" then | ||
val = unit .. amount .. range .. i18n.multipliers[scale] | val = unit .. amount .. range .. i18n.multipliers[scale] | ||
| Dòng 1.719: | Dòng 1.745: | ||
local paraset = tonumber(args.ps or args.parameterset or 0) | local paraset = tonumber(args.ps or args.parameterset or 0) | ||
if paraset == 1 then | if paraset == 1 then | ||
-- a common setting | -- a common setting, not usable in infoboxes because the 2018 RFC requires sources | ||
args.rank = "best" | args.rank = "best" | ||
args.fetchwikidata = "ALL" | args.fetchwikidata = "ALL" | ||
| Dòng 1.725: | Dòng 1.751: | ||
args.noicon = "true" | args.noicon = "true" | ||
elseif paraset == 2 then | elseif paraset == 2 then | ||
-- equivalent to raw | -- equivalent to raw, not usable in infoboxes because the 2018 RFC requires sources | ||
args.rank = "best" | args.rank = "best" | ||
args.fetchwikidata = "ALL" | args.fetchwikidata = "ALL" | ||
| Dòng 1.733: | Dòng 1.759: | ||
args.pd = "true" | args.pd = "true" | ||
elseif paraset == 3 then | elseif paraset == 3 then | ||
-- | -- parameterset 1, but usable in infoboxes because the 2018 RFC requires sources | ||
args.rank = "best" | |||
args.fetchwikidata = "ALL" | |||
args.onlysourced = "yes" | |||
args.noicon = "true" | |||
end | end | ||
| Dòng 2.791: | Dòng 2.821: | ||
------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | ||
p.pageId = function(frame) | p.pageId = function(frame) | ||
return | return mw.wikibase.getEntityIdForCurrentPage() | ||
end | end | ||
| Dòng 3.042: | Dòng 3.072: | ||
------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | ||
p.siteID = function(frame) | p.siteID = function(frame) | ||
local txtlang = frame: | local txtlang = frame:callParserFunction('int', {'lang'}) or "" | ||
-- This deals with specific exceptions: be-tarask -> be-x-old | -- This deals with specific exceptions: be-tarask -> be-x-old | ||
if txtlang == "be-tarask" then | if txtlang == "be-tarask" then | ||
| Dòng 3.066: | Dòng 3.096: | ||
------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | ||
p.projID = function(frame) | p.projID = function(frame) | ||
local txtlang = frame: | local txtlang = frame:callParserFunction('int', {'lang'}) or "" | ||
-- This deals with specific exceptions: be-tarask -> be-x-old | -- This deals with specific exceptions: be-tarask -> be-x-old | ||
if txtlang == "be-tarask" then | if txtlang == "be-tarask" then | ||
| Dòng 3.225: | Dòng 3.255: | ||
local url = frame.args.url or "" | local url = frame.args.url or "" | ||
if url:upper() == "NONE" then return nil end | if url:upper() == "NONE" then return nil end | ||
local urls = {} | |||
local quals = {} | |||
local qid = frame.args.qid or "" | local qid = frame.args.qid or "" | ||
if qid == "" then qid = mw.wikibase.getEntityIdForCurrentPage() end | if url and url ~= "" then | ||
urls[1] = url | |||
else | |||
if qid == "" then qid = mw.wikibase.getEntityIdForCurrentPage() end | |||
if not qid then return nil end | |||
local prop856 = mw.wikibase.getBestStatements(qid, "P856") | local prop856 = mw.wikibase.getBestStatements(qid, "P856") | ||
for k, v in pairs(prop856) do | for k, v in pairs(prop856) do | ||
| Dòng 3.246: | Dòng 3.277: | ||
end -- test for website having a value | end -- test for website having a value | ||
end -- loop through website(s) | end -- loop through website(s) | ||
end | end | ||
if #urls == 0 then return nil end | if #urls == 0 then return nil end | ||