יחידה:תבנית מידע/טבלת ניווט
מען קען שאפן דאקומענטאציע פאר דעם מאדול ביי יחידה:תבנית מידע/טבלת ניווט/דאק
local p = {}
local WikidataCrossValidation = require('Module:WikidataCrossValidation')
local PropertyLink = require('Module:PropertyLink')
local function getWikidataValue(entity, property, series, yearsOnly)
if entity == nil or property==nil then return end
local res = nil
local propertyVals
if series ~= nil then
propertyVals = mw.wikibase.getBestStatements( entity, series )
if propertyVals and #propertyVals>0 then
local seriesId = propertyVals[1] and propertyVals[1].mainsnak and propertyVals[1].mainsnak.datavalue
seriesId = seriesId and seriesId.value and seriesId.value.id
if seriesId==nil then return end
local qualifierVal = propertyVals[1].qualifiers and propertyVals[1].qualifiers[property] and propertyVals[1].qualifiers[property][1]
qualifierVal = qualifierVal and qualifierVal.datavalue and qualifierVal.datavalue.value and qualifierVal.datavalue.value.id
if qualifierVal == nil then return end
--local seriesLabel = mw.wikibase.label(propertyVals[1].mainsnak.datavalue.value.id)
res = PropertyLink.formatEntity(qualifierVal)
end
else
res = PropertyLink.getPropertyByOptions(property, entity)
end
if yearsOnly and res then
if mw.ustring.match(res, '%[%[.+%|.+') then
res = mw.ustring.gsub(res, '%[%[(.+)%|.+ ([0-9]+)%]%]', '[[%1|%2]]')
else
if mw.ustring.match(res, '%[%[(.+ )([0-9]+)%]%]') then
res = mw.ustring.gsub(res, '%[%[(.+ )([0-9]+)%]%]', '[[%1%2|%2]]')
else
res = mw.ustring.gsub(res, '%[%[(.+ )([0-9]+/[0-9]+)([^0-9]-)%]%]', '[[%1%2%3|%2]]')
end
end
end
return res
end
function p.render(frame)
local Arguments = require('Module:Arguments')
local templateArgs = Arguments.getArgs(frame)
local seriesProperty = templateArgs['סדרה']
local yearsOnly = templateArgs['מקוצר'] == 'כן'
local maintainceCats = ''
local entityId = templateArgs['qid']
local prevLink = frame.args[1]
if prevLink == nil or prevLink=='' then
prevLink=getWikidataValue(entityId, 'P155', seriesProperty, yearsOnly)
else
local wikidataLink = getWikidataValue(entityId, 'P155', seriesProperty, yearsOnly)
if wikidataLink==prevLink then
maintainceCats = maintainceCats .. WikidataCrossValidation.maintainceCategory(WikidataCrossValidation.CrossValidateResult.COMPATIBLE, 'P155')
end
end
local nextLink = frame.args[2]
if nextLink == nil or nextLink=='' then
nextLink=getWikidataValue(entityId, 'P156', seriesProperty, yearsOnly)
else
local wikidataLink = getWikidataValue(entityId, 'P156', seriesProperty, yearsOnly)
if wikidataLink==nextLink then
maintainceCats = maintainceCats .. WikidataCrossValidation.maintainceCategory(WikidataCrossValidation.CrossValidateResult.COMPATIBLE, 'P156')
end
end
if prevLink==nil and nextLink==nil then
return ''
end
local result = ''
if prevLink~=nil then
result = result .. '<div style="float:right;">→ '..prevLink..'</div>'
end
if nextLink~=nil then
result = result .. '<div style="float:left;">'..nextLink ..' ←</div>'
end
if result ~= '' then
result = '<div style="font-size:smaller;">'..result ..'</div>'
end
return result .. maintainceCats
end
return p