Изменения

Модуль:Карточка

3943 байта добавлено, 07:56, 7 августа 2016
Новая страница: «local p = {} function p.infobox( f ) local args = require( 'Модуль:ProcessArgs' ).merge( true ) local titleObject = mw.title.getCurrentTitle() local titl…»
local p = {}
function p.infobox( f )
local args = require( 'Модуль:ProcessArgs' ).merge( true )
local titleObject = mw.title.getCurrentTitle()
local title = args['название'] or titleObject.baseText

local imageArea = args["изображения"]
if not imageArea and imageArea ~= 'none' then
local images = {}
local invImages = {}
local defaultImageSize = args["умолчразмеризобр"] or '150px'
args["изображение1"] = args["изображение1"] or args["изображение"] or 'title'
args["изобр1разм"] = args["изобр1разм"] or args["изобрразм"]
args["инвизображение1"] = args["инвизображение1"] or args["инвизображение"] or 'title'

local imgCount = {}
local invImgCount = {}
local grid
for k, v in pairs( args ) do
if type( k ) == 'string' then
local image, num = mw.ustring.match(k, '^(изображение)(%d+)$' )
local invImage, invNum = mw.ustring.match(k, '^(инвизображение)(%d+)$' )
if mw.ustring.lower(v) ~= 'нет' then
if image then
table.insert( imgCount, tonumber( num ) )
elseif invImage then
table.insert( invImgCount, tonumber( invNum ) )
end
end
end
end

table.sort( imgCount )
local animate
for k, v in ipairs( imgCount ) do
local image = args['изображение' .. v]
local size = args['изобр' .. v .. 'разм'] or defaultImageSize

if image == 'title' then
local imageTitle = mw.title.new( 'Файл:' .. title .. '.png' )
if imageTitle and imageTitle.exists then
image = '[[Файл:' .. title .. '.png|' .. size .. ']]'
elseif titleObject.namespace == 0 then
image = '[[Файл:No image.svg|' .. size .. '|link=Файл:' .. title .. '.png|Загрузить ' .. title .. '.png]]'
else
image = '[[Файл:No image.svg|' .. size .. '|link=]]'
end
elseif mw.ustring.match(image, ';' ) then
if not animate then
animate = require( 'Модуль:Анимация' ).animate
end
image = animate{ image, size }
else
image = '[[Файл:' .. image .. '|' .. size .. ']]'
end

table.insert( images, '<div>' .. image .. '</div>' )
end
images = table.concat( images, '\n' )

if #invImgCount > 0 then
table.sort( invImgCount )
local grid
for k, v in ipairs( invImgCount ) do
local image = args['инвизображение' .. v]
if image == 'title' then
local imageTitle = mw.title.new( 'Файл:Grid ' .. title .. '.png' )
if imageTitle and imageTitle.exists then
image = title
else
image = false
end
end

if image == '----' then
table.insert( invImages, '</div><div style="padding-top:.5em">' )
elseif image then
if not grid then
grid = require( 'Модуль:Сетка' ).cell
end
table.insert( invImages, grid{ image, ['ссылка'] = 'нет' } )
end
end

if grid and #invImages > 0 then
invImages = '<div class="infobox2-invimages"><div>' .. table.concat( invImages, '' ) .. '</div></div>'
else
invImages = ''
end
else
invImages = ''
end

if images ~= '' or invImages ~= '' then
imageArea = images .. '\n' .. invImages
else
imageArea = 'нет'
end
end
if imageArea and imageArea ~= 'нет' then
imageArea = '<div class="infobox2-imagearea">' .. imageArea .. '</div>'
else
imageArea = ''
end

local footer = args["подвал"]
if footer then
footer = '| class="infobox2-footer" colspan="2" | ' .. footer
end

local html = {
'<div class="notaninfobox2">',
'<div class="mcwiki-header infobox2-title">' .. title .. '</div>',
imageArea,
'{| class="infobox2-rows" cellspacing="1" cellpadding="4"',
'|-',
args["ряды"] or '',
footer or '',
'|}',
'</div>'
}

return table.concat( html, '\n' )
end

return p