Module:Cite Q/sandbox: Difference between revisions

Content deleted Content added
modify to output links as authorlink
sync with master version
Line 13:
 
 
--[=[-------------------------< G E T _ N A UM TE H_ OL RI S T >--------------------------------------------------------
 
getAuthorsget_name_list -- adapted from getAuthors code taken from [[Module:RexxS]]
arguments:
nl_type - type of name list to fetch: nl_type = 'author' for authors; 'editor' for editors
args - pointer to the parameter arguments table from the template call
qid - value from |qid= parameter; the Q-id of the source (book, etc.) in qid
Line 25 ⟶ 26:
]=]
 
local function get_authorsget_name_list (nl_type, args, qid, wdl)
local propertyID = "P50"
if 'author' == nl_type then
propertyID = 'P50'; -- for authors
elseif 'editor' == nl_type then
propertyID = 'P98'; -- for editors
else
return; -- not specified so return
end
-- wdlinks is a boolean passed to enable links to Wikidata when no article exists
Line 58 ⟶ 67:
-- So now we have something to return:
-- table 'out' is going to to store the author names(s):
-- and table 'link' will store any links to the authorname's article
local out = {}
local link = {}
Line 74 ⟶ 83:
end
if sitelink then
-- just the plain author name,
-- but keep a record of the links, using the same index
out[#out + 1] = label
Line 110 ⟶ 119:
end
-- if there's anything to return, then returninsert athe listadditions in the template arguments table
-- in the form |author1=firstname secondname |author2= ...
if #out > 0 then
for k,v in ipairs(out) do -- authorn or editorn
-- construct the list in the format we want
args[parameter_namenl_type .. k] = v
for k,v in ipairs(out) do
local parameter_name = 'author' .. k
args[parameter_name] = v
end
for k,v in pairs(link) do -- author-linkn or editor-linkn
localargs[nl_type parameter_name =.. 'authorlink-link' .. k] = v
args[parameter_name] = v
end
end
Line 139 ⟶ 145:
local wdl;
 
local argspframe = frame.args; -- get arguments:getParent()
local args = pframe.args; -- first get parent frame arguments - these from the template call
 
for k, v in pairs (args) do -- copy named parameters and their values into citeq_args
if type( k ) == 'string' then -- numbered parameters ignored
citeq_args[k] = v;
end
end
args = frame.args; -- now get frame arguments (from the template wikisource)
 
for k, v in pairs (args) do -- copy args into citeq_args
Line 150 ⟶ 165:
end
end
 
if is_set (qid) then
if not is_set (citeq_args.author) and not is_set (citeq_args.author1) then -- if neither are set, try to get authors from wikidata
get_authorsget_name_list ('author', citeq_args, qid, wdl); -- modify citeq_args table with authors from wikidata
if is_set (qid) then
end
get_authors (citeq_args, qid, wdl); -- modify citeq_args table with authors from wikidata
 
if not is_set (citeq_args.editor) and not is_set (citeq_args.editor1) then -- if neither are set, try to get editors from wikidata
get_name_list ('editor', citeq_args, qid, wdl); -- modify citeq_args table with editors from wikidata
end
end