Módulo:Synchronizer
La documentación para este módulo puede ser creada en Módulo:Synchronizer/doc
local Synchronizer = {}
-- Error handling function
-- @return Wiki friendly error message
function Synchronizer.error( message )
return mw.html.create( 'div' ):addClass( 'error' ):wikitext( 'Synchronizer error: ' .. message )
end
function Synchronizer.main( frame )
-- Get the arguments
local args = frame:getParent().args
for key, value in pairs( frame.args ) do
args[ key ] = value -- args from Lua calls have priority over parent args from template
end
-- Get the entity
local entity
local id = args[1]
if id then
entity = mw.wikibase.getEntity( id ) -- Throws an error if an invalid or non-existent ID is given
else
entity = mw.wikibase.getEntity()
if not entity then
return Synchronizer.error( 'No Wikidata entity is associated to this page' )
end
id = entity:getId()
end
local label = entity:getLabel()
-- Build the button
local title = mw.title.getCurrentTitle()
local url = title:fullUrl( 'withJS=MediaWiki:Synchronizer.js' ) .. '#' .. id
local message = args['text'] or 'Synchronize $1';
local text = mw.message.newRawMessage( message, label ):plain()
local link = '[' .. url .. ' <span class="mw-ui-button" style="max-width:none;">' .. text .. '</span>]';
local master = args['master']
local div = mw.html.create( 'div' )
:attr( 'id', id )
:attr( 'data-entity', id )
:attr( 'data-master', master )
:addClass( 'plainlinks' )
:css( 'margin', '.5em 0' )
:wikitext( link )
return div
end
return Synchronizer