Изменения
не знаю, как это работает, но лучше на такое не полагаться и уточнять поведение кода
end
end
-- Получить три первых значения из свойства в Викиданных
-- Получить num (по умолчанию все) первых значений из свойства в Викиданных
-- TODO: переделать на получение Q-элементов, чтобы не зависеть от языка
-- TODO: переделать на получение Q-элементов, чтобы не зависеть от языка
local function getWikidataProperty( frame, property, entityId )
local function getWikidataProperty( frame, property, entityId, num )
frame = frame or mw.getCurrentFrame()
frame = frame or mw.getCurrentFrame()
result = mw.text.split( result, ', ' )
result = mw.text.split( result, ', ' )
return { unpack( result, 1, 3 ) }
if isEmpty( num ) then
return result
else
return { unpack( result, 1, num ) }
end
end
end
frame = frame or mw.getCurrentFrame()
frame = frame or mw.getCurrentFrame()
local propValues = getWikidataProperty( frame, property, entityId )
local propValues = getWikidataProperty( frame, property, entityId, 3 )
local catName = getCategoryName( name, property )
local catName = getCategoryName( name, property )
local instanceOf = getWikidataProperty( frame, 'p31', entityId )
local instanceOf = getWikidataProperty( frame, 'p31', entityId, 3 )
instanceOf = #instanceOf > 0 and instanceOf[ 1 ] or ''
instanceOf = #instanceOf > 0 and instanceOf[ 1 ] or ''
local pageTitle = mw.title.getCurrentTitle().fullText
local pageTitle = mw.title.getCurrentTitle().fullText
local result = ''
local result = ''
local catName = ''
local occupationExists = false
local validCatsCounter = 0
for key, val in pairs( propValues ) do
for key, val in pairs( propValues ) do
local value = mwLang:lcfirst( val )
local value = mwLang:lcfirst( val )
catName = getCategoryName( 'Википедия:%s (тип: человек; род занятий: %s)', name, value )
occupationExists = true
if isValidCategory( name, catName, property ) then
result = result .. string.format( '[[Category:%s]]', catName )
validCatsCounter = validCatsCounter + 1
end
-- Шаблон проставлял одну категорию
-- Ограничение количества выводимых категорий
if result ~= '' then
if validCatsCounter >= 3 then
break
break
end
end
end
-- Подходящей категории нет, либо в ВД нет рода занятий, но есть дефолтные значения,
-- тогда поставляем категорию на их основе при её наличии
local args = getArgs( frame )
local defaultOccupation = args[ 'default-occupation' ]
if result == '' and not isEmpty( defaultOccupation ) then
occupationExists = true
catName = getCategoryName( 'Википедия:%s (тип: человек; род занятий: %s)', name, defaultOccupation )
if isValidCategory( name, catName, property ) then
result = result .. string.format( '[[Category:%s]]', catName )
end
end
-- Есть род занятий (на ВД или через параметр), но подходящей категории нет,
-- тогда подставляем служебную категорию "не распределён" при её наличии
if result == '' and occupationExists then
catName = getCategoryName( 'Википедия:%s (тип: человек; род занятий: не распределён)', name )
if isValidCategory( name, catName, property ) then
if isValidCategory( name, catName, property ) then
result = result .. string.format( '[[Category:%s]]', catName )
result = result .. string.format( '[[Category:%s]]', catName )
local property = 'p31'
local property = 'p31'
local propValues = getWikidataProperty( frame, property, entityId )
local propValues = getWikidataProperty( frame, property, entityId )
local args = getArgs( frame )
local defaultType = args[ 'default-type' ]
local defaultOccupation = args[ 'default-occupation' ]
local defaultCatKey
local defaultCatKey
local result = ''
local result = ''
local catName = ''
local validCatsCounter = 0
for key, val in pairs( propValues ) do
for key, val in pairs( propValues ) do
catName = getCategoryName( 'Википедия:%s (тип: %s)', name, mwLang:lcfirst( val ) )
-- TODO: переделать на получение Q-элементов, чтобы не зависеть от языка
-- TODO: переделать на получение Q-элементов, чтобы не зависеть от языка
if val == 'человек' or val == 'human' then
if val == 'человек' or val == 'human' then
result = result .. occupations
result = result .. occupations
end
end
validCatsCounter = validCatsCounter + 1 -- "человек" считается всегда валидной
else
else
if isValidCategory( name, catName, property ) then
if isValidCategory( name, catName, property ) then
result = result .. string.format( '[[Category:%s]]', catName )
result = result .. string.format( '[[Category:%s]]', catName )
validCatsCounter = validCatsCounter + 1
else
else
if isEmpty( defaultCatKey ) then
if isEmpty( defaultCatKey ) then
defaultCatKey = val
defaultCatKey = val
end
end
end
end
-- Ограничение количества выводимых категорий
if validCatsCounter >= 3 then
break
end
end
-- Если ничего не нашлось, попытка добавить категорию на основе переданных дефолтных значений
if result == '' and not isEmpty( defaultType ) then
if defaultType == 'человек' and not isEmpty( defaultOccupation ) then -- человек, есть занятие
catName = getCategoryName( 'Википедия:%s (тип: человек; род занятий: %s)', name, defaultOccupation )
if isValidCategory( name, catName, property ) then
result = result .. string.format( '[[Category:%s]]', catName )
else -- человек, есть занятие, но категория для занятия не прошла проверки
catName = getCategoryName( 'Википедия:%s (тип: человек)', name )
result = result .. string.format( '[[Category:%s]]', catName )
end
elseif defaultType == 'человек' then -- человек, нет занятия
catName = getCategoryName( 'Википедия:%s (тип: человек)', name )
result = result .. string.format( '[[Category:%s]]', catName )
else -- нечеловек
catName = getCategoryName( 'Википедия:%s (тип: %s)', name, defaultType )
if isValidCategory( name, catName, property ) then
result = result .. string.format( '[[Category:%s]]', catName )
end
end
end
end
local property = 'p131'
local property = 'p131'
local propValues = getWikidataProperty( frame, property, entityId )
local propValues = getWikidataProperty( frame, property, entityId, 3 )
local result = ''
local result = ''
local property = 'p17'
local property = 'p17'
local propValues = getWikidataProperty( frame, property, entityId )
local propValues = getWikidataProperty( frame, property, entityId, 3 )
local result = ''
local result = ''
-- Игнорировать при наличии изображений в указанных свойствах
-- Игнорировать при наличии изображений в указанных свойствах
for _, val in pairs( localFileProps ) do
for _, val in pairs( localFileProps ) do
local propValue = getWikidataProperty( frame, val, entityId )
local propValue = getWikidataProperty( frame, val, entityId, 3 )
if #propValue > 0 then
if #propValue > 0 then
return ''
return ''