Content deleted Content added
import unset ability from Module:Cite Q/sandbox |
Sync from sandbox: rewriting to convert to Lua |
||
Line 1:
require('Module:No globals')
local wdib = require('Module:WikidataIB')
local getValue = wdib._getValue
local citeq = {}
Line 163 ⟶ 166:
function citeq.cite_q (frame)
local citeq_args = {};
local qid;
local wdl;
citeq_args[k] = v
end
for k, v in pairs
citeq_args[k] = v
end
local simple_properties = { -- PXXX, is multiple?, linked?
publisher = {id="P123", maxvals=1},
oclc = {id="P243", maxvals=1},
place = {id="P291", maxvals=0,linked='no'},
doi = {id="P356", maxvals=1},
issue = {id="P433", maxvals=1},
pmid = {id="P698", maxvals=1},
arxiv = {id="P818", maxvals=1},
bibcode = {id="P819", maxvals=1},
jstor = {id="P888", maxvals=1},
mr = {id="P889", maxvals=1},
ssrn = {id="P893", maxvals=1},
pmc = {id="P932", maxvals=1},
lccn = {id="P1144", maxvals=1},
hdl = {id="P1184", maxvals=1},
ismn = {id="P1208", maxvals=1},
journal = {id="P1433", maxvals=1},
citeseerx = {id="P3784", maxvals=1},
osti = {id="P3894", maxvals=1},
biorxiv = {id="P3951", maxvals=1},
isbn = {id="P212", maxvals=1}, -- ISBN 13
illustrator = {id="P110", maxvals=0}, -- goes to "others" section
composer = {id="P86", maxvals=0}, -- goes to "others" section
chapter = {id="P792", maxvals=1},
["date"] = {id="P577", maxvals=1},
series = {id="P179", maxvals=1},
volume = {id="P478", maxvals=1},
title = {id="P1476", maxvals=1},
url = {id="P953", maxvals=1}, -- full work available at
pages = {id="P304", maxvals=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] } )
end
citeq_args.ol = (getValue( {"P648", ps = 1, qid = citeq_args.qid, maxvals=1, citeq_args.ol } ) or ''):gsub("^OL(.+)$", "%1")
if citeq_args.biorxiv then
citeq_args.biorxiv = "10.1101/" .. citeq_args.biorxiv
end
--[[
citeq_args.others = (citeq_args.others or "")
.. (citeq_args.illustrator and "Illustrator:" .. citeq_args.illustrator or "")
.. (citeq_args.composer and "Composer:" .. citeq_args.composer or "")
--]]
if not citeq_args.others then
if citeq_args.illustrator then
citeq_args.others = "Illustrator: " .. citeq_args.illustrator
citeq_args.illustrator = nil
end
if citeq_args.composer then
if not citeq_args.others then
citeq_args.others = "Composer: " .. citeq_args.composer
else
citeq_args
end
citeq_args.composer = nil
end
end
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
citeq_args.url = nil
citeq_args.title = '[[' .. slink .. '|' .. citeq_args.title .. ']]'
end
else
if slink then
citeq_args.url = nil
if slink:lower() == label:lower() then
citeq_args.title = '[[' .. slink .. ']]'
else
citeq_args.title = '[[' .. slink .. '|' .. slink:gsub("%s%(.+%)$", ""):gsub(",.+$", "") .. ']]'
end
else
citeq_args
end
end
if citeq_args.p or citeq_args.page then
citeq_args.pages = nil
end
if citeq_args.pages then
local _, count = string.gsub(citeq_args.pages, " %d+", "")
if count == 1 then
citeq_args.p = citeq_args.pages
citeq_args.pages = nil
end
end
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
end
end
Line 202 ⟶ 296:
end
if citeq_args.mode ~= 'cs1' then
returntext = returntext .. ','
end
returntext = returntext .. ' [[Wikidata]] [[:d:' .. qid .. '|' .. qid .. ']]'
return returntext
end
|