Модуль:LinksOut
Материал из Указатель частей и соединений РККА 1941-1945
Для документации этого модуля может быть создана страница Модуль:LinksOut/doc
local linksout = {}
local cargo = mw.ext.cargo
local ref = require( 'Module:Ref' )
local mediaproc = {
['1'] = function ( link )
return 'Статья «<i>[[вп:' .. link .. '|' .. link .. ']]</i>» в Википедии'
end,
['2'] = function ( link )
return 'Статья «<i>[http://allaces.ru' .. link .. ']</i>» на сайте <i>allaces.ru</i>'
end,
['3'] = function ( link )
return 'Статья «<i>[https://www.proza.ru' .. link .. ']</i>» Владимира Савончика'
end,
}
function linksout.collect( names )
local where = 'unit="' .. table.concat( names, '" OR unit="' ) .. '"'
local query = cargo.query(
'ext_links',
'unit, media, link, addendum, ref',
{
where = where,
orderBy = 'media, link',
} )
if #query ~= 0 then
local out = {}
local adds, refs = {}, {}
for i = 1, #query do
local dsc = query[i]
if dsc.addendum ~= '' then
table.insert( adds, dsc.addendum )
end
if dsc.ref ~= '' then
table.insert( refs, dsc.ref )
end
if i == #query or dsc.media ~= query[i+1].media or dsc.link ~= query[i+1].link then
table.insert( out, '* ' .. mediaproc[dsc.media]( dsc.link ) )
if #refs ~= 0 then
ref.refStart()
for _, refer in ipairs( refs ) do
table.insert( out, ref.use( refer ) )
end
ref.refReturn()
end
table.insert( out, '. ' .. table.concat( adds, ' ' ) .. '\n' )
adds, refs = {}, {}
end
end
return table.concat( out )
end
end
return linksout