Модуль:Поиск персоны: различия между версиями

Материал из Кадровый состав НКВД 1935-1939
Перейти к навигации Перейти к поиску
Нет описания правки
Нет описания правки
Строка 19: Строка 19:
end
end
end
end
fio[4] = nil
if #fio>3 then
if fio[5] then
return '<p class=error>Невозможно разобрать. Это точно ФИО?</p>'
return '<p class=error>Невозможно разобрать название статьи. Это точно ФИО?</p>'
end
end
return table.concat( fio, ' ' )
return table.concat( fio, ' ' )
Строка 50: Строка 49:
local out = {}
local out = {}
if not query then
if #query == 0 then
return 'В базе не найдено людей с похожим именем (' .. fio .. ')'
return 'В базе не найдено людей с похожим именем (' .. fio .. ')'
end
end

Версия от 17:17, 22 декабря 2016

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

local pp = {}
local global = mw.ext.luaglobal
local tools = require( 'Module:Tools' )
global.strict( true )

function pp.makePattern( ourName )
	local fio = mw.text.split( ourName, '[%. ]+' )
	if #fio == 1 then
		fio[1] = fio[1] .. ', %'
	else
		if mw.ustring.sub( fio[1], -1, -1) ~= ',' then
			fio[1] = fio[1] .. ','
		end
		if mw.ustring.len( fio[2] ) == 1 then
			fio[2] = fio[2] .. '%'
		end
		if fio[3] and mw.ustring.len( fio[3] ) == 1 then
			fio[3] = fio[3] .. '%'
		end
	end
	if #fio>3 then
		return '<p class=error>Невозможно разобрать. Это точно ФИО?</p>'
	end
	return table.concat( fio, ' ' )
end

pp[''] = function ( frame )
	local ourName = mw.title.getCurrentTitle()
	if ourName.text == ourName.subpageText then
		ourName = ourName.text
	else
		return 'Это подстраница с дополнительными материалами (' .. ourName.baseText .. ')'
	end

	local fio = pp.makePattern( ourName )
--	local queryT = frame:callParserFunction{ name = '#cargo_query', args = { '',
--		tables = 'names',
--		where = 'name LIKE "' .. fio .. '"',
--		fields = 'name,disambig,CONCAT(names._pageName)=pn',
--		limit = '999',
--		format = 'native'
--	} }
--	local query = mw.ext.cargo.get()
	local query = tools.cq( 'names', 'name,disambig,_pageName', {
		where = 'name LIKE "' .. fio .. '"',
		limit = '999',
	} )
	
		
	local out = {}
	if #query == 0 then
		return 'В базе не найдено людей с похожим именем (' .. fio .. ')'
	end
	for  _, pers in ipairs( query ) do
		local fio
		if pers.name == pers._pageName then
			fio = '[[' .. pers._pageName .. ']]'
		elseif pers.name .. ' ' .. pers.disambig == pers._pageName then
			fio = '[[' .. pers._pageName .. '|' .. pers.name .. ' <span class="nkvd-idx">' .. pers.disambig .. '</span>]]'
		elseif pers.disambig == '' then
			fio = pers.name .. ' (<i>он же</i> [[' .. pers._pageName .. ']])'
		else
			fio = pers.name .. ' <span class="nkvd-idx">' .. pers.disambig .. '</span> (<i>он же</i> [[' .. pers._pageName .. ']])'
		end
		table.insert( out, fio )
	end
	return 'Возможно, вас интересует одна из следующих персоналий: ' .. '(' .. fio .. '/' .. #query .. ') '
		.. table.concat( out, ' &bull; ' )

end
return pp