Diferencia entre revisiones de «Módulo:Formato texto»

Contenido eliminado Contenido añadido
Añadiendo nueva función extendida
m Cambió la configuración de protección de «Módulo:Formato texto»: Módulo o plantilla muy utilizado/sensible ([Editar=Permitir solo editores de plantillas y administradores] (indefinido))
 
(No se muestran 17 ediciones intermedias de 2 usuarios)
Línea 98:
 
-- Generar un enlace (implementación extendida)
-- @param enlace string En enlace a analizar
-- @param opciones mixed Las opciones, según lo siguiente:
-- @param opciones string La etiqueta (texto alternativo) del enlace
-- @param opciones table Tabla (array) de opciones, según lo siguiente
-- @param opciones['etiqueta'] string La etiqueta (texto alternativo) del enlace
-- @param opciones['namespace'] number El espacio de nombres en formato numérico (donde 6 es "Archivo:")
-- @param opciones['tamaño'] string El tamaño de la imagen en el caso de enlaces en espacio de nombres 6
-- @param opciones['calificativo'] string Texto adicional entre paréntesis, en tamaño de fuente más pequeño
-- (no aplicado a namespace 6)
-- @param opciones['debe existir'] bool Si es true, comprobar si el destino existe y devolver el enlace formateado,
-- de lo contrario, devolver solo la etiqueta.
-- Si es false o nil, devolver el enlace formateado aún si el destino no existe.
 
function z.enlazar2(enlace, opciones)
if enlace and opciones then
local etiqueta, namespace, tamano, calificativoborde, enlace2, pieImagen, debeExistir, solotexto
 
if type(opciones) == 'stringtable' then
etiqueta = opciones
elseif type(opciones) == 'table' then
etiqueta = opciones['etiqueta'] or ''
namespace = tonumber(opciones['namespace']) or 0
tamano = opciones['tamaño'] or '250px'
calificativoborde = opciones['calificativoborder'] or opciones['borde']
enlace2 = opciones['link']
pieImagen = opciones['pie']
debeExistir = opciones['debe existir'] or opciones['debeExistir'] or opciones['debeexistir']
solotexto = opciones['solotexto']
elseif type(opciones) == 'tablestring' then
etiqueta = opciones
elseif type(opciones) == 'number' then
namespace = opciones
else
etiqueta = enlace
return
namespace = 0
end
 
local tituloObj = mw.title.new(enlace, namespace) or {}
 
if not debeExistir then return '[[' .. tituloObj.fullText .. '|' .. etiqueta .. ']]' end
local titulo2Obj = {}
if enlace2 then titulo2Obj= mw.title.new(enlace2, 0) end
 
local resultado = {}
 
table.insert(resultado, tituloObj.fullText)
 
if not debeExistir and namespace ~= 6 and namespace ~= 14 then
if etiqueta then table.insert(resultado, etiqueta) end
if calificativo then return '[[' .. tituloObj.fullTextprefix .. table.concat(resultado, '|' .. etiqueta) .. ']]' .. ' <small>(' .. calificativo .. ')</small>' end
return '[[' .. table.concat(resultado, '|') .. ']]'
end
 
if tituloObj.exists or tituloObj.fileExists then
-- Archivo:
if namespace == 6 then return '[[' .. tituloObj.fullText .. '|' .. tamano .. '|' .. etiqueta .. ']]' end
if namespace == 6 then
if calificativo then return '[[' .. tituloObj.fullText .. '|' .. etiqueta .. ']]' .. ' <small>(' .. calificativo .. ')</small>' end
if solotexto then
return '[[' .. tituloObj.fullText .. '|' .. etiqueta .. ']]'
if etiqueta then table.insert(resultado, etiqueta) end
return '[[:' .. table.concat(resultado, '|') .. ']]'
end
if tamano then table.insert(resultado, tamano) end
if borde then table.insert(resultado, 'border') end
if titulo2Obj.exists then table.insert(resultado, 'link=' .. titulo2Obj.fullText) end
if etiqueta then table.insert(resultado, etiqueta) end
if pieImagen then return '[[' .. table.concat(resultado, '|') .. ']]' .. '<br>' .. pieImagen end
return '[[' .. table.concat(resultado, '|') .. ']]'
end
-- Categoría:
if namespace == 14 then
if solotexto then
if etiqueta then table.insert(resultado, etiqueta) end
return '[[:' .. table.concat(resultado, '|') .. ']]'
end
if not debeExistir then return '[[' .. tituloObj.fullText .. '|' .. etiqueta .. ']]' end
end
 
-- El resto
if etiqueta then table.insert(resultado, etiqueta) end
return '[[' .. table.concat(resultado, '|') .. ']]'
 
end
 
return etiqueta
end