Content deleted Content added
Why does the content of the imported Module:i18n need to be commented out? |
m update comment too |
||
(18 intermediate revisions by 8 users not shown) | |||
Line 1:
-- vim: set noexpandtab ft=lua ts=4 sw=4:
require('
local p = {}
Line 80:
}
if wiki.langcode ~= "en" then
--require("Module:i18n").loadI18n("Module:Wikidata/i18n", i18n)
-- got idea from [[:w:Module:Wd]]
local module_title; if ... == nil then
module_title = mw.getCurrentFrame():getTitle()
else
module_title = ...
end
require('Module:i18n').loadI18n(module_title..'/i18n', i18n)
end
-- this function needs to be internationalised along with the above:
Line 105 ⟶ 114:
return '<span class="error">' .. (i18n.errors[code] or code) .. '</span>'
end
local function parseDateFormat(f, timestamp, addon, prefix_addon, addon_sep)
local year_suffix
local tstr = ""
local lang_obj = mw.language.new(wiki.langcode)
local f_parts = mw.text.split(f, 'Y', true)
for idx, f_part in pairs(f_parts) do
year_suffix = ''
if string.match(f_part, "x[mijkot]$") then
-- for non-Gregorian year
f_part = f_part .. 'Y'
elseif idx < #f_parts then
-- supress leading zeros in year
year_suffix = lang_obj:formatDate('Y', timestamp)
year_suffix = string.gsub(year_suffix, '^0+', '', 1)
end
tstr = tstr .. lang_obj:formatDate(f_part, timestamp) .. year_suffix
end
if addon ~= "" and prefix_addon then
return addon .. addon_sep .. tstr
elseif addon ~= "" then
return tstr .. addon_sep .. addon
else
return tstr
end
end
local function parseDateValue(timestamp, date_format, date_addon)
local prefix_addon = i18n["datetime"]["prefix-addon"]
Line 115 ⟶ 148:
timestamp = '+' .. string.sub(timestamp, 2)
addon = date_addon
end
local _date_format = i18n["datetime"]["format"][date_format]
if _date_format ~= nil then
return
else
return printError("unknown-datetime-format")
Line 211 ⟶ 219:
_date_format = i18n["datetime"][9]
end
return parseDateFormat(_date_format, timestamp, addon, prefix_addon, addon_sep)
else
return printError("unknown-datetime-format")
Line 338 ⟶ 321:
if parameter then
if parameter == "link" then
local linkTarget = mw.wikibase.
local linkName = mw.wikibase.
if linkTarget then
-- if there is a local Wikipedia article link to it using the label or the article title
Line 351 ⟶ 334:
end
else
return mw.wikibase.
end
end
Line 385 ⟶ 368:
return entity.claims[property]
else
property = mw.wikibase.resolvePropertyId(property)
if not property then return end
return entity.claims[property]
end
end
Line 444 ⟶ 426:
if refparts then refparts = refparts .. ", " else refparts = "" end
-- output the label of the property of the reference part, e.g. "imported from" for P143
refparts = refparts .. tostring(mw.wikibase.
-- output all values of this reference part, e.g. "German Wikipedia" and "English Wikipedia" if the referenced claim was imported from both sites
for snakidx = 1, #snakval do
Line 464 ⟶ 446:
return false, input_parm, nil, nil
end
local entity = mw.wikibase.
local claims
if entity and entity.claims then
Line 489 ⟶ 471:
for k, v in pairs(claims) do
local qnumber = "Q" .. v.mainsnak.datavalue.value["numeric-id"]
local sitelink = mw.wikibase.
local label = labelHook(qnumber) or mw.wikibase.
if sitelink then
out[#out + 1] = "[[" .. sitelink .. "|" .. label .. "]]"
Line 520 ⟶ 502:
function p.descriptionIn(frame)
local langcode = frame.args[1]
local id = frame.args[2]
-- return description of a Wikidata entity in the given language or the default language of this Wikipedia site
return mw.wikibase.
end
function p.labelIn(frame)
local langcode = frame.args[1]
local id = frame.args[2]
-- return label of a Wikidata entity in the given language or the default language of this Wikipedia site
return mw.wikibase.
end
Line 602 ⟶ 584:
local input_parm = mw.text.trim(frame.args[3] or "")
if input_parm == "FETCH_WIKIDATA" then
local entity = mw.wikibase.
if entity.claims[propertyID] ~= nil then
local out = {}
Line 623 ⟶ 605:
local function outputValue(value)
local qnumber = "Q" .. value.datavalue.value["numeric-id"]
if (mw.wikibase.
return "[[" .. mw.wikibase.
else
return "[[:d:" .. qnumber .. "|" ..qnumber .. "]]<abbr title='" .. i18n["errors"]["local-article-not-found"] .. "'>[*]</abbr>"
Line 641 ⟶ 623:
local result = entity:formatPropertyValues(propertyID, mw.wikibase.entity.claimRanks).value
-- if number type: remove thousand separators, bounds and units
if isType(claims
result = mw.ustring.gsub(result, "(%d),(%d)", "%1%2")
result = mw.ustring.gsub(result, "(%d)±.*", "%1")
Line 656 ⟶ 638:
local entity = errorOrentity
local result = entity:formatPropertyValues(propertyID, mw.wikibase.entity.claimRanks).value
if isType(claims
result = mw.ustring.sub(result, mw.ustring.find(result, " ")+1, -1)
end
Line 670 ⟶ 652:
local entity = errorOrentity
local result
if isType(claims
-- get the url for the unit entry on Wikidata:
result = claims[1].mainsnak.datavalue.value.unit
Line 682 ⟶ 664:
local function outputHook(value)
if value.datavalue.value["numeric-id"] then
return mw.wikibase.
else
return value.datavalue.value
Line 758 ⟶ 740:
-- This is used to get the TA98 (Terminologia Anatomica first edition 1998) values like 'A01.1.00.005' (property P1323)
-- which are then linked to
-- uses the newer mw.wikibase calls instead of directly using the snaks
-- formatPropertyValues returns a table with the P1323 values concatenated with ", " so we have to split them out into a table in order to construct the return string
p.getTAValue = function(frame)
local ent = mw.wikibase.
local props = ent:formatPropertyValues('P1323')
local out = {}
Line 770 ⟶ 752:
t = mw.text.split( v, ", ")
for k2, v2 in pairs(t) do
out[#out + 1] = "[
end
end
Line 816 ⟶ 798:
local input_parm = mw.text.trim(frame.args[1] or "")
if input_parm == "FETCH_WIKIDATA" then
local ent = mw.wikibase.
local imgs
if ent and ent.claims then
Line 881 ⟶ 863:
-- returns the page id (Q...) of the current page or nothing of the page is not connected to Wikidata
function p.pageId(frame)
end
function p.claim(frame)
local property = frame.args[1] or ""
local id = frame.args["id"]
local qualifierId = frame.args["qualifier"]
local parameter = frame.args["parameter"]
Line 897 ⟶ 878:
-- get wikidata entity
local entity = mw.wikibase.
if not entity then
if showerrors then return printError("entity-not-found") else return default end
Line 954 ⟶ 935:
id = nil
end
local data = mw.wikibase.
if not data then
return nil
Line 980 ⟶ 961:
-- getting sitelink of a given wiki
-- get sitelink of current item if qid not supplied
function p.getSiteLink(frame)
local
if qid == "" then qid = nil end
local f = mw.text.trim( frame.args[1] or "")
local entity = mw.wikibase.getEntity(qid)
if not entity then
return
Line 995 ⟶ 979:
function p.Dump(frame)
local f = (frame.args[1] or frame.args.id) and frame or frame:getParent()
local data = mw.wikibase.
if not data then
return i18n.warnDump
|