Модуль:WikidataMagic
Дакументацыю да гэтага модуля можна стварыць у Модуль:WikidataMagic/Дакументацыя
local p = {}
--[[
Атрыманне параметраў, якія звычайна выкарыстоўваюцца для высновы ўласцівасці.
]]
function p.usualPropertyParams( propertyId )
propertyId = string.upper( string.gsub( propertyId, '%[.*$', '' ) )
local wdConfig = require( 'Module:Wikidata/config' );
local propertyParams = {};
if wdConfig['properties'][propertyId] then
propertyParams = wdConfig['properties'][propertyId];
end
if propertyParams['preset'] and wdConfig['presets']
and wdConfig['presets'][propertyParams['preset']] then
local presetParams = wdConfig['presets'][propertyParams['preset']];
for key, value in pairs( propertyParams ) do
propertyParams[ key ] = value;
end
propertyParams = presetParams;
end
return propertyParams;
end
--[[
Абгортка над метадам formatProperty модуля Wikidata.
]]
function p.formatProperty( frame )
local Wikidata = require( 'Module:Wikidata' )
-- калі лакальнае значэнне перададзена ў параметрах выкліку,
-- адразу выклікаецца фарматар Wikidata для высновы
if frame.args.value and frame.args.value ~= '' then
return Wikidata.formatProperty( frame )
end
-- часавае рашэнне для выкарыстання спецыяльных шаблонаў
local specalTemplates = { P348 = 1, P421 = 1, P2031 = 1, P2032 = 1 }
if specalTemplates[ string.upper( frame.args.property ) ] then
return frame:expandTemplate{ title = 'Wikidata/' .. string.lower( frame.args.property ) }
end
-- аўтаматычнае фарматаванне ўласцівасці
local propertyParams = p.usualPropertyParams( frame.args.property )
for key, value in pairs( propertyParams ) do
frame.args[ key ] = value
end
return Wikidata.formatProperty( frame )
end
return p