Module:Cite Q: Difference between revisions

Content deleted Content added
make function exportable; improve title linking; minor bugfix
Tag: Reverted
restoring to check line feed error
Line 1:
-- Version: 20212020-0112-0926
 
local pciteq = {}
 
require('Module:No globals')
Line 25:
-- we need three exceptions in English for 1st, 2nd, 3rd, 21st, .. 31st, etc.
-------------------------------------------------------------------------------
p.local makeOrdinal = function(cardinal)
local card = tonumber(cardinal)
if not card then return cardinal end
Line 224:
end
return maxpos
end -- of local function makelink
end
 
--[=[-------------------------< G E T _ N A M E _ L I S T >----------------------------------------------------
Line 339:
end
 
function pciteq._cite_qcite_q (citeq_argsframe)
local frameciteq_args = mw.getCurrentFrame(){};
local expand = '' -- when set to anything, causes {{cite q}} to render <code><nowiki>{{citation|...}}</nowiki></code>
 
for k, v in pairs(frame:getParent().args) do
if in_array (k, {'expand', '_debug'}) then
if is_set(v) then
expand = v -- record setting but don't pass |expand= to {{citation}}
end
else
if v ~= "" then citeq_args[k] = v end
end
end
 
for k, v in pairs(frame.args) do
if v ~= "" then citeq_args[k] = v end
end
 
-- parameters that don't get passed to Citation
local qid = citeq_args.qid
local expand = citeq_args.expand -- when set to anything, causes {{cite q}} to render <code><nowiki>{{citation|...}}</nowiki></code>
local qid = citeq_args[1] or citeq_args.qid
local wdl = citeq_args.wdl
local template = citeq_args.template
citeq_args.expand = nil
citeq_args[1] = nil
citeq_args.qid = nil
citeq_args.wdl = nil
citeq_args.template = nil
 
-- if title supplied, flag to not read html title
local titleforced = (citeq_args.title ~= nil)
 
Line 371 ⟶ 382:
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] } )
if data.populate_from_journal then
local publishedinciteq_args[name] = getValue( {"P1433", ps = 1, qid = qid, maxvals = 0, citeq_args[name], qual = data.id, qualsonly = 'yes'} )
citeq_args[name] = publishedinciteq_args[name] or getPropOfProp({qid = qid, prop1 = "P1433", prop2 = data.id, maxvals = data.maxvals, ps = 1})
end
if citeq_args[name] and citeq_args[name]:find('[[Category:Articles with missing Wikidata information]]', 1, true) then
Line 412 ⟶ 423:
citeq_args.url = getValue( {"P2699", ps = 1, qid = qid, maxvals = 0, citeq_args.url } ) -- try url
 
local slink = mw.wikibase.getSitelink(qid)
if citeq_args.publisher == "Unknown" then -- look for "stated as" (P1932)
local label = mw.wikibase.getLabel(qid) or citeq_args.language and mw.wikibase.getLabelByLang(qid, citeq_args.language)
local stated_as = getValue( {"P123", ps = 1, qid = qid, maxvals = 1, qual="P1932", qo="y"} )
local slink_flag = false
if stated_as then citeq_args.publisher = stated_as end
local wrap_title = ''
end
if citeq_args.title then
 
if not titleforcedslink then
citeq_args.url = nil
local htmltitle = getValue( {"P1476", qual = "P6833", ps = 1, qid = qid, maxvals = 1, qo = "y"} )
wrap_title = wrap_nowiki(citeq_args.title, titleforced)
if htmltitle then
slink_flag = true
citeq_args.title = htmltitle:gsub("</?i>", "''")
else
local title_displayciteq_args.title = wrap_nowiki(citeq_args.title, titleforced)
end
or mw.wikibase.getLabel(qid)
else
or (citeq_args.language and mw.wikibase.getLabelByLang(qid, citeq_args.language))
if slink then
or ("No label or title -- debug: " .. qid)
if citeq_args.url then= nil
if slink:lower() == label:lower() then
citeq_args.title = wrap_nowiki(title_display)
citeq_args.title = '[[' .. slink .. ']]'
else
wrap_title = wrap_nowiki(slink:gsub("%s%(.+%)$", ""):gsub(",.+$", ""), titleforced)
local slink = mw.wikibase.getSitelink(qid)
local slink_flag = falsetrue
local wrap_title = ''
if citeq_args.title then
if slink then
wrap_title = wrap_nowiki(citeq_args.title)
slink_flag = true
else
citeq_args.title = wrap_nowiki(citeq_args.title)
end
else
if slink then
if slink:lower() == title_display:lower() then
citeq_args.title = '[[' .. slink .. ']]'
else
wrap_title = wrap_nowiki(slink:gsub("%s%(.+%)$", ""):gsub(",.+$", ""))
slink_flag = true
end
else
citeq_args.title = wrap_nowiki(title_display)
end
end
if slink_flag then
if slink == wrap_title then -- direct link
citeq_args.title = '[[' .. slink .. ']]'
else -- piped link
citeq_args.title = '[[' .. slink .. '|' .. wrap_title .. ']]'
end
end
end
else
citeq_args.title = wrap_nowiki(label, titleforced)
end
end
if slink_flag then
if slink == wrap_title then -- direct link
citeq_args.title = '[[' .. slink .. ']]'
else -- piped link
citeq_args.title = '[[' .. slink .. '|' .. wrap_title .. ']]'
end
end
Line 529 ⟶ 523:
 
-- change edition to ordinal if it's set and numeric
citeq_args.edition = citeq_args.edition and p.makeOrdinal(citeq_args.edition)
 
-- code to make a guess what template to use from the supplied parameters
-- (first draft for proof-of-concept)
if citeq_args.isbn then
template = template or "book"
elseif citeq_args.journal then
template = template or "journal"
elseif citeq_args.website then
template = template or "web"
end
 
Line 564 ⟶ 558:
else
citeq_args.id = id;
end
 
-- clean up any blank parameters
for k, v in pairs(citeq_args) do
if v == "" then citeq_args[k] = nil end
end
 
-- if |expand=<anything>, write a nowiki'd version to see what the {{citation}} template call looks like
if is_set(expand) then
local expand_args = { "'{{"' .. template }; -- init with citation template
if expand == "self" then
citeq_args.id = old_id; -- restore original |id= parameter
expand_args = { "'{{cite Q|"' .. qid }; -- expand to itself
end
for p, v in pairs (citeq_args) do -- spin through citeq_args and
table.insert (expand_args, p .. '=' .. v); -- add parameter name = value
end
-- make the nowiki'd string and done
return "table.concat ({'<code>"', ..frame:callParserFunction ('#tag:nowiki', table.concat (expand_args, ' |') .. "'}}'), '</code>"'})
end
 
Line 595 ⟶ 584:
end
 
return citeq
function p.cite_q (frame)
local args = {}
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
return p._cite_q(args)
end
 
return p