Модуль:Ссылки

Материал из Кадровый состав НКВД 1935-1939
Перейти к навигации Перейти к поиску

Для документации этого модуля может быть создана страница Модуль:Ссылки/doc

local p = {}
tools = require( 'Модуль:Tools' )
local global = mw.ext.luaglobal;

p[''] = function ( frame )
	local Args, tmp = tools.checkargs( frame:getParent().args,
        { ['публикация'] = true, ['источник'] = true, ['архив'] = true, } )
    if not Args then
		return tools.errorMsg( 'Ссылки', 'Неизвестный параметр «' .. tmp .. '»', '' )
    end
	local out = {}
	if Args['публикация'] then
		out[#out+1] = 'опубликовано: <span class="nkvd-value">' 
			.. Args['публикация'] .. '</span>'
	end
	if Args['источник'] then
		out[#out+1] = 'воспроизводится по: <span class="nkvd-value">' 
			.. Args['источник'] .. '</span>'
	end
	if Args['архив'] then
		out[#out+1] = '<span class="nkvd-value">' 
			.. Args['архив'] .. '</span>'
	end
	return '<span class="nkvd-links">' .. table.concat( out, ' &bull; ' ) .. '</span>'
end

local function header( Args )
	local out 
	if Args['первоисточник'] then
		out = '<span class="nkvd-value">' .. Args['первоисточник'] 
			.. '</span> (цит. по: <span class="nkvd-value">' 
			.. ( Args[1] or Args['источник'] ) .. '</span>)'
	else
		out = '<span class="nkvd-value">' .. ( Args[1] or Args['источник'] ) .. '</span>'
	end
	if Args['архив'] then
		if out then
			out = out .. '; '
		else
			out = ''
		end
		out = out .. '<span class="nkvd-archive">' ..  Args['архив'] .. '</span>'
	end
	return '<span class="nkvd-links">' .. out .. tools.commonParams( Args['дополнение'], Args['сноска']  )
		.. '</span>'
end

local function endCite()
	return [[
      </div>
      <div style="display: table-cell; padding: 2px; width: 80px; text-align: center; vertical-align: bottom; "><i class="fa fa-quote-right fa-3x" style="color: #AEC8A9; "></i></div>
    </div>
  </div>
</div>
]]
end	

p.Main = function ( frame )
	local Args, tmp = tools.checkargs( frame:getParent().args,
        { true, ['первоисточник'] = true, ['источник'] = true, ['архив'] = true, 
        	['дополнение'] = true, ['сноска'] = true, } )
    if not Args then
		return tools.errorMsg( 'ссылка', 'Неизвестный параметр «' .. tmp .. '»', '' )
    end
	if Args[1] and Args['источник'] then
		return tools.errorMsg( 'ссылка', 'Источник задан и как позиционный параметр, и как ключевой', '' )
	end
	return header( Args )
end

p.Cite = function ( frame )
	local Args, tmp = tools.checkargs( frame:getParent().args,
        { true, ['заголовок'] = true, ['текст'] = true,
        	['первоисточник'] = true, ['источник'] = true, ['архив'] = true, 
        	['дополнение'] = true, ['сноска'] = true, } )
    if not Args then
		return tools.errorMsg( 'ссылка', 'Неизвестный параметр «' .. tmp .. '»', '' )
	end
	if Args[1] == 'конец' then
		return endCite()
	end
	
	if Args[1] and ( Args['источник'] or Args['заголовок'] ) then
		return tools.errorMsg( 'ссылка', 'Параметры «заголовок» и «источник» не могут использоваться при наличии позиционного (безымянного) параметра', '' )
	end
	if Args['заголовок'] and ( Args[1] or Args['источник'] or Args['первоисточник'] or Args['архив'] or Args['дополнение'] ) then
		return tools.errorMsg( 'ссылка', 'Если задан параметр «заголовок», то  «источник» и другие параметры для автоматического формирования заголовка не могут использоваться', '' )
	end
	local out = [[
<div style="width: 100%; max-width: 1000px; background-color: #e8f0e6; ">
  <div style="display: table; ">
    <div style="display: table-caption; background-color: #B9C7B7; padding: 4px; ">]]
    	.. ( Args['заголовок'] or header( Args ) ) .. [[</div>
    <div style="display:table-row; ">
      <div style="display: table-cell; padding: 2px; width: 80px; text-align: center; vertical-align: top; "><i class="fa fa-quote-left fa-3x" style="color:#AEC8A9; "></i></div>
      <div style="display: table-cell; padding: 2px; ">
]]      
	if Args['текст'] then
		return out .. Args['текст'] .. endCite()
	end
	return out
end

local function endCite1()
	return [[
      </div>
      <div style="display: table-cell; padding: 2px; width: 80px; text-align: center; vertical-align: bottom; "><i class="fa fa-quote-right fa-3x" style="color: #AEC8A9; "></i></div>
    </div>
    <div style="display: table-row; ">
      <div style="display: table-cell; padding: 2px;  width: 80px; "></div>
      <div style="display: table-cell; padding: 2px; ">
        <hr>
        <p style="text-align:right">]] .. global.get( 'Cite1' ) .. [[</p>
      </div>
      <div style="display: table-cell; padding: 2px; width: 80px; "></div>
    </div>
  </div>
</div>
]]
end

p.Cite1 = function ( frame )
	local Args, tmp = tools.checkargs( frame:getParent().args,
        { true, ['заголовок'] = true, ['текст'] = true,
        	['первоисточник'] = true, ['источник'] = true, ['архив'] = true, 
        	['дополнение'] = true, ['сноска'] = true, } )
    if not Args then
		return tools.errorMsg( 'ссылка', 'Неизвестный параметр «' .. tmp .. '»', '' )
	end
	if Args[1] == 'конец' then
		return endCite1()
	end
	
	if Args[1] and ( Args['источник'] or Args['заголовок'] ) then
		return tools.errorMsg( 'ссылка', 'Параметры «заголовок» и «источник» не могут использоваться при наличии позиционного (безымянного) параметра', '' )
	end
	if Args['заголовок'] and ( Args[1] or Args['источник'] or Args['первоисточник'] or Args['архив'] or Args['дополнение'] ) then
		return tools.errorMsg( 'ссылка', 'Если задан параметр «заголовок», то  «источник» и другие параметры для автоматического формирования заголовка не могут использоваться', '' )
	end
	global.set( 'Cite1', Args['заголовок'] or header( Args ) )
	local out = [[
<div style="width: 100%; max-width: 1000px; background-color: #e8f0e6; ">
  <div style="display: table; ">
    <div style="display: table-row; ">
      <div style="display: table-cell; padding: 2px; width: 80px; text-align: center; vertical-align: top; "><i class="fa fa-quote-left fa-3x" style="color: #AEC8A9; "></i></div>
      <div style="display:table-cell;padding:2px; ">
]]      
	if Args['текст'] then
		return out .. Args['текст'] .. endCite1()
	end
	return out
end	

return p