Module:Cite Q/sandbox: Difference between revisions

Content deleted Content added
another fallback for the language of the property
populate language from journal
Line 3:
local getValue = wdib._getValue
local getPropOfProp = wdib._getPropOfProp
local followQid = wdib._followQid
 
local simple_properties = { -- PXXX, is multiple?, linked?
Line 9 ⟶ 10:
place = {id="P291", maxvals=0,linked='no'},
doi = {id="P356", maxvals=1},
issue = {id="P433", maxvals=1, populate_from_journal = true},
pmid = {id="P698", maxvals=1},
arxiv = {id="P818", maxvals=1},
Line 24 ⟶ 25:
osti = {id="P3894", maxvals=1},
biorxiv = {id="P3951", maxvals=1},
isbn = {id="P212", maxvals=1, populate_from_journal = true}, -- ISBN 13
chapter = {id="P792", maxvals=1},
["date"] = {id="P577", maxvals=1, populate_from_journal = true},
series = {id="P179", maxvals=1, populate_from_journal = true},
volume = {id="P478", maxvals=1, populate_from_journal = true},
title = {id="P1476", maxvals=1},
url = {id="P953", maxvals=1}, -- full work available at
pages = {id="P304", maxvals=1, populate_from_journal = true},
translator = {id="P655", maxvals=0}, -- does **not** go to "others" section!
illustrator = {id="P110", maxvals=0, others=true}, -- goes to "others" section
Line 224 ⟶ 225:
citeq_args.language = citeq_args.language or getPropOfProp( {qid = qid, prop1 = "P407", prop2 = "P218", ps = 1} )
if not citeq_args.issuelanguage == '' then
citeq_args.language = nil
end
if not citeq_args.volumelanguage then
-- try fallback to journal's language
local journal_qid = followQid({qid = qid, props = "P1433"})
citeq_args.language = journal_qid and getPropOfProp( {qid = journal_qid, prop1 = "P407", prop2 = "P218", ps = 1} )
end
for name, data in pairs(simple_properties) do
citeq_args[name] = getValue( {data.id, ps = 1, qid = qid, maxvals=data.maxvals, linked=data.linked, citeq_args[name] } )
if data.populate_from_journal then
citeq_args['date'name] = getValue( {"P1433", ps = 1, qid = qid, maxvals=0, citeq_args['date'name], qual='P577'data.id, qualsonly='yes' } )
citeq_args[name] = citeq_args[name] or getPropOfProp({qid = qid, prop1 = "P1433", prop2 = data.id})
end
if citeq_args[name] and citeq_args[name]:find('[[Category:Articles with missing Wikidata information]]', 1, true) then
-- try fallback to work's native language
Line 254 ⟶ 268:
citeq_args.url = getValue( {"P856", ps = 1, qid = qid, maxvals=0, citeq_args.url } ) -- try official website
citeq_args.url = getValue( {"P2699", ps = 1, qid = qid, maxvals=0, citeq_args.url } ) -- try url
-- Get extra values if needed
if not citeq_args['date'] then
citeq_args['date'] = getValue( {"P1433", ps = 1, qid = qid, maxvals=0, citeq_args['date'], qual='P577', qualsonly='yes' } )
end
if not citeq_args.issue then
citeq_args.issue = getValue( {"P1433", ps = 1, qid = qid, maxvals=0, citeq_args.issue, qual='P433', qualsonly='yes' } )
end
if not citeq_args.volume then
citeq_args.volume = getValue( {"P1433", ps = 1, qid = qid, maxvals=0, citeq_args.volume, qual='P478', qualsonly='yes' } )
end
if not citeq_args.pages then
citeq_args.pages = getValue( {"P1433", ps = 1, qid = qid, maxvals=0, citeq_args.pages, qual='P304', qualsonly='yes' } )
end
if not citeq_args.isbn then
citeq_args.isbn = getValue( {"P1433", ps = 1, qid = qid, maxvals=0, citeq_args.isbn, qual='P212', qualsonly='yes' } )
end
 
local slink = mw.wikibase.getSitelink(qid)