Module:références
Apparence
La documentation pour ce module peut être créée à Module:références/Documentation
local m_params = require("Module:paramètres")
local m_table = require("Module:table")
local data = require("Module:références/data")
local p = {}
function _getQidFromLabel(label)
if mw.ustring.match(label, "^Q[1-9][0-9]*$") then
return label
else
return data[label]
end
end
function _reference(label, entryName)
local res = "« " .. entryName .. " », dans ''"
local qid = _getQidFromLabel(label)
local qitem = mw.wikibase.getEntity(qid)
local title = qitem:getLabel('fr')
local sitelink = qitem:getSitelink('frwiki')
local wp_name = ""
if sitelink then
wp_name = sitelink
else
local entity = qitem:getAllStatements('P629')
mw.logObject(entity)
if #entity > 0 then
local eid = entity[1]['mainsnak']['datavalue']['value']['id']
local eitem = mw.wikibase.getEntity(eid)
local sitelink = eitem:getSitelink('frwiki')
if sitelink then
wp_name = sitelink
end
end
end
if wp_name and wp_name ~= "" then
title = mw.getCurrentFrame():expandTemplate{title='w', args={[1]=wp_name}}
end
res = res .. title
local lang = mw.getLanguage('fr')
local dates = qitem:getAllStatements('P577')
if #dates > 0 then
local date = mw.ustring.sub(dates[1]['mainsnak']['datavalue']['value']['time'], 2, 5)
res = res .. "'', " .. date
end
local links = qitem:getAllStatements('P4354')
if #links > 0 then
local link = links[1]['mainsnak']['datavalue']['value']
res = res .. " → [" .. mw.ustring.gsub(link, '$1', entryName) .. " consulter cet ouvrage]"
end
return res
end
function p.reference(frame)
local params = m_params.process(frame:getParent().args, {
[1] = { required = true },
["entrée"] = { required = true }
})
local label = params[1]
local entryName = params["entrée"] or mw.title.getCurrentTitle().text
return _reference(label, entryName)
end
function p.project_list(frame)
local params = m_params.process(frame:getParent().args, {
[1] = { required = true },
[2] = { required = true }
})
local lang = params[1]
local id = params[2]
local qitem = mw.wikibase.getEntity(id)
local res = '*' .. frame:expandTemplate{ title = 'WD', args = { id }}
local sitelink = qitem:getSitelink(lang .. 'wiki')
if sitelink then
res = res .. '\n*' .. frame:expandTemplate{ title = 'WP', args = { sitelink, lang = lang }}
end
sitelink = qitem:getSitelink(lang .. 'wikisource')
if sitelink then
res = res .. '\n*' .. frame:expandTemplate{ title = 'WS', args = { sitelink, lang = lang }}
end
sitelink = qitem:getSitelink('commonswiki')
if sitelink then
res = res .. '\n*' .. frame:expandTemplate{ title = 'Commons', args = { sitelink }}
end
sitelink = qitem:getSitelink('specieswiki')
if sitelink then
res = res .. '\n*' .. frame:expandTemplate{ title = 'WSP', args = { sitelink }}
end
sitelink = qitem:getSitelink(lang .. 'wikiquote')
if sitelink then
res = res .. '\n*' .. frame:expandTemplate{ title = 'WQ', args = { sitelink, lang = lang }}
end
sitelink = qitem:getSitelink(lang .. 'wikivoyage')
if sitelink then
res = res .. '\n*' .. frame:expandTemplate{ title = 'VOY', args = { sitelink, lang = lang }}
end
sitelink = qitem:getSitelink(lang .. 'wikiversity')
if sitelink then
res = res .. '\n*' .. frame:expandTemplate{ title = 'WV', args = { sitelink, lang = lang }}
end
sitelink = qitem:getSitelink(lang .. 'wikibooks')
if sitelink then
res = res .. '\n*' .. frame:expandTemplate{ title = 'WB', args = { sitelink, lang = lang }}
end
return res
end
return p