Модуль:Поиск персоны: различия между версиями
Перейти к навигации
Перейти к поиску
StasR (обсуждение | вклад) Нет описания правки |
StasR (обсуждение | вклад) Нет описания правки |
||
Строка 22: | Строка 22: | ||
end | end | ||
fio[4] = nil | fio[4] = nil | ||
if fio[5] then | |||
return '<p class=error>Невозможно разобрать название статьи. Это точно ФИО?</p>' | |||
end | |||
fio = table.concat( fio, ' ' ) | fio = table.concat( fio, ' ' ) | ||
local queryT = frame:callParserFunction{ name = '#cargo_query', args = { '', | local queryT = frame:callParserFunction{ name = '#cargo_query', args = { '', |
Версия от 10:24, 13 ноября 2016
Для документации этого модуля может быть создана страница Модуль:Поиск персоны/doc
local pp = {}
local global = mw.ext.luaglobal
local tools = require( 'Module:Tools' )
global.strict( true )
pp[''] = function ( frame )
local ourName = mw.title.getCurrentTitle().text
local fio = mw.text.split( ourName .. ' ', '[%. ]+' )
local where
if #fio == 1 then
where = 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 out = {}
if not query then
return 'В базе не найдено людей с похожим именем (' .. fio .. ')'
end
for _, pers in ipairs( query ) do
if pers.name == pers.pn then
fio = '[[' .. pers.pn .. ']]'
elseif pers.name .. ' ' .. pers.disambig == pers.pn then
fio = '[[' .. pers.pn .. '|' .. pers.name .. ' <span class="nkvd-idx">' .. pers.disambig .. '</span>]]'
elseif pers.disambig == '' then
fio = pers.name .. ' (<i>он же</i> [[' .. pers.pn .. ']])'
else
fio = pers.name .. ' <span class="nkvd-idx">' .. pers.disambig .. '</span> (<i>он же</i> [[' .. pers.pn .. ']])'
end
table.insert( out, fio )
end
return 'Возможно, вас интересует одна из следующих персоналий: '
.. table.concat( out, ' • ' )
end
return pp