Mòdul:Databox
Aparença
Documentació del mòdul [ mostra ] [ modifica el codi ] [ mostra l'historial ] [ refresca ]
A continuació es mostra la documentació transclosa de la subpàgina /ús. [salta a la caixa de codi]
PROVES d'un dels projectes presentat a la Hackathon 2018.
Genera infotaules elementals de qualsevol tipus d'article.
És similar a l'eina Reasonator (que genera una pàgina, no una infotaula), si bé permet limitar les propietats a mostrar.
Es pot provar mitjançant la plantilla:databox sense cap paràmetre.
NO LA FEU SERVIR dins els articles. Està en beta i, de moment, és força elemental respecte a les nostres. |
local property_blacklist = {
'P360', --is a list of
'P4224', --category contains
'P935', -- Commons gallery
'P1472', -- Commons Creator page
'P1612', -- Commons Institution page
'P373', -- Commons category
'P3722', -- Commons maps category
'P1151', -- topic's main Wikimedia portal
'P1424', -- topic's main template
'P910', -- topic's main category
'P1200', -- bodies of water basin category
'P1792', -- category of associated people
'P1464', -- category for people born here
'P1465', -- category for people who died here
'P1791', -- category of people buried here
'P1740', -- category for films shot at this location
'P2033', -- Category for pictures taken with camera
'P2517', -- category for recipients of this award
'P4195', -- category for employees of the organization
'P1754', -- category related to list
'P301', -- category's main topic
'P971', -- category combines topics
'P3876', -- category for alumni of educational institution
'P1753', -- list related to category
'P3921', -- Wikidata SPARQL query equivalent
'P1204', -- Wikimedia portal's main topic
'P1423', -- template's main topic
'P1709', -- equivalent class
'P3950', -- narrower external class
'P2888', -- exact match
'P1382', -- coincident with
'P527', -- has part
'P2670', -- has parts of the class
'P3113', -- does not have part
'P2737', -- union of
'P2738', -- disjoint union of
'P2445', -- metasubclass of
'P1963', -- properties for this type
'P3176', -- uses property
'P1889', -- different from
'P460', -- said to be the same as
'P2959', -- permanent duplicated item
'P2860', -- cites
'P5125', -- wikimedia outline
'P5008', -- on focus list of Wikimedia project
}
--Utlity function to buil maps
local function buildInteractiveMap(width, point, item_id, zoom)
-- On fait un hack pour générer une valeur par défaut pour la latitude et la longitude
local geojson = {
{
type = 'Feature',
geometry = {
type = "Point",
coordinates = { point.longitude, point.latitude }
},
properties = {
title = point.text or '',
['marker-symbol'] = point.marker or 'marker',
['marker-color'] = point.markercolor or "#224422",
}
}
}
local args = {
['height'] = width,
['width'] = width,
['frameless'] = 'frameless',
['align'] = 'center',
['latitude'] = point.latitude,
['longitude'] = point.longitude,
['zoom'] = zoom
}
return mw.getCurrentFrame():extensionTag('mapframe', mw.text.jsonEncode(geojson), args)
end
function valuesToKeys(array)
local result = {}
for _, v in pairs(array) do
result[v] = true
end
return result
end
local p = {}
function p.databox(frame)
local args = frame:getParent().args
local itemId = nil
if args.item then
itemId = args.item
end
local item = mw.wikibase.getEntity(itemId)
if item == nil then
mw.addWarning("Wikidata item not found")
return ""
end
local databoxRoot = mw.html.create('div')
:css({
float = 'right',
border = '1px solid #aaa',
['max-width'] = '300px',
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() or mw.title.getCurrentTitle().text)
--Image
local images = item:getBestStatements('P18')
if #images == 1 then
databoxRoot
:tag('div')
:wikitext('[[File:' .. images[1].mainsnak.datavalue.value .. '|frameless|300px]]')
end
--Table
local dataTable = databoxRoot
:tag('table')
:css({
['text-align'] = 'left',
['font-size'] = '90%',
['word-break'] = 'break-word'
})
dataTable:tag('caption')
:css({
['background-color'] = '#f5f5f5',
['font-weight'] = 'bold',
['margin-top'] = '0.2em',
})
:wikitext(item:formatStatements('P31').value)
local properties = mw.wikibase.orderProperties(item:getProperties())
local property_blacklist_hash = valuesToKeys(property_blacklist)
property_blacklist_hash['P31'] = true --Special property
local edit_message = mw.message.new('vector-view-edit'):plain()
for _, property in pairs(properties) do
local datatype = item.claims[property][1].mainsnak.datatype
if datatype ~= 'commonsMedia' and datatype ~= 'external-id' and datatype ~= 'quantity' and not property_blacklist_hash[property] and #item.claims[property] <= 5 then
local propertyValue = item:formatStatements(property)
dataTable:tag('tr')
:tag('th')
:attr('scope', 'row')
:wikitext(propertyValue.label):done()
:tag('td')
:wikitext(propertyValue.value)
:wikitext(' [[File:OOjs UI icon edit-ltr.svg|' .. edit_message .. '|12px|baseline|class=noviewer|link=https://www.wikidata.org/wiki/' .. item.id .. '#' .. property .. ']]')
end
end
--Map
if item.claims and item.claims['P625'] and item.claims['P625'][1].mainsnak.datavalue then
databoxRoot:wikitext(buildInteractiveMap('300', item.claims['P625'][1].mainsnak.datavalue.value, item.id, 13))
end
return tostring(databoxRoot)
end
return p