Modul:InfoboxBook
Documentația acestui modul poate fi creată la Modul:InfoboxBook/doc
local getArgs = require('Modul:Arguments').getArgs
local infobox = require('Modul:Infobox')
local ibImage = require('Modul:InfoboxImage')
local wikidata = require('Modul:Wikidata')
local TableTools = require('Modul:TableTools')
local WikidataLiterature = require('Modul:WikidataUtils/Literature')
local EditAtWikidata = require('Modul:EditAtWikidata')
local join = require('Modul:Separated entries').main
local p = {}
local function processArgs(args)
local ibargs = {}
ibargs['aboveclass'] = 'autor'
ibargs['culoare cadru'] = 'EEDC82'
ibargs['title'] = tostring(mw.html.create('div'):css('font-style', 'italic'):wikitext(args['nume'] or args['title'] or args['titlu'] or wikidata.findLabel(nil, nil)))
local coverStr = args['image'] or args['copertă'] or args['coperta']
local caption = args['descriere_copertă'] or args['image_caption'] or args['descriere_img']
local coverSize = args['copertă_mărime'] or args['imagewidth'] or '200px'
if not coverStr then
coverStr, caption = wikidata.findImageAndCaption()
end
if coverStr then
if coverStr and mw.text.trim(coverStr) ~= '' then
ibargs['image'] = ibImage.InfoboxImage{image = coverStr, size = coverSize, sizedefault = 'frameless'}
end
end
ibargs['caption'] = caption
local imageStr = args['poza'] or args['poză']
local imageSize = args['poză_mărime'] or '200px'
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
local volumes = args['volume']
if volumes == nil then
local wikidataVols = wikidata.getValueList(nil, 'P527')
if wikidataVols and #wikidataVols > 0 then
wikidataVols.separator = tostring(mw.html.create('br'))
volumes = join(wikidataVols)
end
end
if volumes then
ibargs['header' .. tostring(lineIndex)] = 'Volume'
lineIndex = lineIndex + 1
ibargs['data' .. tostring(lineIndex)] = volumes
lineIndex = lineIndex + 1
end
ibargs['header' .. tostring(lineIndex)] = 'Informații generale'
lineIndex = lineIndex + 1
local author = wikidata.getValueList(nil, 'P50')
if args['autor'] or args['author'] or args['authors'] or author then
ibargs['label' .. tostring(lineIndex)] = 'Autor'
ibargs['data' .. tostring(lineIndex)] = args['autor'] or args['author'] or args['authors'] or table.concat(author, ', ')
lineIndex = lineIndex + 1
end
local series = {}
local numeSerie = args['serie'] or args['series'] or args['seria']
local precededBy = args['precedata_de'] or args['precedată_de'] or args['preceded_by']
local followedBy = args['urmata_de'] or args['urmată_de'] or args['followed_by']
if numeSerie or precededBy or followedBy then
local serie = {}
serie.nume = numeSerie
serie.prevItem = precededBy
serie.nextItem = followedBy
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 args['subiect'] or args['subject'] or subject then
ibargs['label' .. tostring(lineIndex)] = 'Subiect'
ibargs['data' .. tostring(lineIndex)] = args['subiect'] or args['subject'] or table.concat(subject, tostring(mw.html.create('br')))
lineIndex = lineIndex + 1
end
local gender = wikidata.getValueList(nil, 'P136')
if args['gen'] or args['genre'] or gender then
ibargs['label' .. tostring(lineIndex)] = 'Gen'
ibargs['data' .. tostring(lineIndex)] = args['gen'] or args['genre'] 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 = WikidataLiterature.findOrigTitlesOfWork()
local origLanguageIds
if not (args['limbă'] or args['limba'] or args['language']) or not (args['titlu_original'] or args['title_orig']) then
origLanguageIds = wikidata.getEntityIdsList(nil, 'P407')
if origLanguageIds then
for i, eachOrigLangId in pairs(origLanguageIds) do
local origLanguageCode = wikidata.findOneValueNoRef('P218', mw.wikibase.getEntity('Q' .. eachOrigLangId))
if origLanguageCode then
local titleInOrigLang = wikidata.findLabel(nil, origLanguageCode)
if titleInOrigLang and not TableTools.isEmpty(titlesInOrigLangs) then titlesInOrigLangs[origLanguageCode] = titleInOrigLang end
end
end
end
end
if args['titlu_original'] or args['title_orig'] or not TableTools.isEmpty(titlesInOrigLangs) then
ibargs['label' .. tostring(lineIndex)] = 'Titlu original'
ibargs['data' .. tostring(lineIndex)] = tostring(mw.html.create('div'):css('font-style', 'italic'):wikitext(args['titlu_original'] or WikidataLiterature.concatTitles(titlesInOrigLangs, tostring(mw.html.create('br')))))
lineIndex = lineIndex + 1
end
local language = args['limba'] or args['language']
if not language then
local languages = wikidata.getValueList(nil, 'P407')
if languages and #languages > 0 then
language = table.concat(languages, tostring(mw.html.create('br'))) .. ' ' .. EditAtWikidata.displayMessage('P407')
end
end
if language then
ibargs['label' .. tostring(lineIndex)] = 'Limba'
ibargs['data' .. tostring(lineIndex)] = language
lineIndex = lineIndex + 1
end
local publisher = args['editura'] or args['editură'] or args['publisher']
if not publisher then
local publishers = wikidata.getValueList(nil, 'P123')
if publishers and #publishers > 0 then publisher = table.concat(publishers, tostring(mw.html.create('br'))) .. ' ' .. EditAtWikidata.displayMessage('P123') end
end
if publisher then
ibargs['label' .. tostring(lineIndex)] = '[[Editură]]'
ibargs['data' .. tostring(lineIndex)] = publisher
lineIndex = lineIndex + 1
end
ibargs['label' .. tostring(lineIndex)] = 'Ilustrator'
ibargs['data' .. tostring(lineIndex)] = args['ilustratia'] or args['ilustrator'] or args['illustrator'] or args['autor_ilustrații'] or wikidata._getBestValuesWithSeparator(nil, 'P110', tostring(mw.html.create('br')))
lineIndex = lineIndex + 1
ibargs['label' .. tostring(lineIndex)] = 'Coperta de'
ibargs['data' .. tostring(lineIndex)] = args['cover_artist']
lineIndex = lineIndex + 1
local country = args['tara'] or args['țară_de_lansare'] or args['țara_de_apariție'] or args['country']
if not country then
local countries = wikidata.findValueListWithDecoratedQualifiers(nil, 'P495', true, nil, nil, 'P41', '20px')
if countries and #countries > 0 then
country = table.concat(countries, tostring(mw.html.create('br'))) .. ' ' .. EditAtWikidata.displayMessage('P495')
end
end
ibargs['label' .. tostring(lineIndex)] = 'Țara primei apariții'
ibargs['data' .. tostring(lineIndex)] = country
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['pub_date'] or args['release_date'] or wikidata.findOneValue('P577', nil)
lineIndex = lineIndex + 1
ibargs['label' .. tostring(lineIndex)] = 'Perioada de publicare'
ibargs['data' .. tostring(lineIndex)] = args['perioada']
lineIndex = lineIndex + 1
ibargs['label' .. tostring(lineIndex)] = 'Număr de cărți'
ibargs['data' .. tostring(lineIndex)] = args['no_carti']
lineIndex = lineIndex + 1
ibargs['label' .. tostring(lineIndex)] = 'Format original'
ibargs['data' .. tostring(lineIndex)] = args['format_original'] or args['media_type']
if args['audio_orig'] and (args['format_original'] or args['media_type']) 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'] or args['pages'] or wikidata.findOneValue('P1104')
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
local wikidata_isbn = ""
if isbn10 ~= nil and #isbn10 > 0 then
wikidata_isbn = wikidata_isbn .. table.concat(isbn10, tostring(mw.html.create('br'))) .. tostring(mw.html.create('br'))
end
if isbn13 ~= nil and #isbn13 > 0 then
wikidata_isbn = wikidata_isbn .. table.concat(isbn13, tostring(mw.html.create('br'))) .. tostring(mw.html.create('br'))
end
ibargs['label' .. tostring(lineIndex)] = '[[International Standard Book Number|ISBN]]'
ibargs['data' .. tostring(lineIndex)] = args['isbn'] or wikidata_isbn
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
local dewey = args['dewey'] or wikidata.findOneValue('P1036', nil)
if dewey then
ibargs['label' .. tostring(lineIndex)] = '[[Dewey Decimal Classification|Dewey Decimal]]'
ibargs['data' .. tostring(lineIndex)] = dewey
lineIndex = lineIndex + 1
end
local locClasif = args['congress'] or wikidata.findOneValue('P1149', nil)
if locClasif then
ibargs['label' .. tostring(lineIndex)] = '[[Library of Congress Classification|Clasificare LC]]'
ibargs['data' .. tostring(lineIndex)] = locClasif
lineIndex = lineIndex + 1
end
if args['traducerea'] or args['traducător'] or args['translator'] or args['editura_ro'] or args['data_apariției_în_românia'] or args['romanian_release_date'] or args['romanian_pub_date'] 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'] or args['translator']
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'] or args['romanian_release_date'] or args['romanian_pub_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)] = 'ISBN ro'
ibargs['data' .. tostring(lineIndex)] = args['isbn_ro']
lineIndex = lineIndex + 1
ibargs['label' .. tostring(lineIndex)] = 'Format'
ibargs['data' .. tostring(lineIndex)] = args['format']
if args['audio'] and ibargs['data' .. tostring(lineIndex)] 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'):attr('width', '100%')
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['wikidata'] = 'yes'
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', 'Format:Infobox Book', 'Format:Infocaseta Serie Cărți' } })
return p._infobox(args)
end
return p