Compare commits
10 commits
61b2d57f61
...
ebba5e8e7f
| Author | SHA1 | Date | |
|---|---|---|---|
| ebba5e8e7f | |||
| 5116c6ad8c | |||
| 57d21267c7 | |||
| bd68a9118e | |||
| 2c0b7f935f | |||
| 881047f7e9 | |||
| f32596a4f8 | |||
| d0298adb5d | |||
| fbc531998a | |||
| 6df6071a72 |
2 changed files with 355 additions and 40 deletions
373
module_citeq.lua
373
module_citeq.lua
|
|
@ -4,10 +4,11 @@ local wdib = require('Module:WikidataIB')
|
||||||
local getValue = wdib._getValue
|
local getValue = wdib._getValue
|
||||||
local _getPropOfProp = wdib._getPropOfProp
|
local _getPropOfProp = wdib._getPropOfProp
|
||||||
local followQid = wdib._followQid
|
local followQid = wdib._followQid
|
||||||
local getPropertyIDs = wdib._getPropertyIDs
|
--local getPropertyIDs = wdib._getPropertyIDs
|
||||||
local cite_cfg = mw.loadData ('Module:Cite/config')
|
local cite_cfg = mw.loadData ('Module:Cite/config')
|
||||||
local cfg = mw.loadData ('Module:Cite_Q/config')
|
local cfg = mw.loadData ('Module:Cite_Q/config/sandbox')
|
||||||
local cs1_module = 'Module:Citation/CS1' -- don't load the module yet, may not be needed
|
local cs1_module = 'Module:Citation/CS1/sandbox' -- don't load the module yet, may not be needed
|
||||||
|
local cs1_cfg = mw.loadData('Module:Citation/CS1/Configuration/sandbox')
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- makeOrdinal needs to be internationalised along with cfg.i18n_t
|
-- makeOrdinal needs to be internationalised along with cfg.i18n_t
|
||||||
|
|
@ -87,8 +88,16 @@ local function makelink(v, out, link, maxpos, wdl)
|
||||||
local qnumber = v.mainsnak.datavalue.value.id
|
local qnumber = v.mainsnak.datavalue.value.id
|
||||||
local sitelink = mw.wikibase.getSitelink(qnumber)
|
local sitelink = mw.wikibase.getSitelink(qnumber)
|
||||||
if qnumber == "Q2818964" then sitelink = nil end -- suppress link to "Various authors"
|
if qnumber == "Q2818964" then sitelink = nil end -- suppress link to "Various authors"
|
||||||
|
|
||||||
|
-- Last name, first name(s)
|
||||||
|
local last_name = getValue({"P734", qid=qnumber, maxvals=1, ps=2})
|
||||||
|
local first_names = getValue({"P735", qid=qnumber, maxvals=0, ps=2})
|
||||||
|
if first_names then
|
||||||
|
first_names = mw.text.trim(first_names:gsub(', ', ' '))
|
||||||
|
end
|
||||||
|
|
||||||
if v.qualifiers and v.qualifiers.P1932 then
|
if v.qualifiers and v.qualifiers.P1932 then
|
||||||
label = v.qualifiers.P1932[1].datavalue.value
|
label = v.qualifiers.P1932[1].datavalue.value -- "object named as"
|
||||||
else
|
else
|
||||||
label = mw.wikibase.getLabel(qnumber)
|
label = mw.wikibase.getLabel(qnumber)
|
||||||
if label then
|
if label then
|
||||||
|
|
@ -99,14 +108,22 @@ local function makelink(v, out, link, maxpos, wdl)
|
||||||
end
|
end
|
||||||
local position = maxpos + 1 -- Default to 'next' author.
|
local position = maxpos + 1 -- Default to 'next' author.
|
||||||
-- use P1545 (series ordinal) instead of default position.
|
-- use P1545 (series ordinal) instead of default position.
|
||||||
if v["qualifiers"] and v.qualifiers["P1545"] and v.qualifiers["P1545"][1] then
|
if v.qualifiers and v.qualifiers.P1545 and v.qualifiers.P1545[1] then
|
||||||
position = tonumber(v.qualifiers["P1545"][1].datavalue.value)
|
position = tonumber(v.qualifiers.P1545[1].datavalue.value)
|
||||||
end
|
end
|
||||||
maxpos = math.max(maxpos, position)
|
maxpos = math.max(maxpos, position)
|
||||||
if sitelink then
|
if sitelink then
|
||||||
-- just the plain name,
|
-- just the plain name,
|
||||||
-- but keep a record of the links, using the same index
|
-- but keep a record of the links, using the same index
|
||||||
|
if last_name and first_names then
|
||||||
|
out[position] = {
|
||||||
|
label = label,
|
||||||
|
last = last_name or nil,
|
||||||
|
first = first_names or nil,
|
||||||
|
}
|
||||||
|
else
|
||||||
out[position] = label
|
out[position] = label
|
||||||
|
end
|
||||||
link[position] = sitelink
|
link[position] = sitelink
|
||||||
else
|
else
|
||||||
if wdl then
|
if wdl then
|
||||||
|
|
@ -119,26 +136,72 @@ local function makelink(v, out, link, maxpos, wdl)
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
-- no Wikidata links wanted, so just give the plain label
|
-- no Wikidata links wanted, so just give the plain label
|
||||||
|
if last_name and first_names then
|
||||||
|
out[position] = {
|
||||||
|
label = label,
|
||||||
|
last = last_name or nil,
|
||||||
|
first = first_names or nil,
|
||||||
|
}
|
||||||
|
else
|
||||||
out[position] = label
|
out[position] = label
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
elseif v.mainsnak.datatype == "string" then
|
elseif v.mainsnak.datatype == "string" then
|
||||||
local position = maxpos + 1 -- Default to 'next' author.
|
local position = maxpos + 1 -- Default to 'next' author.
|
||||||
-- use P1545 (series ordinal) instead of default position.
|
-- use P1545 (series ordinal) instead of default position.
|
||||||
if v["qualifiers"] and v.qualifiers["P1545"] and v.qualifiers["P1545"][1] then
|
if v.qualifiers and v.qualifiers.P1545 and v.qualifiers.P1545[1] then
|
||||||
position = tonumber(v.qualifiers["P1545"][1].datavalue.value)
|
position = tonumber(v.qualifiers.P1545[1].datavalue.value)
|
||||||
end
|
end
|
||||||
maxpos = math.max(maxpos, position)
|
maxpos = math.max(maxpos, position)
|
||||||
|
|
||||||
|
-- Names from "author given names" and "author last names" qualifiers
|
||||||
|
local last_name
|
||||||
|
local first_names
|
||||||
|
if v.qualifiers and v.qualifiers.P9688 and v.qualifiers.P9688[1] then
|
||||||
|
last_name = v.qualifiers.P9688[1].datavalue.value
|
||||||
|
end
|
||||||
|
if v.qualifiers and v.qualifiers.P9687 and v.qualifiers.P9687[1] then
|
||||||
|
first_names = mw.text.trim(v.qualifiers.P9687[1].datavalue.value:gsub(', ', ' '))
|
||||||
|
end
|
||||||
|
|
||||||
|
if last_name and first_names then
|
||||||
|
out[position] = {
|
||||||
|
label = v.mainsnak.datavalue.value,
|
||||||
|
last = last_name or nil,
|
||||||
|
first = first_names or nil,
|
||||||
|
}
|
||||||
|
else
|
||||||
out[position] = v.mainsnak.datavalue.value
|
out[position] = v.mainsnak.datavalue.value
|
||||||
|
end
|
||||||
else
|
else
|
||||||
-- not a wikibase-item or a string!
|
-- not a wikibase-item or a string!
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- code here if we want to return something when author is "unknown"
|
-- try the "object named as" qualifier, otherwise use the unknown author item
|
||||||
if v.qualifiers and v.qualifiers.P1932 then
|
if v.qualifiers and v.qualifiers.P1932 then
|
||||||
label = v.qualifiers.P1932[1].datavalue.value
|
label = v.qualifiers.P1932[1].datavalue.value -- "object named as"
|
||||||
|
|
||||||
|
-- Names from "author given names" and "author last names" qualifiers
|
||||||
|
local last_name
|
||||||
|
local first_names
|
||||||
|
if v.qualifiers and v.qualifiers.P9688 and v.qualifiers.P9688[1] then
|
||||||
|
last_name = v.qualifiers.P9688[1].datavalue.value
|
||||||
|
end
|
||||||
|
if v.qualifiers and v.qualifiers.P9687 and v.qualifiers.P9687[1] then
|
||||||
|
first_names = mw.text.trim(v.qualifiers.P9687[1].datavalue.value:gsub(', ', ' '))
|
||||||
|
end
|
||||||
|
if last_name and first_names then
|
||||||
|
out[position] = {
|
||||||
|
label = label,
|
||||||
|
last = last_name or nil,
|
||||||
|
first = first_names or nil,
|
||||||
|
}
|
||||||
else
|
else
|
||||||
label = cfg.i18n_t["unknown-author"] .. (cfg.i18n_t.trackingcats["unknown-author"] or "")
|
out[position] = label
|
||||||
|
end
|
||||||
|
else
|
||||||
|
label = mw.wikibase.getLabel("Q4233718"):gsub("^%l", mw.ustring.upper) .. (cfg.i18n_t.trackingcats["unknown-author"] or "")
|
||||||
end
|
end
|
||||||
maxpos = maxpos + 1
|
maxpos = maxpos + 1
|
||||||
out[maxpos] = label
|
out[maxpos] = label
|
||||||
|
|
@ -157,8 +220,8 @@ returns nothing; modifies the args table
|
||||||
]=]
|
]=]
|
||||||
|
|
||||||
local function get_name_list (nl_type, args, qid, wdl)
|
local function get_name_list (nl_type, args, qid, wdl)
|
||||||
local propertyID = "P50"
|
local propertyID
|
||||||
local fallbackID = "P2093" -- author name string
|
local fallbackID
|
||||||
|
|
||||||
if nl_type =="author" then
|
if nl_type =="author" then
|
||||||
propertyID = 'P50' -- for authors
|
propertyID = 'P50' -- for authors
|
||||||
|
|
@ -234,15 +297,27 @@ local function get_name_list (nl_type, args, qid, wdl)
|
||||||
end
|
end
|
||||||
table.sort(keys) -- as they might be out of order
|
table.sort(keys) -- as they might be out of order
|
||||||
for i, k in ipairs(keys) do
|
for i, k in ipairs(keys) do
|
||||||
out[k] = out[k]:gsub (''', '\''); -- prevent cs1|2 multiple names categorization; replace html entity with the actual character
|
local label
|
||||||
mw.log(i .. " " .. k .. " " .. (out[k]))
|
if out[k].label then
|
||||||
|
label = out[k].label
|
||||||
|
else
|
||||||
|
label = out[k]
|
||||||
|
end
|
||||||
|
label = label:gsub(''', '\''); -- prevent cs1|2 multiple names categorization; replace html entity with the actual character
|
||||||
|
mw.log(i .. " " .. k .. " " .. label)
|
||||||
if args[nl_type .. i] then -- name gets overwritten
|
if args[nl_type .. i] then -- name gets overwritten
|
||||||
-- pull corresponding -link only if overwritten name is same as WD name
|
-- pull corresponding -link only if overwritten name is same as WD name
|
||||||
if link[k] and (args[nl_type .. i] == out[k]) then
|
if link[k] and (args[nl_type .. i] == label) then
|
||||||
args[nl_type .. '-link' .. i] = args[nl_type .. '-link' .. i] or link[k] -- author-linkn or editor-linkn
|
args[nl_type .. '-link' .. i] = args[nl_type .. '-link' .. i] or link[k] -- author-linkn or editor-linkn
|
||||||
end
|
end
|
||||||
else -- name does not get overwritten, so pull name from WD
|
else -- name does not get overwritten, so pull name from WD
|
||||||
args[nl_type .. i] = out[k]
|
if out[k].first and out[k].last then
|
||||||
|
-- First/last names were found, so add them
|
||||||
|
args[nl_type .. '-last' .. i] = args[nl_type .. '-last' .. i] or out[k].last
|
||||||
|
args[nl_type .. '-first' .. i] = args[nl_type .. '-first' .. i] or out[k].first
|
||||||
|
else
|
||||||
|
args[nl_type .. i] = label
|
||||||
|
end
|
||||||
if link[k] then
|
if link[k] then
|
||||||
args[nl_type .. '-link' .. i] = args[nl_type .. '-link' .. i] or link[k] -- author-linkn or editor-linkn
|
args[nl_type .. '-link' .. i] = args[nl_type .. '-link' .. i] or link[k] -- author-linkn or editor-linkn
|
||||||
end
|
end
|
||||||
|
|
@ -272,11 +347,12 @@ end
|
||||||
|
|
||||||
-- gets the language codes of a Wikidata entry as a table
|
-- gets the language codes of a Wikidata entry as a table
|
||||||
local function _lang_code(qid)
|
local function _lang_code(qid)
|
||||||
local lc = _getPropOfProp( {qid = qid, prop1 = "P407", prop2 = "P424", ps = 1} )
|
-- P407 "language of work or name"
|
||||||
|
local lc = _getPropOfProp( {qid = qid, prop1 = "P407", prop2 = "P424", ps = 1} ) -- "Wikimedia language code"
|
||||||
if lc then return mw.text.split( lc, "[, ]+" ) end
|
if lc then return mw.text.split( lc, "[, ]+" ) end
|
||||||
lc = _getPropOfProp( {qid = qid, prop1 = "P407", prop2 = "P218", ps = 1} )
|
lc = _getPropOfProp( {qid = qid, prop1 = "P407", prop2 = "P218", ps = 1} ) -- "ISO 639-1 code"
|
||||||
if lc then return mw.text.split( lc, "[, ]+" ) end
|
if lc then return mw.text.split( lc, "[, ]+" ) end
|
||||||
return _getLangOfProp(qid, "P1476")
|
return _getLangOfProp(qid, "P1476") -- "title"
|
||||||
end
|
end
|
||||||
local function lang_code(frame)
|
local function lang_code(frame)
|
||||||
return table.concat(_lang_code(frame.args.qid or mw.text.trim(frame.args[1] or "")), ", ")
|
return table.concat(_lang_code(frame.args.qid or mw.text.trim(frame.args[1] or "")), ", ")
|
||||||
|
|
@ -293,6 +369,101 @@ local function wrap_nowiki(str, disable)
|
||||||
return mw.text.nowiki(str or '')
|
return mw.text.nowiki(str or '')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- returns the first string sequence of 3 or more digits in a date string, or nil
|
||||||
|
local function yearFromDate(datestr)
|
||||||
|
if datestr then
|
||||||
|
return string.match(datestr, '%d%d%d+')
|
||||||
|
end
|
||||||
|
return datestr
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Attempt to determine heuristically if we're citing a news article
|
||||||
|
local function isNewsArticle(qid, args)
|
||||||
|
local newsitems = {
|
||||||
|
'Q5707594', -- news article
|
||||||
|
'Q30070590', -- magazine article
|
||||||
|
-- TODO: somehow use WHERE {?item (wdt:P31|wdt:P31/wdt:P279*) wd:Q5707594.}
|
||||||
|
-- main subclasses of news article:
|
||||||
|
'Q87849013', -- AP article
|
||||||
|
'Q2144639', -- feature story
|
||||||
|
'Q139172839', -- top story
|
||||||
|
'Q18339884', -- cover story
|
||||||
|
'Q3326038', -- critical review
|
||||||
|
'Q4202018', -- interview
|
||||||
|
'Q309481', -- obituary
|
||||||
|
'Q108970988', -- column
|
||||||
|
'Q2602337', -- op-ed
|
||||||
|
'Q59908', -- opinion piece
|
||||||
|
}
|
||||||
|
-- most of the time a cheap lookup to a single value will work
|
||||||
|
if args['instance-of'] and in_array(args['instance-of'], newsitems) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
-- otherwise check multiple non-deprecated values
|
||||||
|
local instance_of = mw.wikibase.getBestStatements(qid, 'P31')
|
||||||
|
if instance_of and instance_of[1] then
|
||||||
|
for k, v in pairs(instance_of) do
|
||||||
|
if v.mainsnak.snaktype == "value" and v.mainsnak.datatype == "wikibase-item" then
|
||||||
|
if in_array(v.mainsnak.datavalue.value.id, newsitems) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Figure out a URL access value, from the "online access status" (P6954) qualifier of an identifier
|
||||||
|
-- The [[Template:Cite journal]] docs state these should only allow "free"
|
||||||
|
-- e.g. DOI = P356
|
||||||
|
local function getIdentifierAccess(qid, args, identifier)
|
||||||
|
if not args[identifier] then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
-- check DOI registrant is known free, using CS1 config
|
||||||
|
-- TODO: this should also be modelled in Wikidata
|
||||||
|
if identifier == 'doi' then
|
||||||
|
local registrant, suffix = mw.ustring.match(args.doi:lower(), '^10%.([^/]+)/([^%s–]+)$');
|
||||||
|
if registrant and suffix and cs1_cfg.known_free_doi_registrants_t[registrant] then
|
||||||
|
return 'free'
|
||||||
|
elseif registrant and suffix and cs1_cfg.extended_registrants_t[registrant] then
|
||||||
|
for _, incipit in ipairs(cs1_cfg.extended_registrants_t[registrant]) do
|
||||||
|
if mw.ustring.find (suffix, '^' .. incipit:lower()) then
|
||||||
|
return 'free'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- fetch statement values to examine qualifiers
|
||||||
|
local ids = mw.wikibase.getBestStatements(qid, cfg.simple_properties_t[identifier]['id'])
|
||||||
|
if not ids or not ids[1] then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
if not ids[1].qualifiers or not ids[1].qualifiers.P6954 then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Check property constraints (P2302) in definition of online access status (P6954)
|
||||||
|
-- Q66439598 = 'limited', -- partial open access
|
||||||
|
-- Q107459441 = 'registration', -- registration required
|
||||||
|
-- Q910845 = 'subscription', -- paywall
|
||||||
|
-- Q16572632 = 'subscription', -- login (see note on P6954)
|
||||||
|
local free_status = {
|
||||||
|
'Q24707952', -- free to read
|
||||||
|
'Q232932', -- open access
|
||||||
|
}
|
||||||
|
local access = ids[1].qualifiers.P6954[1]
|
||||||
|
if access.datatype == "wikibase-item" then
|
||||||
|
local accessQID = access.datavalue.value.id
|
||||||
|
if in_array(accessQID, free_status) then
|
||||||
|
return 'free'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
-- sort sequence table whose values are key-value pairs by key
|
-- sort sequence table whose values are key-value pairs by key
|
||||||
local function comp_key(a, b)
|
local function comp_key(a, b)
|
||||||
local param_a, enum_a = a[1]:match ('(%D+)(%d+)$'); -- get param name and enumerator from <a>
|
local param_a, enum_a = a[1]:match ('(%D+)(%d+)$'); -- get param name and enumerator from <a>
|
||||||
|
|
@ -357,7 +528,15 @@ local function _cite_q (citeq_args)
|
||||||
|
|
||||||
-- loop through list of simple properties and get their values in citeq_args
|
-- loop through list of simple properties and get their values in citeq_args
|
||||||
for name, data in pairs(cfg.simple_properties_t) do
|
for name, data in pairs(cfg.simple_properties_t) do
|
||||||
|
if data.qidonly then
|
||||||
|
citeq_args[name] = followQid({qid = qid, props = data.id})
|
||||||
|
if citeq_args[name] == qid then
|
||||||
|
citeq_args[name] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not citeq_args[name] then
|
||||||
citeq_args[name] = getValue( {data.id, fwd = "ALL", osd = "no", noicon = "true", qid = qid, maxvals = data.maxvals, linked = data.linked, rank = data.rank or "best", citeq_args[name] } )
|
citeq_args[name] = getValue( {data.id, fwd = "ALL", osd = "no", noicon = "true", qid = qid, maxvals = data.maxvals, linked = data.linked, rank = data.rank or "best", citeq_args[name] } )
|
||||||
|
end
|
||||||
if data.populate_from_journal then
|
if data.populate_from_journal then
|
||||||
local publishedin = getValue( {"P1433", ps = 1, qid = qid, maxvals = 0, citeq_args[name], qual = data.id, qualsonly = 'yes'} )
|
local publishedin = getValue( {"P1433", ps = 1, qid = qid, maxvals = 0, citeq_args[name], qual = data.id, qualsonly = 'yes'} )
|
||||||
citeq_args[name] = publishedin or _getPropOfProp({qid = qid, prop1 = "P1433", prop2 = data.id, maxvals = data.maxvals, ps = 1})
|
citeq_args[name] = publishedin or _getPropOfProp({qid = qid, prop1 = "P1433", prop2 = data.id, maxvals = data.maxvals, ps = 1})
|
||||||
|
|
@ -385,6 +564,17 @@ local function _cite_q (citeq_args)
|
||||||
|
|
||||||
citeq_args.doi = citeq_args.doi and citeq_args.doi:lower() or nil; -- force |doi= value to be lower case
|
citeq_args.doi = citeq_args.doi and citeq_args.doi:lower() or nil; -- force |doi= value to be lower case
|
||||||
|
|
||||||
|
-- URL access for identifiers, from P6954 online access status
|
||||||
|
-- The [[Template:Cite journal]] docs state these should only allow "free"
|
||||||
|
citeq_args['bibcode-access'] = citeq_args['bibcode-access'] or getIdentifierAccess(qid, citeq_args, 'bibcode');
|
||||||
|
citeq_args['doi-access'] = citeq_args['doi-access'] or getIdentifierAccess(qid, citeq_args, 'doi');
|
||||||
|
citeq_args['hdl-access'] = citeq_args['hdl-access'] or getIdentifierAccess(qid, citeq_args, 'hdl');
|
||||||
|
citeq_args['jstor-access'] = citeq_args['jstor-access'] or getIdentifierAccess(qid, citeq_args, 'jstor');
|
||||||
|
-- citeq_args['ol-access'] = citeq_args['ol-access'] or getIdentifierAccess(qid, citeq_args, 'ol');
|
||||||
|
citeq_args['osti-access'] = citeq_args['osti-access'] or getIdentifierAccess(qid, citeq_args, 'osti');
|
||||||
|
citeq_args['ssrn-access'] = citeq_args['ssrn-access'] or getIdentifierAccess(qid, citeq_args, 'ssrn');
|
||||||
|
citeq_args['s2cid-access'] = citeq_args['s2cid-access'] or getIdentifierAccess(qid, citeq_args, 's2cid');
|
||||||
|
|
||||||
citeq_args.others = citeq_args.others or table.concat(oth, ". ")
|
citeq_args.others = citeq_args.others or table.concat(oth, ". ")
|
||||||
if citeq_args.others == "" then
|
if citeq_args.others == "" then
|
||||||
citeq_args.others = nil
|
citeq_args.others = nil
|
||||||
|
|
@ -427,6 +617,19 @@ local function _cite_q (citeq_args)
|
||||||
if stated_as then citeq_args.publisher = stated_as end
|
if stated_as then citeq_args.publisher = stated_as end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Handle thesis args - degree, supervising institution
|
||||||
|
local is_thesis = false
|
||||||
|
if citeq_args.thesis_degree then
|
||||||
|
is_thesis = true
|
||||||
|
citeq_args.degree = citeq_args.thesis_degree
|
||||||
|
citeq_args.thesis_degree = nil
|
||||||
|
end
|
||||||
|
if citeq_args.thesis_submitted_to then
|
||||||
|
is_thesis = true
|
||||||
|
citeq_args.publisher = citeq_args.thesis_submitted_to
|
||||||
|
citeq_args.thesis_submitted_to = nil
|
||||||
|
end
|
||||||
|
|
||||||
if not titleforced then
|
if not titleforced then
|
||||||
-- Handle subtitle.
|
-- Handle subtitle.
|
||||||
if citeq_args.title then
|
if citeq_args.title then
|
||||||
|
|
@ -573,11 +776,37 @@ local function _cite_q (citeq_args)
|
||||||
|
|
||||||
-- code to make a guess what template to use from the supplied parameters
|
-- code to make a guess what template to use from the supplied parameters
|
||||||
-- (first draft for proof-of-concept)
|
-- (first draft for proof-of-concept)
|
||||||
if citeq_args.isbn then
|
local pubyear = yearFromDate(citeq_args['publication-date'])
|
||||||
template = template or "book"
|
local is_news = isNewsArticle(qid, citeq_args)
|
||||||
citeq_args.asin = nil -- suppress ASIN if ISBN exists
|
if is_news then
|
||||||
|
template = template or "news"
|
||||||
|
-- some items use P123 (publisher) as the newspaper instead of P1433 (published in)
|
||||||
|
if citeq_args.publisher and not citeq_args.journal then
|
||||||
|
citeq_args.journal = citeq_args.publisher
|
||||||
|
citeq_args.publisher = nil
|
||||||
|
end
|
||||||
elseif citeq_args.journal then
|
elseif citeq_args.journal then
|
||||||
template = template or "journal"
|
template = template or "journal"
|
||||||
|
citeq_args['publication-date'] = pubyear or citeq_args['publication-date']
|
||||||
|
-- articles can be published in books/proceedings, otherwise suppress publisher
|
||||||
|
if not citeq_args.isbn then
|
||||||
|
citeq_args.publisher = nil
|
||||||
|
end
|
||||||
|
-- only display ISSN if there are no article identifiers
|
||||||
|
if citeq_args.issn then
|
||||||
|
if citeq_args.doi or citeq_args.pmid or citeq_args.pmc or citeq_args.arxiv or
|
||||||
|
citeq_args.bibcode or citeq_args.jstor or citeq_args.ssrn or citeq_args.s2cid or
|
||||||
|
citeq_args.hdl or citeq_args.biorxiv or citeq_args.osti or citeq_args.zbl or
|
||||||
|
citeq_args.jfm or citeq_args.mr then
|
||||||
|
citeq_args.issn = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elseif is_thesis then
|
||||||
|
template = template or "thesis"
|
||||||
|
elseif citeq_args.isbn then
|
||||||
|
template = template or "book"
|
||||||
|
citeq_args.asin = nil -- suppress ASIN if ISBN exists
|
||||||
|
citeq_args['publication-date'] = pubyear or citeq_args['publication-date']
|
||||||
elseif citeq_args.website then
|
elseif citeq_args.website then
|
||||||
template = template or "web"
|
template = template or "web"
|
||||||
end
|
end
|
||||||
|
|
@ -598,6 +827,36 @@ local function _cite_q (citeq_args)
|
||||||
citeq_args.id = id
|
citeq_args.id = id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local opt_cat = ''
|
||||||
|
|
||||||
|
-- Indicator if item has been retracted
|
||||||
|
local retract = ''
|
||||||
|
if citeq_args.retracted_by then
|
||||||
|
opt_cat = cfg.i18n_t.trackingcats.retracted
|
||||||
|
local retract_id = string.gsub(citeq_args.retracted_by, 'Q', '')
|
||||||
|
local retr_params = {
|
||||||
|
citeq = 'yes',
|
||||||
|
id = frame:expandTemplate{
|
||||||
|
title = 'QID', args = {qid = retract_id}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
retr_params.doi = getValue({"P356", ps = 1, qid = citeq_args.retracted_by}) or nil
|
||||||
|
retr_params.doi = retr_params.doi and retr_params.doi:lower() or nil
|
||||||
|
retr_params.bibcode = getValue({"P819", ps = 1, qid = citeq_args.retracted_by}) or nil
|
||||||
|
retr_params.pmc = getValue({"P932", ps = 1, qid = citeq_args.retracted_by}) or nil
|
||||||
|
retr_params.pmid = getValue({"P698", ps = 1, qid = citeq_args.retracted_by}) or nil
|
||||||
|
-- check qualifiers for access=free
|
||||||
|
retr_params['doi-access'] = getIdentifierAccess(citeq_args.retracted_by, retr_params, 'doi')
|
||||||
|
retr_params['bibcode-access'] = getIdentifierAccess(citeq_args.retracted_by, retr_params, 'bibcode')
|
||||||
|
if 'yes' == citeq_args['retracted-intentional'] then
|
||||||
|
retr_params.intentional = 'yes'
|
||||||
|
end
|
||||||
|
retract = ' ' .. frame:expandTemplate{ title = "Retracted", args = retr_params }
|
||||||
|
end
|
||||||
|
-- remove non-CS1 retraction properties
|
||||||
|
citeq_args.retracted_by = nil
|
||||||
|
citeq_args['retracted-intentional'] = nil
|
||||||
|
|
||||||
-- clean up any blank parameters
|
-- clean up any blank parameters
|
||||||
for k, v in pairs(citeq_args) do
|
for k, v in pairs(citeq_args) do
|
||||||
if v == "" then citeq_args[k] = nil end
|
if v == "" then citeq_args[k] = nil end
|
||||||
|
|
@ -625,24 +884,72 @@ local function _cite_q (citeq_args)
|
||||||
return frame:preprocess (table.concat ({'<syntaxhighlight lang="wikitext" inline="1">', table.concat (expand_args, ' |') .. '}}', '</syntaxhighlight>'}));
|
return frame:preprocess (table.concat ({'<syntaxhighlight lang="wikitext" inline="1">', table.concat (expand_args, ' |') .. '}}', '</syntaxhighlight>'}));
|
||||||
end
|
end
|
||||||
|
|
||||||
local erratumid = getPropertyIDs( { "P2507", qid = qid, fwd = "ALL", osd = "no", rank = "best", maxvals = 1 } )
|
-- Indicator if item has corrigendum/erratum
|
||||||
if erratumid then
|
local erratumid = ""
|
||||||
erratumid = " [[d:" .. erratumid .. "|" .. cfg.i18n_t.erratum .. "]]" .. cfg.i18n_t.trackingcats.erratum
|
if citeq_args.erratum then
|
||||||
else
|
opt_cat = opt_cat .. cfg.i18n_t.trackingcats.erratum
|
||||||
erratumid = ""
|
local erratum_params = {
|
||||||
|
citeq = 'yes',
|
||||||
|
id = frame:expandTemplate{
|
||||||
|
title = 'QID', args = {qid = string.gsub(citeq_args.erratum, 'Q', '')}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
erratum_params.doi = getValue({"P356", ps = 1, qid = citeq_args.erratum}) or nil
|
||||||
|
erratum_params.doi = erratum_params.doi and erratum_params.doi:lower() or nil
|
||||||
|
erratum_params.bibcode = getValue({"P819", ps = 1, qid = citeq_args.erratum}) or nil
|
||||||
|
erratum_params.pmc = getValue({"P932", ps = 1, qid = citeq_args.erratum}) or nil
|
||||||
|
erratum_params.pmid = getValue({"P698", ps = 1, qid = citeq_args.erratum}) or nil
|
||||||
|
-- check qualifiers for access=free
|
||||||
|
erratum_params['doi-access'] = getIdentifierAccess(citeq_args.erratum, erratum_params, 'doi')
|
||||||
|
erratum_params['bibcode-access'] = getIdentifierAccess(citeq_args.erratum, erratum_params, 'bibcode')
|
||||||
|
if 'yes' == citeq_args['erratum-checked'] then
|
||||||
|
erratum_params.checked = 'yes'
|
||||||
end
|
end
|
||||||
|
erratumid = ' ' .. frame:expandTemplate{ title = "Erratum", args = erratum_params }
|
||||||
|
end
|
||||||
|
citeq_args.erratum = nil
|
||||||
|
citeq_args['erratum-checked'] = nil
|
||||||
|
|
||||||
local opt_cat = ''
|
-- Indicator if item has an expression of concern notice (P14891)
|
||||||
if getValue( {"P5824", ps = 1, qid = qid} ) then
|
local eoc = ""
|
||||||
opt_cat = cfg.i18n_t.trackingcats.retracted
|
if citeq_args['expression-of-concern'] then
|
||||||
|
opt_cat = opt_cat .. cfg.i18n_t.trackingcats['expression-of-concern']
|
||||||
|
local eoc_params = {
|
||||||
|
citeq = 'yes',
|
||||||
|
id = frame:expandTemplate{
|
||||||
|
title = 'QID', args = {qid = string.gsub(citeq_args['expression-of-concern'], 'Q', '')}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
eoc_params.doi = getValue({"P356", ps = 1, qid = citeq_args['expression-of-concern']}) or nil
|
||||||
|
eoc_params.doi = eoc_params.doi and eoc_params.doi:lower() or nil
|
||||||
|
eoc_params.bibcode = getValue({"P819", ps = 1, qid = citeq_args['expression-of-concern']}) or nil
|
||||||
|
eoc_params.pmc = getValue({"P932", ps = 1, qid = citeq_args['expression-of-concern']}) or nil
|
||||||
|
eoc_params.pmid = getValue({"P698", ps = 1, qid = citeq_args['expression-of-concern']}) or nil
|
||||||
|
-- check qualifiers for access=free
|
||||||
|
eoc_params['doi-access'] = getIdentifierAccess(citeq_args['expression-of-concern'], eoc_params, 'doi')
|
||||||
|
eoc_params['bibcode-access'] = getIdentifierAccess(citeq_args['expression-of-concern'], eoc_params, 'bibcode')
|
||||||
|
if 'yes' == citeq_args['eoc-intentional'] then
|
||||||
|
eoc_params.intentional = 'yes'
|
||||||
end
|
end
|
||||||
if getValue( {"P1366", ps = 1, qid = qid} ) then
|
eoc = ' ' .. frame:expandTemplate{ title = "Expression of concern", args = eoc_params }
|
||||||
|
end
|
||||||
|
citeq_args['expression-of-concern'] = nil
|
||||||
|
citeq_args['eoc-intentional'] = nil
|
||||||
|
|
||||||
|
if citeq_args.replaced_by then
|
||||||
opt_cat = opt_cat .. cfg.i18n_t.trackingcats.replaced
|
opt_cat = opt_cat .. cfg.i18n_t.trackingcats.replaced
|
||||||
|
citeq_args.replaced_by = nil
|
||||||
end
|
end
|
||||||
if not citeq_args.title then -- emit category link if missing title
|
if not citeq_args.title then -- emit category link if missing title
|
||||||
opt_cat = opt_cat .. cfg.i18n_t.trackingcats['no-label-or-title'];
|
opt_cat = opt_cat .. cfg.i18n_t.trackingcats['no-label-or-title'];
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Disable CiteSeerX IDs for now
|
||||||
|
citeq_args.citeseerx = nil
|
||||||
|
|
||||||
|
-- remove any remaining non-CS1 fields
|
||||||
|
citeq_args['instance-of'] = nil
|
||||||
|
|
||||||
-- render the template
|
-- render the template
|
||||||
local lc_template = template and template:lower() or "citation"
|
local lc_template = template and template:lower() or "citation"
|
||||||
local output
|
local output
|
||||||
|
|
@ -654,7 +961,7 @@ local function _cite_q (citeq_args)
|
||||||
title = "Cite "..template, args = citeq_args
|
title = "Cite "..template, args = citeq_args
|
||||||
} .. cfg.i18n_t.trackingcats["unknown-template"]
|
} .. cfg.i18n_t.trackingcats["unknown-template"]
|
||||||
end
|
end
|
||||||
return output .. erratumid .. opt_cat
|
return output .. erratumid .. eoc .. retract .. opt_cat
|
||||||
end
|
end
|
||||||
|
|
||||||
local function cite_q (frame)
|
local function cite_q (frame)
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ settings definitions for i18n
|
||||||
local i18n_t = {
|
local i18n_t = {
|
||||||
["cite_q"] = "{{cite Q|",
|
["cite_q"] = "{{cite Q|",
|
||||||
["erratum"] = "(erratum)",
|
["erratum"] = "(erratum)",
|
||||||
["unknown-author"] = mw.wikibase.getLabel("Q4233718"):gsub("^%l", mw.ustring.upper),
|
|
||||||
["wdq"] = "[[WDQ (identifier)|Wikidata]]", -- go through "WDQ (identifier)" redirect to reduce clutter in "What links here" and improve reverse lookup. Keep in sync with {{QID}}.
|
["wdq"] = "[[WDQ (identifier)|Wikidata]]", -- go through "WDQ (identifier)" redirect to reduce clutter in "What links here" and improve reverse lookup. Keep in sync with {{QID}}.
|
||||||
["wikisource"] = "enwikisource",
|
["wikisource"] = "enwikisource",
|
||||||
["errors"] = {
|
["errors"] = {
|
||||||
|
|
@ -25,6 +24,7 @@ local i18n_t = {
|
||||||
["default"] = "th"
|
["default"] = "th"
|
||||||
},
|
},
|
||||||
["trackingcats"] = {
|
["trackingcats"] = {
|
||||||
|
['expression-of-concern'] = "[[Category:Cite Q - cites a work with an expression of concern notice]]",
|
||||||
["erratum"] = "[[Category:Cite Q - cites a work with an erratum]]",
|
["erratum"] = "[[Category:Cite Q - cites a work with an erratum]]",
|
||||||
["missing-wikidata"] = "[[Category:Articles with missing Wikidata information]]", -- TODO: point to a {{cite q}}-specific category; this one is specific to Module:WikidataIB
|
["missing-wikidata"] = "[[Category:Articles with missing Wikidata information]]", -- TODO: point to a {{cite q}}-specific category; this one is specific to Module:WikidataIB
|
||||||
['no-label-or-title'] = '[[Category:Cite Q - missing label or title]]',
|
['no-label-or-title'] = '[[Category:Cite Q - missing label or title]]',
|
||||||
|
|
@ -44,6 +44,7 @@ id = PXXX
|
||||||
|
|
||||||
maxvals = maximum number of multiple values (0 for all)
|
maxvals = maximum number of multiple values (0 for all)
|
||||||
linked = "no" suppresses linking
|
linked = "no" suppresses linking
|
||||||
|
qidonly = true - fetch the QID rather than the label string
|
||||||
populate_from_journal = true/false determines whether to look in a journal where the source is published
|
populate_from_journal = true/false determines whether to look in a journal where the source is published
|
||||||
rank = "best", "preferred", normal, etc. determines how Wikidata ranks are treated
|
rank = "best", "preferred", normal, etc. determines how Wikidata ranks are treated
|
||||||
others = true - the value for the property goes to "others" section
|
others = true - the value for the property goes to "others" section
|
||||||
|
|
@ -71,7 +72,14 @@ local simple_properties_t = {
|
||||||
hdl = {id = "P1184", maxvals = 1}, -- take care of |hdl-access=?
|
hdl = {id = "P1184", maxvals = 1}, -- take care of |hdl-access=?
|
||||||
ismn = {id = "P1208", maxvals = 1},
|
ismn = {id = "P1208", maxvals = 1},
|
||||||
journal = {id = "P1433", maxvals = 1},
|
journal = {id = "P1433", maxvals = 1},
|
||||||
citeseerx = {id = "P3784", maxvals = 1},
|
['instance-of'] = {id = "P31", qidonly=true, maxvals = 5}, -- transient, non-CS1
|
||||||
|
thesis_degree = {id = "P13338", maxvals = 1}, -- transient, non-CS1
|
||||||
|
thesis_submitted_to = {id = "P4101", maxvals = 1}, -- transient, non-CS1
|
||||||
|
retracted_by = {id = "P5824", qidonly=true, maxvals = 1}, -- transient, non-CS1
|
||||||
|
replaced_by = {id = "P1366", qidonly=true, maxvals = 1}, -- transient, non-CS1
|
||||||
|
erratum = {id = "P2507", qidonly=true, maxvals = 1}, -- transient, non-CS1
|
||||||
|
['expression-of-concern'] = {id = "P14891", qidonly=true, maxvals = 1}, -- transient, non-CS1
|
||||||
|
-- citeseerx = {id = "P3784", maxvals = 1},
|
||||||
osti = {id = "P3894", maxvals = 1}, -- take care of |osti-access=?
|
osti = {id = "P3894", maxvals = 1}, -- take care of |osti-access=?
|
||||||
biorxiv = {id = "P3951", maxvals = 1},
|
biorxiv = {id = "P3951", maxvals = 1},
|
||||||
asin = {id = "P5749", maxvals = 1}, -- What about |asin-tld=? (WD examples resolve to .com at present, but may change)
|
asin = {id = "P5749", maxvals = 1}, -- What about |asin-tld=? (WD examples resolve to .com at present, but may change)
|
||||||
|
|
@ -115,4 +123,4 @@ local simple_properties_t = {
|
||||||
return {
|
return {
|
||||||
i18n_t = i18n_t,
|
i18n_t = i18n_t,
|
||||||
simple_properties_t = simple_properties_t,
|
simple_properties_t = simple_properties_t,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue