Module:Cite Q: Difference between revisions

Content deleted Content added
stet; bug was at source
rm misplaced tracking category
 
(8 intermediate revisions by 6 users not shown)
Line 1:
-- Version: 2021-0210-2119
 
local p = {}
 
require('Module:No globalsstrict')
local wdib = require('Module:WikidataIB')
local getValue = wdib._getValue
Line 12:
local i18n = {
["unknown-author"] = mw.wikibase.getLabel("Q4233718"):gsub("^%l", mw.ustring.upper),
["unknown-author-trackingcat"] = "", -- [[Category:Cite Q - author unknown]]", removed as misplaced; someone is welcome to restore it if it is placed outside of the template parameter value
["ordinal"] = {
[1] = "st",
Line 175:
if v.qualifiers and v.qualifiers.P1932 then
label = v.qualifiers.P1932[1].datavalue.value
elseif v.qualifiers and v.qualifiers.P1810 then
label = v.qualifiers.P1810[1].datavalue.value
else
label = mw.wikibase.getLabel(qnumber)
Line 220 ⟶ 218:
if v.qualifiers and v.qualifiers.P1932 then
label = v.qualifiers.P1932[1].datavalue.value
elseif v.qualifiers and v.qualifiers.P1810 then
label = v.qualifiers.P1810[1].datavalue.value
else
label = i18n["unknown-author"] .. (i18n["unknown-author-trackingcat"] or "")
Line 274 ⟶ 270:
end
 
local entity = mw.wikibase.getEntity(qid)
local props = nil
local fallback = nil
if mw.wikibase.entityExists(qid) then
if entity and entity.claims then
props = entitymw.claims[wikibase.getAllStatements(qid, propertyID])
if props and fallbackID then
fallback = entitymw.claims[wikibase.getAllStatements(qid, fallbackID])
end
end
Line 316 ⟶ 311:
table.sort(keys) -- as they might be out of order
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
mw.log(i .. " " .. k .. " " .. (out[k]))
if args[nl_type .. i] then -- name gets overwritten
Line 394 ⟶ 390:
-- parameters that don't get passed to Citation
local expand = citeq_args.expand -- when set to anything, causes {{cite q}} to render <code><nowiki>{{citation|...}}</nowiki></code>
local qid = citeq_args[1].qid or citeq_args.qid[1]
local wdl = citeq_args.wdl
local template = citeq_args.template
Line 479 ⟶ 475:
if url then
citeq_args.url = mw.text.split( url, " (", true )[1]
local arcurl = mw.ustring.match( url, " %((.*)%)" ) -- when there is an archive url, <url> holds: url<space>(archive url); here extract the archive url if present
if arcurl then
local arcy, arcm, arcd = arcurl:match("(20%d%d)%p?(%d%d)%p?(%d%d)")
Line 498 ⟶ 494:
 
if not titleforced then
-- Handle subtitle.
if citeq_args.title then
local subtitle = mw.wikibase.getBestStatements (qid, 'P1680');
if 0 ~= #subtitle then
subtitle = subtitle[1].mainsnak.datavalue.value.text;
citeq_args.title = citeq_args.title .. ": " .. subtitle
end
end
local htmltitle = getValue( {"P1476", qual = "P6833", ps = 1, qid = qid, maxvals = 1, qo = "y"} )
if htmltitle then
Line 609 ⟶ 614:
end
if author_count > 8 then -- convention in astronomy journals, optional mode for this?
citeq_args[if 'display-authorsall'] == citeq_args['display-authors'] or 3then
citeq_args['display-authors'] = nil; -- unset because no longer needed
else
citeq_args['display-authors'] = citeq_args['display-authors'] or 3 -- limit to three displayed names
end
end
 
Line 619 ⟶ 628:
end
if editor_count > 8 then -- convention in astronomy journals, optional mode for this?
citeq_args[if 'display-editorsall'] == citeq_args['display-editors'] or 3then
citeq_args['display-editors'] = nil; -- unset because no longer needed
else
citeq_args['display-editors'] = citeq_args['display-editors'] or 3 -- limit to three displayed names
end
end
 
Line 638 ⟶ 651:
-- template is CS1 designator: journal, web, news, etc.
if template then
-- citeq_args.mode = citeq_args.mode or "cs1" -- a cs1 template already knows that it is cs1 so this line is superfluous
template = "Cite " .. template
else
-- citeq_args.mode = citeq_args.mode or "cs2" -- a cs2 template already knows that it is cs2 so this line is superfluous
template = "Citation"
end
Line 684 ⟶ 697:
end
-- make the nowiki'd string and done
return "frame:preprocess (table.concat ({'<code>syntaxhighlight lang="wikitext" ..inline="1">', table.concat (expand_args, ' |') .. "'}}', '</codesyntaxhighlight>"'}));
end