Modul:InfoboxBook
Aspect

local getArgs = require('Modul:Arguments').getArgs
local infobox = require('Modul:Infobox')
local ibImage = require('Modul:InfoboxImage')
local wikidata = require('Modul:Wikidata')
local p = {}
local function processArgs(args)
local ibargs = {}
ibargs['aboveclass'] = 'autor'
ibargs['culoare cadru'] = 'EEDC82'
ibargs['title'] = args['nume'] or args['title'] or args['titlu'] or wikidata.findLabel(nil, nil)
local coverStr = args['image'] or args['copertă'] or args['coperta'] or wikidata.findOneValueNoRef(nil, 'P18')
local coverSize = args['copertă_mărime'] or args['imagewidth'] or '200x200px'
if coverStr and mw.text.trim(coverStr) ~= '' then
ibargs['image'] = ibImage.InfoboxImage{image = coverStr, size = coverSize, sizedefault = 'frameless'}
end
ibargs['caption1'] = args['descriere_copertă'] or args['image_caption']
local imageStr = args['poza'] or args['poză']
local imageSize = args['poză_mărime'] or '230x230px'
if imageStr then
ibargs['image2'] = ibImage.InfoboxImage{image = imageStr, size = imageSize, sizedefault = 'frameless' }
end
ibargs['caption2'] = args['comentariu'] or args['comentariu_poză']
local lineIndex = 1
ibargs['header' .. tostring(lineIndex)] = 'Informații generale'
lineIndex = lineIndex + 1
ibargs['label' .. tostring(lineIndex)] = 'Autor'
ibargs['data' .. tostring(lineIndex)] = args['autor'] or table.concat(wikidata.getValueList(nil, 'P50'), ', ')
lineIndex = lineIndex + 1
local series = {}
if args['serie'] or args['seria'] then
local serie = {}
serie.nume = args['serie'] or args['seria']
serie.prevItem = args['precedata_de'] or args['precedată_de']
serie.nextItem = args['urmata_de'] or args['urmată_de']
table.insert(series, serie)
else
local seriesWdList = wikidata.findClaimsForProperty(nil, 'P179')
if seriesWdList ~= nil then
for i, eachWdClaim in pairs(seriesWdList) do
local serie = {}
if eachWdClaim.mainsnak.datatype == 'wikibase-item' and eachWdClaim.mainsnak.datavalue.type == 'wikibase-entityid' and eachWdClaim.mainsnak.datavalue.value['entity-type'] == 'item' then
serie.nume = wikidata.findLinkToItem(eachWdClaim.mainsnak.datavalue.value['numeric-id'])
local prevItems = wikidata.findQualifierValueListForClaim(eachWdClaim, 'P155')
if prevItems and #prevItems > 0 then serie.prevItem = prevItems[1] end
local nextItems = wikidata.findQualifierValueListForClaim(eachWdClaim, 'P156')
if nextItems and #nextItems > 0 then serie.nextItem = nextItems[1] end
end
table.insert(series, serie)
end
end
end
local seriesNames = {}
for i, eachSeries in pairs(series) do table.insert(seriesNames, eachSeries.nume) end
local subject = wikidata.getValueList(nil, 'P921')
if subject then
ibargs['label' .. tostring(lineIndex)] = 'Subiect'
ibargs['data' .. tostring(lineIndex)] = args['subiect'] or table.concat(subject, tostring(mw.html.create('br')))
lineIndex = lineIndex + 1
end
local gender = wikidata.getValueList(nil, 'P136')
if args['gen'] or gender then
ibargs['label' .. tostring(lineIndex)] = 'Gen'
ibargs['data' .. tostring(lineIndex)] = args['gen'] or table.concat(gender, tostring(mw.html.create('br')))
lineIndex = lineIndex + 1
end
ibargs['label' .. tostring(lineIndex)] = 'Serie'
ibargs['data' .. tostring(lineIndex)] = table.concat(seriesNames, tostring(mw.html.create('br')))
lineIndex = lineIndex + 1
ibargs['header' .. tostring(lineIndex)] = 'Ediția originală'
lineIndex = lineIndex + 1
local titlesInOrigLangs = {}
local origLanguageIds
if not (args['limbă'] or args['limba']) or not (args['titlu_original']) then
origLanguageIds = wikidata.getEntityIdsList(nil, 'P364')
if origLanguageIds then
for i, eachOrigLangId in pairs(origLanguageIds) do
local origLanguageCode = wikidata.findOneValueNoRef('P218', mw.wikibase.getEntity('Q' .. eachOrigLangId))
local titleInOrigLang = wikidata.findLabel(nil, origLanguageCode)
if titleInOrigLang then table.insert(titlesInOrigLangs, titleInOrigLang) end
end
end
end
local orig_title = wikidata.getValueList(nil, 'P50')
if args['titlu_original'] or orig_title then
ibargs['label' .. tostring(lineIndex)] = 'Titlu original'
ibargs['data' .. tostring(lineIndex)] = args['titlu_original'] or table.concat(orig_title, tostring(mw.html.create('br')))
lineIndex = lineIndex + 1
end
local language = wikidata.getValueList(nil, 'P364')
if args['limba'] or language then
ibargs['label' .. tostring(lineIndex)] = 'Limba'
ibargs['data' .. tostring(lineIndex)] = args['limba'] or table.concat(language, ', ')
lineIndex = lineIndex + 1
end
local edition = wikidata.getValueList(nil, 'P123')
if args['editura'] or args['editură'] or edition then
ibargs['label' .. tostring(lineIndex)] = '[[Editură]]'
ibargs['data' .. tostring(lineIndex)] = args['editura'] or args['editură'] or table.concat(edition, ', ')
lineIndex = lineIndex + 1
end
ibargs['label' .. tostring(lineIndex)] = 'Ilustrator'
ibargs['data' .. tostring(lineIndex)] = args['ilustratia'] or args['ilustrator'] or args['autor_ilustrații']
lineIndex = lineIndex + 1
ibargs['label' .. tostring(lineIndex)] = 'Țara primei apariții'
ibargs['data' .. tostring(lineIndex)] = args['tara'] or args['țară_de_lansare'] or args['țara_de_apariție']
lineIndex = lineIndex + 1
ibargs['label' .. tostring(lineIndex)] = 'Data primei apariții'
ibargs['data' .. tostring(lineIndex)] = args['data_publicării'] or args['data_publicarii'] or args['data_apariției'] or args['release_date'] or wikidata.findOneValue('P577', nil)
lineIndex = lineIndex + 1
ibargs['label' .. tostring(lineIndex)] = 'Format original'
ibargs['data' .. tostring(lineIndex)] = args['format_original']
if args['audio_orig'] then ibargs['data' .. tostring(lineIndex)] = ibargs['data' .. tostring(lineIndex)] .. tostring(mw.html.create('br')) .. 'Disponibilă audio ' .. args['audio_orig'] end
lineIndex = lineIndex + 1
ibargs['label' .. tostring(lineIndex)] = 'Număr de pagini'
ibargs['data' .. tostring(lineIndex)] = args['pagini'] or args['număr_pagini']
lineIndex = lineIndex + 1
ibargs['label' .. tostring(lineIndex)] = 'Dimensiune și greutate'
ibargs['data' .. tostring(lineIndex)] = args['dimensiune_greutate'] or args['size_weight']
lineIndex = lineIndex + 1
local isbn10 = wikidata.getValueList(nil, 'P957')
local isbn13 = wikidata.getValueList(nil, 'P212')
if args['isbn'] or isbn10 or isbn13 then
mw.logObject(isbn10)
mw.logObject(isbn13)
ibargs['label' .. tostring(lineIndex)] = '[[International Standard Book Number|ISBN]]'
ibargs['data' .. tostring(lineIndex)] = args['isbn'] or table.concat(isbn10, tostring(mw.html.create('br'))) .. mw.html.create('br') .. table.concat(isbn13, tostring(mw.html.create('br')))
lineIndex = lineIndex + 1
end
ibargs['label' .. tostring(lineIndex)] = '[[OCLC]]'
local oclc = wikidata.getValueList(nil, 'P243')
if args['oclc'] then
ibargs['data' .. tostring(lineIndex)] = '[http://worldcat.org/oclc/' .. args['oclc'] .. ' ' .. args['oclc'] .. ']'
lineIndex = lineIndex + 1
else
if oclc then
ibargs['data' .. tostring(lineIndex)] = table.concat(oclc, tostring(mw.html.create('br')))
lineIndex = lineIndex + 1
end
end
if args['traducerea'] or args['traducător'] or args['editura_ro'] or args['data_apariției_în_românia'] or args['pagini_ro'] or args['format'] then
ibargs['header' .. tostring(lineIndex)] = 'Ediția în limba română'
lineIndex = lineIndex + 1
end
ibargs['label' .. tostring(lineIndex)] = 'Traducător'
ibargs['data' .. tostring(lineIndex)] = args['traducător'] or args['traducerea']
lineIndex = lineIndex + 1
ibargs['label' .. tostring(lineIndex)] = 'Editură'
ibargs['data' .. tostring(lineIndex)] = args['editura_ro']
lineIndex = lineIndex + 1
ibargs['label' .. tostring(lineIndex)] = 'Data apariției'
ibargs['data' .. tostring(lineIndex)] = args['data_apariției_în_românia'] or args['english_release_date']
lineIndex = lineIndex + 1
ibargs['label' .. tostring(lineIndex)] = 'Număr de pagini'
ibargs['data' .. tostring(lineIndex)] = args['pagini_ro']
lineIndex = lineIndex + 1
ibargs['label' .. tostring(lineIndex)] = 'Format'
ibargs['data' .. tostring(lineIndex)] = args['format'] or args['media_type']
if args['audio'] then ibargs['data' .. tostring(lineIndex)] = ibargs['data' .. tostring(lineIndex)] .. tostring(mw.html.create('br')) .. 'Disponibilă audio ' .. args['audio'] end
lineIndex = lineIndex + 1
if table.maxn(series) > 0 then
ibargs['header' .. tostring(lineIndex)] = 'Cronologie'
lineIndex = lineIndex + 1
for seriesIdx = 1, table.maxn(series) do
if series[seriesIdx] then
local chronoRoot = mw.html.create('table')
local chronoSingleRow = chronoRoot:tag('tr')
local brokenRowLeft = chronoSingleRow:tag('th'):attr('width', '50%')
local tinyTable = brokenRowLeft:tag('table')
:attr('cellspacing', '0')
:css('width', '100%')
:css('padding', '5px')
:css('margin', '0 0 0 0')
:css('border-collapse', 'collapse')
:css('background-color', series[seriesIdx].prevItem and '#E6E6E6' or 'transparent')
local tinyTableRow = tinyTable:tag('tr')
local prevTd = tinyTableRow:tag('td')
:attr('width', '20')
:attr('align', 'left')
if series[seriesIdx].prevItem then
prevTd:wikitext(mw.getCurrentFrame():expandTemplate{title='Click cu text', args={imagine='Fleche-defaut-gauche.png', page=series[seriesIdx].prevItem, width='13px', height='27px'}})
end
tinyTableRow:tag('td')
:css('text-align', 'left')
:css('font-style', 'italic')
:wikitext(series[seriesIdx].prevItem)
local brokenRowRight = chronoSingleRow:tag('th'):attr('width', '50%')
tinyTable = brokenRowRight:tag('table')
:attr('cellspacing', '0')
:css('width', '100%')
:css('padding', '5px')
:css('margin', '0 0 0 0')
:css('border-collapse', 'collapse')
:css('background-color', series[seriesIdx].nextItem and '#E6E6E6' or 'transparent')
tinyTableRow = tinyTable:tag('tr')
tinyTableRow:tag('td')
:css('text-align', 'right')
:css('font-style', 'italic')
:wikitext(series[seriesIdx].nextItem)
local nextTd = tinyTableRow:tag('td')
:attr('width', '20')
:attr('align', 'right')
if series[seriesIdx].nextItem then
nextTd:wikitext(mw.getCurrentFrame():expandTemplate{title='Click cu text', args={imagine='Fleche-defaut-droite.png', page=series[seriesIdx].nextItem, width='13px', height='27px'}})
end
ibargs['data' .. tostring(lineIndex)] = tostring(chronoRoot)
end
end
end
ibargs['doc'] = 'Infocaseta Carte'
ibargs['doc-colspan'] = '2'
return ibargs
end
p._infobox = function(args)
local infoboxArgs = processArgs(args)
local retval = mw.getCurrentFrame():expandTemplate{title='titlu cursiv', args={}}
retval = retval .. infobox.infobox(infoboxArgs)
if not (infoboxArgs['image'] or infoboxArgs['image2']) then
retval = retval .. '[[Categorie:Articole despre cărți fără coperte]]'
end
return retval
end
p.infobox = function(frame)
local args = getArgs(frame, { wrappers = { 'Format:Carte', 'Format:Infocaseta Carte' } })
return p._infobox(args)
end
return p