Page MenuHomePhabricator
Paste P707

Module:Capiunto-wikibase
ActivePublic

Authored by Bene on May 30 2015, 2:08 PM.
local capiunto = require 'capiunto'
local util = require 'libraryUtil'
local referenceRenderer
function addStatement( t, property )
local value = ''
local frame = mw.getCurrentFrame()
if frame.args[property] then
value = frame.args[property]
else
local entity = mw.wikibase.getEntity()
local propertyId = mw.wikibase.resolvePropertyId( property )
if propertyId ~= nil then
value = renderStatements( entity:getStatements( propertyId ) )
end
end
if value ~= '' then
t:addRow( property, value )
end
return t
end
function renderStatements( statements )
local value = ''
local frame = mw.getCurrentFrame()
for k, statement in pairs( statements ) do
if value ~= '' then
value = value .. tostring( mw.message.new( 'comma-separator' ) )
end
value = value .. mw.wikibase.renderSnak( statement.mainsnak )
if statement.references then
value = value .. renderReferences( statement.references )
end
end
return value
end
function renderReferences( references )
local value = ''
local frame = mw.getCurrentFrame()
for k, reference in pairs( references ) do
value = value .. frame:preprocess(
'<ref name="' .. reference.hash .. '">' .. referenceRenderer( reference.snaks ) .. '</ref>'
)
end
return value
end
function defaultReferenceRenderer( snaks )
return mw.wikibase.renderSnaks( snaks )
end
local create = capiunto.create
capiunto.create = function( options )
local infobox = create( options )
infobox.addStatement = addStatement
referenceRenderer = options.referenceRenderer or defaultReferenceRenderer
util.checkType( 'referenceRenderer', 1, referenceRenderer, 'function' )
return infobox
end
return capiunto

Event Timeline

Bene edited the content of this paste. (Show Details)May 30 2015, 2:08 PM
Bene changed the title of this paste from untitled to Module:Capiunto-wikibase.
Bene updated the paste's language from autodetect to autodetect.