Module:Cite Q/sandbox: Difference between revisions

Content deleted Content added
getPropOfProp
populating language
Line 2:
local wdib = require('Module:WikidataIB')
local getValue = wdib._getValue
local getPropOfProp = wdib.getPropOfProp_getPropOfProp
 
local simple_properties = { -- PXXX, is multiple?, linked?
Line 32:
url = {id="P953", maxvals=1}, -- full work available at
pages = {id="P304", maxvals=1},
language = {id="P407", maxvals=1},
translator = {id="P655", maxvals=0}, -- does **not** go to "others" section!
illustrator = {id="P110", maxvals=0, others=true}, -- goes to "others" section
Line 204 ⟶ 203:
function citeq.cite_q (frame)
local citeq_args = {};
local qid;
local wdl;
 
for k, v in pairs(frame:getParent().args) do
Line 214 ⟶ 211:
citeq_args[k] = v
end
local qid = citeq_args.qid
local wdl = citeq_args.wdl
citeq_args[k].qid = nil
citeq_args[k].wdl = nil
local oth = {}
citeq_args.language = citeq_args.language or getPropOfProp( {qid = qid, prop1 = "P407", prop2 = "P218", ps = 1} )
for name, data in pairs(simple_properties) do
citeq_args[name] = getValue( {data.id, ps = 1, qid = citeq_args.qid, maxvals=data.maxvals, linked=data.linked, citeq_args[name] } )
if data.others then
oth[#oth+1] = citeq_args[name] and (name:gsub("^%l", string.upper) .. ": " .. citeq_args[name])
Line 227 ⟶ 231:
citeq_args.journal = citeq_args.journal and citeq_args.journal:gsub("^''", ""):gsub("''$", ""):gsub("|''", "|"):gsub("'']]", "]]")
 
citeq_args.ol = (getValue( {"P648", ps = 1, qid = citeq_args.qid, maxvals=1, citeq_args.ol } ) or ''):gsub("^OL(.+)$", "%1")
citeq_args.biorxiv = citeq_args.biorxiv and ("10.1101/" .. citeq_args.biorxiv)
 
citeq_args.isbn = getValue( {"P957", ps = 1, qid = citeq_args.qid, maxvals=0, citeq_args.isbn } ) -- try ISBN 10
citeq_args.url = getValue( {"P856", ps = 1, qid = citeq_args.qid, maxvals=0, citeq_args.url } ) -- try official website
citeq_args.url = getValue( {"P2699", ps = 1, qid = citeq_args.qid, maxvals=0, citeq_args.url } ) -- try url
local slink = mw.wikibase.getSitelink(citeq_args.qid)
local label = mw.wikibase.getLabel(citeq_args.qid)
if citeq_args.title then
if slink then
Line 267 ⟶ 271:
 
for k, v in pairs(citeq_args) do
if k == 'qid' then
qid = v
citeq_args[k] = nil
elseif k == 'wdlinks' then
wdl = v
citeq_args[k] = nil
end
if v == 'unset' or type(k) ~= 'string' then
citeq_args[k] = nil