Módulo:Enlaces
Apariencia
[editar] [ ]
Documentación del módulo
|wikipedia=
o |wikcionario=
) como de Wikidata.Esta documentación está transcluida desde Módulo:Enlaces/doc.
Los editores pueden experimentar en la zona de pruebas de este módulo.
Por favor, añade las categorías e interwikis a la subpágina de documentación. Subpáginas de este módulo.
Los editores pueden experimentar en la zona de pruebas de este módulo.
Por favor, añade las categorías e interwikis a la subpágina de documentación. Subpáginas de este módulo.
--The sister project linking module
local p = {}
local Wikidata = require('Módulo:Wikidata')
local function getsize(tab)
count=0
for _,_ in pairs(tab) do
count=count+1
end
return count
end
local aliases = {
['commons'] = 'commonswiki',
['commonscat'] = 'commonswiki',
['wikilibros'] = 'eswikibooks',
['wikibooks'] = 'eswikibooks',
['wikinoticias'] = 'eswikinews',
['wikinews'] = 'eswikinews',
['wikipedia'] = 'eswiki',
['wikiquote'] = 'eswikiquote',
['wikicitas'] = 'eswikiquote',
['wikispecies'] = 'specieswiki',
['wikiespecies'] = 'specieswiki',
['wikiversity'] = 'eswikiversity',
['wikiversidad'] = 'eswikiversity',
['desambiguación'] = 'desambiguacion',
['wiktionary'] = 'eswiktionary',
['wikcionario'] = 'eswiktionary'
}
p.relevants = { --{['name']='',['image']='',['text']='',['prefix']='',}
['commonswiki'] = { ['name'] = 'Wikimedia Commons',
['image'] = 'Commons-logo.svg|link=c:',
['text'] = 'multimedia',
['prefix'] = 'c:',
['title'] = '',
},
['eswikibooks'] = { ['name'] = 'Wikibooks',
['image'] = 'Wikibooks-logo.svg|link=wikibooks:',
['text'] = 'libro',
['prefix'] = 'wikibooks:es:',
['title'] = '',},
['eswikinews'] = { ['name'] = 'Wikinews',
['image'] = 'Wikinews-logo.svg|link=wikinews:',
['text'] = 'noticias',
['prefix'] = 'wikinews:es:',
['title'] = '',},
['eswiki'] = { ['name'] = 'Wikipedia',
['image'] = 'Wikipedia-logo-simple.png|link=w:',
['text'] = 'artículo enciclopédico',
['prefix'] = 'w:es:',
['title'] = '',},
['eswiktionary'] = { ['name'] = 'Wiktionary',
['image'] = 'Wiktionary-logo.svg|link=wikt:',
['text'] = 'diccionario',
['prefix'] = 'wikt:es:',
['title'] = '',},
['eswikiquote'] = { ['name'] = 'Wikiquote',
['image'] = 'Wikiquote-logo.svg|link=wikiquote:',
['text'] = 'citas',
['prefix'] = 'wikiquote:es:',
['title'] = '',},
['specieswiki'] = { ['name'] = 'Wikispecies',
['image'] = 'Wikispecies-logo.svg|link=species:',
['text'] = 'taxonomía',
['prefix'] = 'species:',
['title'] = '',},
['eswikiversity'] = { ['name'] = 'Wikiversity',
['image'] = 'Wikiversity-logo.svg|link=wikiversity:',
['text'] = 'clase',
['prefix'] = 'wikiversity:es:',
['title'] = '',},
['wikidata'] = { ['name'] = 'Wikidata',
['image'] = 'Wikidata-logo.svg|link=d:',
['text'] = 'metadatos',
['prefix'] = 'd:',
['title'] = '',},
['desambiguacion']= { ['name'] = 'Desambiguación',
['image'] = 'Disambiguation.svg',
['text'] = 'títulos similares u otras versiones',
['prefix'] = '',
['title'] = '',},
}
-- Function for getting the text for the project
local function getProjectText( frame ) --sin uso
local projecttext = {
['commons'] = '[[c:|Wikimedia Commons]] has [[media]] related to:',
['wikibooks'] = 'The [[wikibooks:|English Wikibooks]] has more information on:',
['wikinews'] = 'The [[wikinews:|English Wikinews]] has news articles on:',
['wikipedia'] = 'The [[w:|Simple English Wikipedia]] has an article on:',
['wikiquote'] = 'The [[wikiquote:|English Wikiquote]] has a collection of quotations related to:',
['wikisource'] = 'The [[wikisource:|English Wikisource]] has original writing on:',
['wikispecies'] = '[[wikispecies:|Wikispecies]] has more information on:',
['wikiversity'] = 'The [[wikiversity:|English Wikiversity]] has learning resources on:',
['wikivoyage'] = 'The [[wikivoyage:|English Wikivoyage]] has travel guides about:',
}
return projecttext[ frame.args[ 'project' ] ]
end
-- toma los enlaces directamente desde los parámetros de la plantilla. Ejemplo, |Wikipedia= en {{encabezado}}
function p.getlinksfromargs( args, relevantsList )
local lang = mw.language.getContentLanguage()
local output = relevantsList
for key, value in pairs( args ) do
if value ~='' then
key = lang:lcfirst(tostring(key))
if (aliases[key]) then
key=aliases[key] --si hay alias, usarlo
end
if (output[key]) then
output[key]["title"] = value
end
end
end
return output
end
function p.getlinksfromwikidata(relevantsList, QID )
local lang = mw.language.getContentLanguage()
local output = relevantsList
local Entidad = mw.wikibase.getEntityObject(QID)
if Entidad then
output["wikidata"]["title"]=Entidad.id
if Entidad["sitelinks"] and getsize(Entidad["sitelinks"]) > 1 then
for k, v in pairs(Entidad["sitelinks"]) do
if output[k] then
output[k]["title"]=v["title"]
end
end
elseif Entidad["claims"] and Entidad["claims"]["P629"] then
-- edición de...
local P629 = Entidad["claims"]["P629"][1]["mainsnak"]["datavalue"]["value"]["id"]
newEntidad = mw.wikibase.getEntityObject(P629)
newEntidad["sitelinks"] = newEntidad["sitelinks"] or {} --inicializar en caso de obras originales sin sitelinks
for k, v in pairs(newEntidad["sitelinks"]) do
if output[k] then
output[k]["title"]=v["title"]
end
end
end
-- categoría en commons
if output['commonswiki']['title'] == '' and Entidad["claims"] and Entidad["claims"]["P373"] then
output['commonswiki']['title'] = 'Category:'..Entidad["claims"]["P373"][1]["mainsnak"]["datavalue"]["value"]
end
end
return output
end
--todos los enlaces
function p.all(args)
local QID
if args.wikidata and args.wikidata ~= '' then
QID = args.wikidata
else
QID = mw.wikibase.getEntityIdForCurrentPage()
end
-- Wikidata y luego args, en ese orden
local output = p.getlinksfromwikidata(p.relevants, QID)
output = p.getlinksfromargs( args, output )
return output
end
function p.formattedlinks (relevantList)
linklist = {}
for k, v in pairs(relevantList) do
if v.title ~= '' then
link = '<span style="white-space:nowrap;">'
if v.image then
link = link..'[[File:'.. v.image ..'|16px]] '
end
link = link..'[[' .. v.prefix .. v.title .. '|' .. v.text .. ']]</span>'
table.insert(linklist, link)
end
end
local noofwords = table.maxn( linklist )
if (noofwords == 0) then
output = ''
elseif ( noofwords == 1 ) then
output = linklist[1] .. '.'
else
output = table.concat( linklist, ' ', 1, noofwords ) .. '.'
end
return ( output )
end
--funcion para {{biocitas}}
function p.formattedbiocitas (relevantList, order)
linklist = {}
for _, x in pairs(order) do
local v = relevantList[x]
if v and v["title"] ~= '' then
link = '<div class="bc-enlace">[[File:'..v['image']..
'|16px]]<span style=\'display:inline-block; width:.5em;\'> </span>[[' ..
v['prefix'] .. v['title'] .. '|' .. v['text'] .. ']]</div>'
table.insert(linklist, link)
end
end
local noofwords = table.maxn( linklist )
if (noofwords == 0) then
output = ''
else
output = table.concat( linklist, '\n', 1, noofwords )
end
return ( output )
end
-- The main function to run the module
function p.main( frame )
local output = ''
local links = {}
links = p.all(frame)
output = p.formattedlinks(links)
return output
end
return p