Module:Databox
ꠍꠥꠞꠔ ꠢꠣꠟ
Documentation for this module may be created at Module:Databox/doc
local property_blacklist = {
'P360', 'P4224', 'P935', 'P1472', 'P1612', 'P373', 'P3722',
'P1151', 'P1424', 'P910', 'P1200', 'P1792', 'P1464', 'P1465',
'P1791', 'P1740', 'P2033', 'P2517', 'P4195', 'P1754', 'P301',
'P971', 'P3876', 'P1753', 'P3921', 'P1204', 'P1423', 'P1709',
'P3950', 'P2888', 'P1382', 'P527', 'P2670', 'P3113', 'P2737',
'P2738', 'P2445', 'P1963', 'P3176', 'P1889', 'P460', 'P2959',
'P2860', 'P5125', 'P5008', 'P2559', 'P1343', 'P972', 'P1282',
'P4839', 'P6104', 'P5996', 'P948', -- Excluding certain properties
}
-- Add date, digit, numeric properties
local date_properties = {
'P580', -- start time
'P577', -- publication date
'P582', -- end time
'P571', -- inception
'P575', -- time of discovery or invention
'P348', -- software version identifier
'P569', -- date of birth
'P570', -- date of death
'P2124',
'P576',
'P2046', -- ꠄꠞꠤꠀ
'P1082',
'P1540', -- ꠛꠦꠐꠣꠁꠘ꠆ꠔꠞ ꠡꠂꠋꠈꠣ
'P1539', -- ꠛꠦꠐꠤꠘ꠆ꠔꠞ ꠡꠂꠋꠈꠣ
'P1538', -- ꠛꠣꠠꠤꠊꠞꠞ ꠡꠂꠋꠈꠣ
'P6895', -- ꠛꠣꠋꠟꠣꠖꠦꠡ ꠙꠡꠣꠡꠘꠤ ꠛꠤꠜꠣꠉꠣꠁꠘ꠆ꠔꠞ ꠇꠥꠒ
'P4530', -- ꠛꠣꠋꠟꠣꠖꠦꠡ ꠙꠡꠣꠡꠘꠤ ꠛꠤꠜꠣꠉꠣꠁꠘ꠆ꠔꠞ ꠇꠥꠒ ꠀꠉꠞ
'P6390',
-- Add other date-related properties here
}
local p = {}
-- Function to get the Sylheti label of a property or a hyperlink to the property ID
local function getSylhetiLabel(propertyId)
local property = mw.wikibase.getEntity(propertyId)
if property then
local sylLabel = property:getLabel('syl')
if sylLabel then
return sylLabel
else
-- Create a hyperlink to the Wikidata property page with 'd:'
return "[[d:Property:" .. propertyId .. "|" .. propertyId .. "]]"
end
else
return "No label available"
end
end
-- Function to convert digits to Sylheti using the template
local function convertDigitsToSylheti(value)
return '{{ꠍꠤꠟꠐꠤ ꠉꠘꠣ|' .. value .. '}}'
end
-- Function to check if a value exists in a table
local function tableContains(tbl, val)
for _, v in ipairs(tbl) do
if v == val then
return true
end
end
return false
end
function p.databox(frame)
local args = frame:getParent().args
local itemId = args.item
local item = mw.wikibase.getEntity(itemId)
if not item then
mw.addWarning("Wikidata item not found")
return ""
end
local databoxRoot = mw.html.create('div')
:addClass('infobox')
:css({
float = 'right',
border = '1px solid #aaa',
['max-width'] = '400px',
padding = '0 0.4em',
margin = '0 0 0.4em 0.4em',
})
-- Title
databoxRoot:tag('div')
:css({
['text-align'] = 'center',
['background-color'] = '#f5f5f5',
padding = '0.5em 0',
margin = '0.5em 0',
['font-size'] = '120%',
['font-weight'] = 'bold',
})
:wikitext(item:getLabel('syl') or mw.title.getCurrentTitle().text)
-- Table for statements
local dataTable = databoxRoot:tag('table')
:css({
['text-align'] = 'left',
['font-size'] = '90%',
['word-break'] = 'break-word',
['width'] = '100%',
['table-layout'] = 'fixed',
})
local properties = mw.wikibase.orderProperties(item:getProperties())
local propertyCount = 0
local processedProperties = {} -- Table to track processed properties
-- Display properties in specified order
local propertyOrder = {
'P154', -- logo
'P18', -- image
'P25', -- audio
'P31', -- video
'P276', -- map
'P1003', -- detailed map (you can add more map-related properties here)
-- Add other relevant map properties if needed
}
-- Add date properties at the end
for _, property in ipairs(date_properties) do
table.insert(propertyOrder, property)
end
-- Collect properties based on the specified order
for _, property in ipairs(propertyOrder) do
if propertyCount >= 15 then break end -- Limit to 15 properties
if not property_blacklist[property] and not processedProperties[property] then
local statements = item:getBestStatements(property)
if #statements > 0 then
local propertyValue = item:formatStatements(property)
local sylLabel = getSylhetiLabel(property)
-- Handle date properties for digit conversion
if tableContains(date_properties, property) then
local convertedValue = convertDigitsToSylheti(propertyValue.value)
dataTable:tag('tr')
:tag('th')
:attr('scope', 'row')
:css({ ['width'] = '30%' })
:wikitext(sylLabel):done()
:tag('td')
:css({ ['width'] = '70%' })
:wikitext(frame:preprocess(convertedValue))
else
dataTable:tag('tr')
:tag('th')
:attr('scope', 'row')
:css({ ['width'] = '30%' })
:wikitext(sylLabel):done()
:tag('td')
:css({ ['width'] = '70%' })
:wikitext(frame:preprocess(propertyValue.value))
end
processedProperties[property] = true -- Mark property as processed
propertyCount = propertyCount + 1
end
end
end
-- Process remaining properties (not in the order specified) to fill the total of 15 if needed
for _, property in ipairs(properties) do
if propertyCount >= 15 then break end -- Limit to 15 properties
if not property_blacklist[property] and not processedProperties[property] then
local statements = item:getBestStatements(property)
if #statements > 0 then
local propertyValue = item:formatStatements(property)
local sylLabel = getSylhetiLabel(property)
-- Handle date properties for digit conversion
if tableContains(date_properties, property) then
local convertedValue = convertDigitsToSylheti(propertyValue.value)
dataTable:tag('tr')
:tag('th')
:attr('scope', 'row')
:css({ ['width'] = '30%' })
:wikitext(sylLabel):done()
:tag('td')
:css({ ['width'] = '70%' })
:wikitext(frame:preprocess(convertedValue))
else
dataTable:tag('tr')
:tag('th')
:attr('scope', 'row')
:css({ ['width'] = '30%' })
:wikitext(sylLabel):done()
:tag('td')
:css({ ['width'] = '70%' })
:wikitext(frame:preprocess(propertyValue.value))
end
processedProperties[property] = true -- Mark property as processed
propertyCount = propertyCount + 1
end
end
end
return tostring(databoxRoot)
end
return p