Módulo:NMSF-AR
Este módulo no tiene página de documentación[crear]
require('strict')
local p = {}
local wiki =
{
langcode = mw.language.getContentLanguage().code
}
-- internationalisation
local i18n =
{
["errors"] =
{
["local-article-not-found"] = "Article is not yet available in this wiki."
}
}
local function isType(claims, type)
return claims[1] and claims[1].mainsnak.snaktype == "value" and claims[1].mainsnak.datavalue.type == type
end
local function getValue(entity, claims, propertyID, delim, labelHook)
if labelHook == nil then
labelHook = function (qnumber)
return nil;
end
end
if isType(claims, "wikibase-entityid") then
local out = {}
for k, v in pairs(claims) do
local qnumber = "Q" .. v.mainsnak.datavalue.value["numeric-id"]
local sitelink = mw.wikibase.sitelink(qnumber)
local label = labelHook(qnumber) or mw.wikibase.label(qnumber) or qnumber
if sitelink then
out[#out + 1] = "[[" .. sitelink .. "|" .. label .. "]]"
else
out[#out + 1] = "[[:d:" .. qnumber .. "|" .. label .. "]]<abbr title='" .. i18n["errors"]["local-article-not-found"] .. "'>[*]</abbr>"
end
end
return table.concat(out, delim)
else
-- just return best values
return entity:formatPropertyValues(propertyID).value
end
end
-- This is used to get a value, or a comma separated list of them if multiple values exist
-- from an arbitrary entry by using its QID.
-- Use : {{#invoke:NMSF-AR|getValueFromID|<ID>|<Property>}}
-- E.g.: {{#invoke:NMSR-AR|getValueFromID|Q151973|P26}} - to fetch value of 'spouse' (P26) from 'Richard Burton' (Q151973)
-- Please use sparingly - this is an *expensive call*.
p.getValueFromID = function(frame)
local itemID = mw.text.trim(frame.args[1] or "")
local propertyID = mw.text.trim(frame.args[2] or "")
local entity = mw.wikibase.getEntity(itemID)
local claims
if entity and entity.claims then
claims = entity.claims[propertyID]
end
if claims then
return getValue(entity, claims, propertyID, ", ")
else
return ""
end
end
-- Use : {{#invoke:NMSF-AR|getCatImages|<ID>}}
p.getCatImages = function(frame)
local itemID = mw.text.trim(frame.args[1] or "")
local entity = mw.wikibase.getEntity(itemID)
local out = ""
if entity and entity.claims then
local category = entity.claims.P373[1]
if category then
out = "[[:c:Category:" .. category.mainsnak.datavalue.value .. "|" .. category.mainsnak.datavalue.value .. "]]"
end
out = out .. " | "
local image = entity.claims.P18[1]
if image then
out = out .. "[[File:" .. image.mainsnak.datavalue.value .. "|50px|center]]"
else
out = out .. "subir imagen"
end
out = out .. " | "
local escudo = entity.claims.P94[1]
if escudo then
out = out .. "[[File:" .. escudo.mainsnak.datavalue.value .. "|50px|center]]"
else
out = out .. "subir escudo"
end
out = out .. " | "
local bandera = entity.claims.P41[1]
if bandera then
out = out .. "[[File:" .. bandera.mainsnak.datavalue.value .. "|50px|center]]"
else
out = out .. "subir bandera"
end
out = out .. " | "
end
return out
end
-- Use : {{#invoke:NMSF-AR|getCatCommons|<ID>}}
p.getCatCommons = function(frame)
local itemID = mw.text.trim(frame.args[1] or "")
local entity = mw.wikibase.getEntity(itemID)
local out = ""
if entity and entity.claims then
local category = entity.claims.P373
if category then
out = "[[:c:Category:" .. category[1].mainsnak.datavalue.value .. "|" .. category[1].mainsnak.datavalue.value .. "]]"
end
end
return out
end
-- Use : {{#invoke:NMSF-AR|getCatCommonsRaw|<ID>}}
p.getCatCommonsRaw = function(frame)
local itemID = mw.text.trim(frame.args[1] or "")
local entity = mw.wikibase.getEntity(itemID)
local out = ""
if entity and entity.claims then
local category = entity.claims.P373
if category then
out = category[1].mainsnak.datavalue.value
end
end
return out
end
-- Use : {{#invoke:NMSF-AR|getImage|<ID>|<Prop>}}
p.getImage = function(frame)
local itemID = mw.text.trim(frame.args[1] or "")
local propertyID = mw.text.trim(frame.args[2] or "")
local entity = mw.wikibase.getEntity(itemID)
local out = ""
if entity and entity.claims then
local image = entity.claims[propertyID]
if image then
if image[1].mainsnak.snaktype == "value" then
out = out .. "[[File:" .. image[1].mainsnak.datavalue.value .. "|50px|center]]"
else
out = out .. "No tiene"
end
else
out = out .. "subir imagen"
end
end
return out
end
return p