Модуль:Поиск персоны
Перейти к навигации
Перейти к поиску
Для документации этого модуля может быть создана страница Модуль:Поиск персоны/doc
local pp = {}
local global = mw.ext.luaglobal
local tools = require( 'Module:Tools' )
global.strict( true )
pp[''] = function ( frame )
local ourName = mw.title.getCurrentTitle()
if ourName.text == ourName.subpageText then
ourName = ourName.text
else
return 'Это подстраница с дополнительными материалами (' .. ourName.baseText .. ')'
end
local fio = mw.text.split( ourName, '[%. ]+' )
local where
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
fio[4] = nil
if fio[5] then
return '<p class=error>Невозможно разобрать название статьи. Это точно ФИО?</p>'
end
fio = table.concat( fio, ' ' )
-- 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 not query 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, ' • ' )
end
return pp