Compare commits
2 commits
6f13edba6e
...
b2ab54ccb4
| Author | SHA1 | Date | |
|---|---|---|---|
| b2ab54ccb4 | |||
| 43bf989f91 |
1 changed files with 30 additions and 14 deletions
|
|
@ -80,7 +80,7 @@ local function accept_value( param_val, wd_val )
|
||||||
return val
|
return val
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Split string of comma-separated first names into table of initials
|
-- Split string of comma-separated first names into a table of initials
|
||||||
local function getInitials(str)
|
local function getInitials(str)
|
||||||
local initials = {}
|
local initials = {}
|
||||||
for _, word in pairs(mw.text.split(str, ' ', true)) do
|
for _, word in pairs(mw.text.split(str, ' ', true)) do
|
||||||
|
|
@ -92,13 +92,14 @@ local function getInitials(str)
|
||||||
return initials
|
return initials
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Return initials given a style (e.g. Vancouver or APA)
|
-- Return initials given a first name string and a name-list-style value
|
||||||
|
-- (e.g. 'vanc' for Vancouver, or APA)
|
||||||
local function getStyledNames(names, style)
|
local function getStyledNames(names, style)
|
||||||
if style == 'Vancouver' then
|
-- Vancouver style (vanc) is handled by CS1: Doe JQ
|
||||||
return table.concat(getInitials(names))
|
if style == 'apa' then -- APA: Doe, J. Q.
|
||||||
elseif style == 'APA' then
|
|
||||||
return table.concat(getInitials(names), '. ') .. '.'
|
return table.concat(getInitials(names), '. ') .. '.'
|
||||||
else
|
else
|
||||||
|
-- Otherwise, just remove any trailing commas from names
|
||||||
return mw.text.trim(names:gsub(', ', ' '))
|
return mw.text.trim(names:gsub(', ', ' '))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -106,6 +107,8 @@ end
|
||||||
-- function to fetch a value to display
|
-- function to fetch a value to display
|
||||||
local function makelink(v, out, link, maxpos, wdl, namestyle)
|
local function makelink(v, out, link, maxpos, wdl, namestyle)
|
||||||
local label
|
local label
|
||||||
|
local max_authors_displayed = 10 -- TODO: this is probably in CS1 config somewhere
|
||||||
|
local item_lookup = false
|
||||||
if v.mainsnak.snaktype == "value" then
|
if v.mainsnak.snaktype == "value" then
|
||||||
if v.mainsnak.datatype == "wikibase-item" then
|
if v.mainsnak.datatype == "wikibase-item" then
|
||||||
local qnumber = v.mainsnak.datavalue.value.id
|
local qnumber = v.mainsnak.datavalue.value.id
|
||||||
|
|
@ -122,12 +125,15 @@ local function makelink(v, out, link, maxpos, wdl, namestyle)
|
||||||
first_names = v.qualifiers.P9687[1].datavalue.value
|
first_names = v.qualifiers.P9687[1].datavalue.value
|
||||||
end
|
end
|
||||||
-- Otherwise, get last name, first name(s) from author item properties
|
-- Otherwise, get last name, first name(s) from author item properties
|
||||||
last_name = last_name or getValue({"P734", qid=qnumber, maxvals=1, ps=2})
|
-- but this requires a getValue WD item lookup for each author, and
|
||||||
first_names = first_names or getValue({"P735", qid=qnumber, maxvals=0, ps=2})
|
-- lookups are limited to 500 per page, so do this after we have the
|
||||||
if first_names then
|
-- "series ordinal" order, then only do the first few since there are
|
||||||
first_names = getStyledNames(first_names, namestyle)
|
-- article items out there with 400+ authors(!)
|
||||||
|
if not last_name or not first_names then
|
||||||
|
item_lookup = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- use object named as for the label
|
||||||
if v.qualifiers and v.qualifiers.P1932 then
|
if v.qualifiers and v.qualifiers.P1932 then
|
||||||
label = v.qualifiers.P1932[1].datavalue.value -- "object named as"
|
label = v.qualifiers.P1932[1].datavalue.value -- "object named as"
|
||||||
else
|
else
|
||||||
|
|
@ -144,6 +150,16 @@ local function makelink(v, out, link, maxpos, wdl, namestyle)
|
||||||
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)
|
||||||
|
|
||||||
|
-- now try determining first/last names with item lookup, if needed
|
||||||
|
if item_lookup and position <= max_authors_displayed then
|
||||||
|
last_name = last_name or getValue({"P734", qid=qnumber, maxvals=1, ps=2})
|
||||||
|
first_names = first_names or getValue({"P735", qid=qnumber, maxvals=0, ps=2})
|
||||||
|
end
|
||||||
|
if first_names then
|
||||||
|
first_names = getStyledNames(first_names, namestyle)
|
||||||
|
end
|
||||||
|
|
||||||
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
|
||||||
|
|
@ -305,7 +321,7 @@ local function get_name_list (nl_type, args, qid, wdl)
|
||||||
if props and props[1] then
|
if props and props[1] then
|
||||||
for k, v in pairs(props) do
|
for k, v in pairs(props) do
|
||||||
if 'deprecated' ~= v.rank then -- ignore deprecated names
|
if 'deprecated' ~= v.rank then -- ignore deprecated names
|
||||||
maxpos = makelink(v, out, link, maxpos, wdl, args.namestyle)
|
maxpos = makelink(v, out, link, maxpos, wdl, args['name-list-style'])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -313,7 +329,7 @@ local function get_name_list (nl_type, args, qid, wdl)
|
||||||
-- second properties
|
-- second properties
|
||||||
for k, v in pairs(fallback) do
|
for k, v in pairs(fallback) do
|
||||||
if 'deprecated' ~= v.rank then -- ignore deprecated names
|
if 'deprecated' ~= v.rank then -- ignore deprecated names
|
||||||
maxpos = makelink(v, out, link, maxpos, wdl, args.namestyle)
|
maxpos = makelink(v, out, link, maxpos, wdl, args['name-list-style'])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -538,7 +554,6 @@ local function _cite_q (citeq_args)
|
||||||
citeq_args.qid = nil
|
citeq_args.qid = nil
|
||||||
citeq_args.wdl = nil
|
citeq_args.wdl = nil
|
||||||
citeq_args.template = nil
|
citeq_args.template = nil
|
||||||
citeq_args.namestyle = citeq_args.namestyle or citeq_args['name-style'] or nil
|
|
||||||
|
|
||||||
-- if title supplied, flag to not read html title
|
-- if title supplied, flag to not read html title
|
||||||
local titleforced = (citeq_args.title ~= nil)
|
local titleforced = (citeq_args.title ~= nil)
|
||||||
|
|
@ -993,8 +1008,9 @@ local function _cite_q (citeq_args)
|
||||||
|
|
||||||
-- remove any remaining non-CS1 fields
|
-- remove any remaining non-CS1 fields
|
||||||
citeq_args['instance-of'] = nil
|
citeq_args['instance-of'] = nil
|
||||||
citeq_args.namestyle = nil
|
if citeq_args['name-list-style'] and citeq_args['name-list-style'] == 'apa' then
|
||||||
citeq_args['name-style'] = nil
|
citeq_args['name-list-style'] = nil
|
||||||
|
end
|
||||||
|
|
||||||
-- render the template
|
-- render the template
|
||||||
local lc_template = template and template:lower() or "citation"
|
local lc_template = template and template:lower() or "citation"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue