Refactor cite_q arg processing, i18n string for QID error
This commit is contained in:
parent
35496de2b6
commit
0da5fa4047
2 changed files with 31 additions and 24 deletions
|
|
@ -726,6 +726,7 @@ local function _cite_q (citeq_args)
|
||||||
local wikisource_sitelink = mw.wikibase.getSitelink(qid, cfg.i18n_t.wikisource) or nil
|
local wikisource_sitelink = mw.wikibase.getSitelink(qid, cfg.i18n_t.wikisource) or nil
|
||||||
if wikisource_sitelink then
|
if wikisource_sitelink then
|
||||||
slink = 's:'..wikisource_sitelink; -- use 's:' instead of ':s:' so that cs1|2 includes wikisource icon
|
slink = 's:'..wikisource_sitelink; -- use 's:' instead of ':s:' so that cs1|2 includes wikisource icon
|
||||||
|
citeq_args.via = citeq_args.via or '[[Wikisource]]'; -- set |via=[[Wikisource]] if not already set
|
||||||
wslink = true
|
wslink = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -1120,42 +1121,46 @@ local function _cite_q (citeq_args)
|
||||||
return output .. erratumid .. eoc .. retract .. table.concat(opt_cat, ' ') .. cq_errors
|
return output .. erratumid .. eoc .. retract .. table.concat(opt_cat, ' ') .. cq_errors
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--[[--------------------------< C I T E _ Q >------------------------------------------------------------------
|
||||||
|
|
||||||
|
template entry point
|
||||||
|
|
||||||
|
]]
|
||||||
|
|
||||||
local function cite_q (frame)
|
local function cite_q (frame)
|
||||||
local args = {}
|
local args = require ('Module:Arguments').getArgs(frame);
|
||||||
for k, v in pairs(frame:getParent().args) do
|
|
||||||
if v ~= "" then args[k] = v end
|
|
||||||
end
|
|
||||||
for k, v in pairs(frame.args) do
|
|
||||||
if v ~= "" then args[k] = v end
|
|
||||||
end
|
|
||||||
args.qid = args.qid or args[1] or ""
|
|
||||||
if args.qid == "" then return nil end
|
|
||||||
args[1] = nil
|
|
||||||
|
|
||||||
local citesep = (args.citesep or "")
|
args.qid = args.qid or args[1];
|
||||||
if citesep == "" then citesep = ", " end
|
if not args.qid then return nil end -- this should return an error message?
|
||||||
|
args[1] = nil; -- unset; not needed
|
||||||
|
|
||||||
|
local citesep = args.citesep; -- separator string between separate cites of {{cite q|q..., q...}}; any need to keep this?
|
||||||
|
if not citesep then citesep = ", " end
|
||||||
citesep = citesep:gsub('"', '') -- strip double quotes after setting default to allow |citesep="" as a blank separator
|
citesep = citesep:gsub('"', '') -- strip double quotes after setting default to allow |citesep="" as a blank separator
|
||||||
args.citesep = nil
|
args.citesep = nil; -- unset; not needed
|
||||||
|
|
||||||
local tag = args.tag or ""
|
local tag = args.tag; -- for applying tags like <ref>...</ref>; <tag> is the name of the tag
|
||||||
if tag == "" then tag = nil end
|
-- if not tag then tag = nil end
|
||||||
args.tag = nil
|
args.tag = nil; -- unset; not needed
|
||||||
|
|
||||||
local list = args.list or ""
|
local list = args.list -- undocumented |list= gets a template name; what templates are appropriate? added at [[Special:Diff/1004682832]]
|
||||||
if list == "" then list = nil end
|
-- if list == "" then list = nil end
|
||||||
args.list = nil
|
args.list = nil; -- unset; not needed
|
||||||
|
|
||||||
args.language = args.language or args.lang
|
args.language = args.language or args.lang
|
||||||
args.lang = nil
|
args.lang = nil
|
||||||
|
|
||||||
-- QID as normal form; emit error if not ^Q%d+$ (e.g. a Wikidata URL)
|
-- QID as normal form; emit error if not ^Q%d+$ (e.g. a Wikidata URL)
|
||||||
local qid_form = mw.ustring.match(mw.text.trim(args.qid), "^Q%d+$") or nil
|
-- local qid_form = mw.ustring.match(mw.text.trim(args.qid), "^Q%d+$") or nil
|
||||||
if not qid_form then
|
-- if not qid_form then
|
||||||
return ' <span class="error" style="font-size:inherit"><code class="cs1-code">{{[[Template:Cite Q|Cite Q]]}}</code>: QID parameter must be supplied as "Q" followed by digits, e.g. <code class="cs1-code">Q12345</code> ([[Template:Cite Q#Error messages|help]])</span> ' .. cfg.i18n_t.trackingcats["invalid-qid"]
|
-- return ' <span class="error" style="font-size:inherit"><code class="cs1-code">{{[[Template:Cite Q|Cite Q]]}}</code>: QID parameter must be supplied as "Q" followed by digits, e.g. <code class="cs1-code">Q12345</code> ([[Template:Cite Q#Error messages|help]])</span> ' .. cfg.i18n_t.trackingcats["invalid-qid"]
|
||||||
|
if not args.qid:match ('^Q%d+$') then
|
||||||
|
return cfg.i18n_t.errors.bad_qid_form .. cfg.i18n_t.trackingcats["invalid-qid"];
|
||||||
end
|
end
|
||||||
|
|
||||||
local cites = {}
|
local cites = {}
|
||||||
for q in args.qid:gmatch("Q%d+") do
|
for q in args.qid:gmatch("Q%d+") do -- for processing separate cites of {{cite q|q..., q...}}; any need to keep this?
|
||||||
-- make a new copy of the arguments
|
-- make a new copy of the arguments
|
||||||
local newargs = {}
|
local newargs = {}
|
||||||
for k, v in pairs(args) do
|
for k, v in pairs(args) do
|
||||||
|
|
@ -1172,13 +1177,14 @@ local function cite_q (frame)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if list then
|
if list then -- undocumented |list= gets a template name; what templates are appropriate? added at [[Special:Diff/1004682832]]
|
||||||
return frame:expandTemplate{ title = list, args = cites }
|
return frame:expandTemplate{ title = list, args = cites }
|
||||||
else
|
else
|
||||||
return table.concat(cites, citesep)
|
return table.concat(cites, citesep)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--[[--------------------------< E X P O R T E D F U N C T I O N S >------------------------------------------
|
--[[--------------------------< E X P O R T E D F U N C T I O N S >------------------------------------------
|
||||||
]]
|
]]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ local i18n_t = {
|
||||||
["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"] = {
|
||||||
|
bad_qid_form = ' <span class="error" style="font-size:inherit"><code class="cs1-code">{{[[Template:Cite Q|Cite Q]]}}</code>: QID parameter must be supplied as "Q" followed by digits, e.g. <code class="cs1-code">Q12345</code> ([[Template:Cite Q#Error messages|help]])</span>',
|
||||||
["local-article-not-found"] = "Local article not found.",
|
["local-article-not-found"] = "Local article not found.",
|
||||||
["no-label-or-title"] = "No label or title -- debug: ",
|
["no-label-or-title"] = "No label or title -- debug: ",
|
||||||
missing_name = '%s <span title="edit %s in Wikidata">[[File:Edit icon on Wikisite.svg|14px|class=noviewer|alt=|link=[[:d:%s]] ]]</span>'; -- %s: <name>.label, '<name>', <name>.qid
|
missing_name = '%s <span title="edit %s in Wikidata">[[File:Edit icon on Wikisite.svg|14px|class=noviewer|alt=|link=[[:d:%s]] ]]</span>'; -- %s: <name>.label, '<name>', <name>.qid
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue