- Docs: Module:Book/doc (should use {{module}})
- Styles: Module:Book/style.css
- Templates that use this module:
All modules: book, chronology, kbd, module, post, todo, wikidata link.
local PROP_AUTHOR = 'P50'
local p = {}
-- =p.main({args={wikidata='Q123'}})
p.main = function( frame )
local item = mw.ext.UnlinkedWikibase.getEntity( frame.args.wikidata )
local title = '[Untitled]'
if frame.args.title == nil and item.labels ~= nil and item.labels.en ~= nil then
title = item.labels.en.value
end
local author = ''
if frame.args.author == nil and item.claims[PROP_AUTHOR] ~= nil then
local authorId = item.claims[PROP_AUTHOR][1].mainsnak.datavalue.value.id
local authorItem = mw.ext.UnlinkedWikibase.getEntity( authorId )
author = authorItem.labels.en.value
end
local cardBody = mw.html.create( 'div' )
cardBody:attr( 'class', 'mdl-book-card-body' )
cardBody:wikitext( 'Author: ' .. author )
local cardTitle = mw.html.create( 'h2' )
cardTitle:attr( 'class', 'mdl-book-card-title' )
cardTitle:node( title )
local cardHead = mw.html.create( 'div' )
cardHead:attr( 'class', 'mdl-book-card-head' )
cardHead:node( cardTitle )
local card = mw.html.create( 'div' )
card:attr( 'class', 'mdl-book-card' )
card:node( cardHead )
card:node( cardBody )
local div = mw.html.create( 'div' )
div:attr( 'class', 'mdl-book' )
div:node( card )
return mw.getCurrentFrame():extensionTag( 'templatestyles', '', { src = 'Module:Book/style.css' } )
.. tostring( div )
end
return p