Modulus:Vicidata
Appearance
Documentation for this module may be created at Modulus:Vicidata/doc
local multilinguia = {
commonswiki = true,
foundationwiki = true,
incubatorwiki = true,
mediawikiwiki = true,
sourceswiki = true, -- old wikisource
specieswiki = true,
wikidatawiki = true
}
local ifacies = {}
ifacies.qid = function (frame)
local titulus
local situs
if frame.args[1] ~= nil then titulus = frame.args[1]:match'^%s*(.*%S)' end
if frame.args[2] ~= nil then situs = frame.args[2]:match'^%s*(.*%S)' end
if situs ~= nil then
if titulus == nil then titulus = frame:getParent():getTitle() end
return mw.wikibase.getEntityIdForTitle(titulus, situs)
end
if titulus == nil then return mw.wikibase.getEntityIdForCurrentPage() end
return mw.wikibase.getEntityIdForTitle(titulus)
end
ifacies.quantae_translationes = function (frame)
local titulus
local qid
local situs
if frame.args.qid ~= nil then qid = frame.args.qid:match'^%s*(.*%S)' end
if qid == nil then
if frame.args.pagina ~= nil then titulus = frame.args.pagina:match'^%s*(.*%S)' end
if titulus == nil then qid = mw.wikibase.getEntityIdForCurrentPage()
else qid = mw.wikibase.getEntityIdForTitle(titulus) end
if not qid then return '0' end
end
local entitas = mw.wikibase.getEntity(qid)
if not entitas or not entitas.sitelinks then return '0' end
local num = 0
for _ in pairs(entitas.sitelinks) do num = num + 1 end
return tostring(num)
end
ifacies.si_sunt_translationes = function (frame)
local titulus
local qid
local situs
if frame.args.qid ~= nil then qid = frame.args.qid:match'^%s*(.*%S)' end
if qid == nil then
if frame.args.pagina ~= nil then titulus = frame.args.pagina:match'^%s*(.*%S)' end
if titulus == nil then qid = mw.wikibase.getEntityIdForCurrentPage()
else qid = mw.wikibase.getEntityIdForTitle(titulus) end
if not qid then return frame.args[2] or '' end
end
local entitas = mw.wikibase.getEntity(qid)
if not entitas or not entitas.sitelinks then return frame.args[2] or '' end
local plures = false
for _ in pairs(entitas.sitelinks) do
if plures then return frame.args[1] or '' end
plures = true
end
return frame.args[2] or ''
end
ifacies.si_sunt_translationes_interviciales = function (frame)
local titulus
local qid
local situs
if frame.args.qid ~= nil then qid = frame.args.qid:match'^%s*(.*%S)' end
if qid == nil then
if frame.args.pagina ~= nil then titulus = frame.args.pagina:match'^%s*(.*%S)' end
if titulus == nil then qid = mw.wikibase.getEntityIdForCurrentPage()
else qid = mw.wikibase.getEntityIdForTitle(titulus) end
if not qid then return frame.args[3] or frame.args[2] or '' end
end
local entitas = mw.wikibase.getEntity(qid)
if not entitas or not entitas.sitelinks then return frame.args[3] or frame.args[2] or '' end
local speciales = false
for _, sitelink in pairs(entitas.sitelinks) do
situs = sitelink.site
if situs ~= 'lawiki' then
n_situs = situs:len()
if not multilinguia[situs] and n_situs > 3 and situs:sub(n_situs - 3) == 'wiki' then
return frame.args[1] or ''
end
speciales = true
end
end
if speciales and frame.args[3] then return frame.args[2] end
return frame.args[3] or frame.args[2] or ''
end
ifacies.index_translationum = function (frame)
local titulus
local qid
local situs
if frame.args.qid ~= nil then qid = frame.args.qid:match'^%s*(.*%S)' end
if qid == nil then
if frame.args.pagina ~= nil then titulus = frame.args.pagina:match'^%s*(.*%S)' end
if titulus == nil then qid = mw.wikibase.getEntityIdForCurrentPage()
else qid = mw.wikibase.getEntityIdForTitle(titulus) end
if not qid then return '' end
end
local entitas = mw.wikibase.getEntity(qid)
if not entitas or not entitas.sitelinks then return '' end
local index = {}
for _, sitelink in pairs(entitas.sitelinks) do
situs = sitelink.site
if situs == 'mediawikiwiki' then situs = 'mwwiki' end
n_situs = situs:len()
if n_situs > 3 and situs:sub(n_situs - 3) == 'wiki' then
if situs ~= 'lawiki' then
table.insert(index, '\n* [[:' ..
situs:sub(1, n_situs - 4):gsub('_', '-') .. ':' ..
sitelink.title .. ']]')
end
elseif n_situs > 9 and situs:sub(n_situs - 9) == 'wikisource' then
table.insert(index, '\n* [[:s:' ..
situs:sub(1, n_situs - 10):gsub('_', '-') .. ':' ..
sitelink.title .. ']]')
elseif n_situs > 8 and situs:sub(n_situs - 8) == 'wikiquote' then
table.insert(index, '\n* [[:q:' ..
situs:sub(1, n_situs - 9):gsub('_', '-') .. ':' ..
sitelink.title .. ']]')
elseif n_situs > 10 and situs:sub(n_situs - 10) == 'wikiversity' then
table.insert(index, '\n* [[:wikiversity:' ..
situs:sub(1, n_situs - 11):gsub('_', '-') .. ':' ..
sitelink.title .. ']]')
elseif n_situs > 9 and situs:sub(n_situs - 9) == 'wikivoyage' then
table.insert(index, '\n* [[:wikivoyage:' ..
situs:sub(1, n_situs - 10):gsub('_', '-') .. ':' ..
sitelink.title .. ']]')
else
table.insert(index, '\n* [[:' .. situs .. ':' .. sitelink.title ..
']]')
end
end
table.sort(index)
return table.concat(index, '')
end
ifacies.titulus_barbarus = function (frame)
local titulus
local qid
local titulus
local situs
if frame.args[1] ~= nil then situs = frame.args[1]:match'^%s*(.*%S)' end
if situs == nil then error(frame:getTitle() .. ', ‘titulus_barbarus’: Situs abest', 0) end
if frame.args.qid ~= nil then qid = frame.args.qid:match'^%s*(.*%S)' end
if qid == nil then
if frame.args.pagina ~= nil then titulus = frame.args.pagina:match'^%s*(.*%S)' end
if titulus == nil then qid = mw.wikibase.getEntityIdForCurrentPage()
else qid = mw.wikibase.getEntityIdForTitle(titulus) end
if not qid then return '' end
end
local entitas = mw.wikibase.getEntity(qid)
if not entitas or not entitas.sitelinks then return '' end
local index = {}
for _, sl in pairs(entitas.sitelinks) do index[sl.site] = sl.title end
return index[situs] or ''
end
return ifacies