Difference between revisions of Module:Citation/CS1
m 1 revision imported |
Viceroy Sam (talk | contribs) m →top: Typo fixing, typos fixed: wikipedia → Wikipedia (2), latin → Latin, et al → et al. (4), , → , (5), etc → etc. (12), dupicate → duplicate, intials → initials (3), maintenence → maintenance, mutliple → multiple, supress → suppress , atribute → attribute (7) |
||
| Line 240: | Line 240: | ||
--[[--------------------------< L I N K _ P A R A M _ O K >--------------------------------------------------- | --[[--------------------------< L I N K _ P A R A M _ O K >--------------------------------------------------- | ||
checks the content of |title-link=, |series-link=, |author-link= etc for properly formatted content: no wikilinks, no urls | checks the content of |title-link=, |series-link=, |author-link= etc. for properly formatted content: no wikilinks, no urls | ||
Link parameters are to hold the title of a | Link parameters are to hold the title of a Wikipedia article so none of the WP:TITLESPECIALCHARACTERS are allowed: | ||
# < > [ ] | { } _ | # < > [ ] | { } _ | ||
except the underscore which is used as a space in wiki urls and # which is used for section links | except the underscore which is used as a space in wiki urls and # which is used for section links | ||
| Line 463: | Line 463: | ||
quote marks regardless of the need for kerning. Unicode quote marks are not replaced in simple [[D]] wikilinks. | quote marks regardless of the need for kerning. Unicode quote marks are not replaced in simple [[D]] wikilinks. | ||
Call this function for chapter titles, for website titles, etc; not for book titles. | Call this function for chapter titles, for website titles, etc.; not for book titles. | ||
]=] | ]=] | ||
| Line 572: | Line 572: | ||
local function script_concatenate (title, script, script_param) | local function script_concatenate (title, script, script_param) | ||
if is_set (script) then | if is_set (script) then | ||
script = format_script_value (script, script_param); -- <bdi> tags, lang | script = format_script_value (script, script_param); -- <bdi> tags, lang attribute, categorization, etc.; returns empty string on error | ||
if is_set (script) then | if is_set (script) then | ||
title = title .. ' ' .. script; -- concatenate title and script title | title = title .. ' ' .. script; -- concatenate title and script title | ||
| Line 594: | Line 594: | ||
end | end | ||
if true == lower then | if true == lower then | ||
msg = cfg.messages[key]:lower(); -- set the message to lower case before | msg = cfg.messages[key]:lower(); -- set the message to lower case before | ||
return substitute( msg, str ); -- including template text | return substitute( msg, str ); -- including template text | ||
| Line 672: | Line 671: | ||
end | end | ||
periodical = script_concatenate (periodical, script_periodical, script_periodical_source); -- <bdi> tags, lang | periodical = script_concatenate (periodical, script_periodical, script_periodical_source); -- <bdi> tags, lang attribute, categorization, etc.; must be done after title is wrapped | ||
if is_set (trans_periodical) then | if is_set (trans_periodical) then | ||
| Line 713: | Line 712: | ||
end | end | ||
chapter = script_concatenate (chapter, scriptchapter, script_chapter_source); -- <bdi> tags, lang | chapter = script_concatenate (chapter, scriptchapter, script_chapter_source); -- <bdi> tags, lang attribute, categorization, etc.; must be done after title is wrapped | ||
if is_set (chapterurl) then | if is_set (chapterurl) then | ||
| Line 954: | Line 953: | ||
local function safe_join( tbl, duplicate_char ) | local function safe_join( tbl, duplicate_char ) | ||
local f = {}; -- create a function table appropriate to type of ' | local f = {}; -- create a function table appropriate to type of 'duplicate character' | ||
if 1 == #duplicate_char then -- for single byte ascii characters use the string library functions | if 1 == #duplicate_char then -- for single byte ascii characters use the string library functions | ||
f.gsub=string.gsub | f.gsub=string.gsub | ||
| Line 1,086: | Line 1,085: | ||
nil == mw.ustring.find (first, "^[A-Za-z\195\128-\195\150\195\152-\195\182\195\184-\198\191\199\132-\201\143%-%s%'%.]*$") then | nil == mw.ustring.find (first, "^[A-Za-z\195\128-\195\150\195\152-\195\182\195\184-\198\191\199\132-\201\143%-%s%'%.]*$") then | ||
add_vanc_error (cfg.err_msg_supl['non-Latin character']); | add_vanc_error (cfg.err_msg_supl['non-Latin character']); | ||
return false; -- not a string of | return false; -- not a string of Latin characters; Vancouver requires Romanization | ||
end; | end; | ||
return true; | return true; | ||
| Line 1,098: | Line 1,097: | ||
Names in |firstn= may be separated by spaces or hyphens, or for initials, a period. See http://www.ncbi.nlm.nih.gov/books/NBK7271/box/A35062/. | Names in |firstn= may be separated by spaces or hyphens, or for initials, a period. See http://www.ncbi.nlm.nih.gov/books/NBK7271/box/A35062/. | ||
Vancouver style requires family rank designations (Jr, II, III, etc) to be rendered as Jr, 2nd, 3rd, etc. See http://www.ncbi.nlm.nih.gov/books/NBK7271/box/A35085/. | Vancouver style requires family rank designations (Jr, II, III, etc.) to be rendered as Jr, 2nd, 3rd, etc. See http://www.ncbi.nlm.nih.gov/books/NBK7271/box/A35085/. | ||
This code only accepts and understands generational suffix in the Vancouver format because Roman numerals look like, and can be mistaken for, initials. | This code only accepts and understands generational suffix in the Vancouver format because Roman numerals look like, and can be mistaken for, initials. | ||
| Line 1,109: | Line 1,108: | ||
if not name then -- if not initials and a suffix | if not name then -- if not initials and a suffix | ||
name = mw.ustring.match(first, "^(%u+)$"); -- is it just | name = mw.ustring.match(first, "^(%u+)$"); -- is it just initials? | ||
end | end | ||
| Line 1,141: | Line 1,140: | ||
end | end | ||
if 3 > i then | if 3 > i then | ||
table.insert (initials, mw.ustring.sub(names[i],1,1)); -- insert the | table.insert (initials, mw.ustring.sub(names[i],1,1)); -- insert the initial at end of initials table | ||
end | end | ||
i = i+1; -- bump the counter | i = i+1; -- bump the counter | ||
| Line 1,270: | Line 1,269: | ||
for _, pattern in ipairs (patterns) do -- loop through all of the patterns | for _, pattern in ipairs (patterns) do -- loop through all of the patterns | ||
if name:match (pattern) then -- if this 'et al' pattern is found in name | if name:match (pattern) then -- if this 'et al.' pattern is found in name | ||
name = name:gsub (pattern, ''); -- remove the offending text | name = name:gsub (pattern, ''); -- remove the offending text | ||
etal = true; -- set flag (may have been set previously here or by |display-<names>=etal) | etal = true; -- set flag (may have been set previously here or by |display-<names>=etal) | ||
| Line 1,413: | Line 1,412: | ||
last, etal = name_has_etal (last, etal, false, last_alias); -- find and remove variations on et al. | last, etal = name_has_etal (last, etal, false, last_alias); -- find and remove variations on et al. | ||
first, etal = name_has_etal (first, etal, false, first_alias); -- find and remove variations on et al. | first, etal = name_has_etal (first, etal, false, first_alias); -- find and remove variations on et al. | ||
last, first= name_checks (last, first, list_name); -- multiple names, extraneous annotation, etc checks | last, first= name_checks (last, first, list_name); -- multiple names, extraneous annotation, etc. checks | ||
if first and not last then -- if there is a firstn without a matching lastn | if first and not last then -- if there is a firstn without a matching lastn | ||
| Line 1,543: | Line 1,542: | ||
if is_set (code) then -- only 2- or 3-character codes | if is_set (code) then -- only 2- or 3-character codes | ||
name = cfg.lang_code_remap[code] or name; -- override | name = cfg.lang_code_remap[code] or name; -- override Wikimedia when they misuse language codes/names | ||
if cfg.this_wiki_code ~= code then -- when the language is not the same as this wiki's language | if cfg.this_wiki_code ~= code then -- when the language is not the same as this wiki's language | ||
| Line 1,549: | Line 1,548: | ||
add_prop_cat ('foreign_lang_source' .. code, {name, code}); -- categorize it; code appended to allow for multiple language categorization | add_prop_cat ('foreign_lang_source' .. code, {name, code}); -- categorize it; code appended to allow for multiple language categorization | ||
else -- or is a recognized language (but has a three-character code) | else -- or is a recognized language (but has a three-character code) | ||
add_prop_cat ('foreign_lang_source_2' .. code, {code}); -- categorize it differently TODO: support | add_prop_cat ('foreign_lang_source_2' .. code, {code}); -- categorize it differently TODO: support multiple three-character code categories per cs1|2 template | ||
end | end | ||
elseif cfg.local_lang_cat_enable then -- when the language and this wiki's language are the same and categorization is enabled | elseif cfg.local_lang_cat_enable then -- when the language and this wiki's language are the same and categorization is enabled | ||
| Line 1,835: | Line 1,834: | ||
for i, v_name in ipairs(v_name_table) do | for i, v_name in ipairs(v_name_table) do | ||
if v_name:match ('^%(%(.+%)%)$') then -- corporate authors are wrapped in doubled parentheses to | if v_name:match ('^%(%(.+%)%)$') then -- corporate authors are wrapped in doubled parentheses to suppress vanc formatting and error detection | ||
first = ''; -- set to empty string for concatenation and because it may have been set for previous author/editor | first = ''; -- set to empty string for concatenation and because it may have been set for previous author/editor | ||
last = v_name:match ('^%(%((.+)%)%)$') -- remove doubled parntheses | last = v_name:match ('^%(%((.+)%)%)$') -- remove doubled parntheses | ||
| Line 1,845: | Line 1,844: | ||
local lastfirstTable = {} | local lastfirstTable = {} | ||
lastfirstTable = mw.text.split(v_name, "%s") | lastfirstTable = mw.text.split(v_name, "%s") | ||
first = table.remove(lastfirstTable); -- removes and returns value of last element in table which should be author | first = table.remove(lastfirstTable); -- removes and returns value of last element in table which should be author initials | ||
if is_suffix (first) then -- if a valid suffix | if is_suffix (first) then -- if a valid suffix | ||
suffix = first -- save it as a suffix and | suffix = first -- save it as a suffix and | ||
| Line 2,967: | Line 2,966: | ||
do -- do editor name list first because the now unsupported coauthors used to modify control table | do -- do editor name list first because the now unsupported coauthors used to modify control table | ||
control.maximum , editor_etal = get_display_names (A['DisplayEditors'], #e, 'editors', editor_etal); | control.maximum, editor_etal = get_display_names (A['DisplayEditors'], #e, 'editors', editor_etal); | ||
last_first_list, EditorCount = list_people(control, e, editor_etal); | last_first_list, EditorCount = list_people(control, e, editor_etal); | ||
| Line 2,973: | Line 2,972: | ||
Editors, editor_etal = name_has_etal (Editors, editor_etal, false, 'editors'); -- find and remove variations on et al. | Editors, editor_etal = name_has_etal (Editors, editor_etal, false, 'editors'); -- find and remove variations on et al. | ||
if editor_etal then | if editor_etal then | ||
Editors = Editors .. ' ' .. cfg.messages['et al']; -- add et al. to editors parameter beause |display-editors=etal | Editors = Editors .. ' ' .. cfg.messages['et al.']; -- add et al. to editors parameter beause |display-editors=etal | ||
end | end | ||
EditorCount = 2; -- we don't know but assume |editors= is multiple names; spoof to display (eds.) annotation | EditorCount = 2; -- we don't know but assume |editors= is multiple names; spoof to display (eds.) annotation | ||
| Line 2,985: | Line 2,984: | ||
end | end | ||
do -- now do interviewers | do -- now do interviewers | ||
control.maximum , interviewer_etal = get_display_names (A['DisplayInterviewers'], #interviewers_list, 'interviewers', interviewer_etal); | control.maximum, interviewer_etal = get_display_names (A['DisplayInterviewers'], #interviewers_list, 'interviewers', interviewer_etal); | ||
Interviewers = list_people (control, interviewers_list, interviewer_etal); | Interviewers = list_people (control, interviewers_list, interviewer_etal); | ||
end | end | ||
do -- now do translators | do -- now do translators | ||
control.maximum , translator_etal = get_display_names (A['DisplayTranslators'], #t, 'translators', translator_etal); | control.maximum, translator_etal = get_display_names (A['DisplayTranslators'], #t, 'translators', translator_etal); | ||
Translators = list_people (control, t, translator_etal); | Translators = list_people (control, t, translator_etal); | ||
end | end | ||
do -- now do contributors | do -- now do contributors | ||
control.maximum , contributor_etal = get_display_names (A['DisplayContributors'], #c, 'contributors', contributor_etal); | control.maximum, contributor_etal = get_display_names (A['DisplayContributors'], #c, 'contributors', contributor_etal); | ||
Contributors = list_people (control, c, contributor_etal); | Contributors = list_people (control, c, contributor_etal); | ||
end | end | ||
do -- now do authors | do -- now do authors | ||
control.maximum , author_etal = get_display_names (A['DisplayAuthors'], #a, 'authors', author_etal); | control.maximum, author_etal = get_display_names (A['DisplayAuthors'], #a, 'authors', author_etal); | ||
last_first_list = list_people(control, a, author_etal); | last_first_list = list_people(control, a, author_etal); | ||
| Line 3,004: | Line 3,003: | ||
Authors, author_etal = name_has_etal (Authors, author_etal, false, 'authors'); -- find and remove variations on et al. | Authors, author_etal = name_has_etal (Authors, author_etal, false, 'authors'); -- find and remove variations on et al. | ||
if author_etal then | if author_etal then | ||
Authors = Authors .. ' ' .. cfg.messages['et al']; -- add et al. to authors parameter | Authors = Authors .. ' ' .. cfg.messages['et al.']; -- add et al. to authors parameter | ||
end | end | ||
else | else | ||
| Line 3,139: | Line 3,138: | ||
Title = kern_quotes (Title); -- if necessary, separate title's leading and trailing quote marks from Module provided quote marks | Title = kern_quotes (Title); -- if necessary, separate title's leading and trailing quote marks from Module provided quote marks | ||
Title = wrap_style ('quoted-title', Title); | Title = wrap_style ('quoted-title', Title); | ||
Title = script_concatenate (Title, ScriptTitle, 'script-title'); -- <bdi> tags, lang | Title = script_concatenate (Title, ScriptTitle, 'script-title'); -- <bdi> tags, lang attribute, categorization, etc.; must be done after title is wrapped | ||
TransTitle= wrap_style ('trans-quoted-title', TransTitle ); | TransTitle= wrap_style ('trans-quoted-title', TransTitle ); | ||
elseif 'report' == config.CitationClass then -- no styling for cite report | elseif 'report' == config.CitationClass then -- no styling for cite report | ||
Title = script_concatenate (Title, ScriptTitle, 'script-title'); -- <bdi> tags, lang | Title = script_concatenate (Title, ScriptTitle, 'script-title'); -- <bdi> tags, lang attribute, categorization, etc.; must be done after title is wrapped | ||
TransTitle= wrap_style ('trans-quoted-title', TransTitle ); -- for cite report, use this form for trans-title | TransTitle= wrap_style ('trans-quoted-title', TransTitle ); -- for cite report, use this form for trans-title | ||
else | else | ||
Title = wrap_style ('italic-title', Title); | Title = wrap_style ('italic-title', Title); | ||
Title = script_concatenate (Title, ScriptTitle, 'script-title'); -- <bdi> tags, lang | Title = script_concatenate (Title, ScriptTitle, 'script-title'); -- <bdi> tags, lang attribute, categorization, etc.; must be done after title is wrapped | ||
TransTitle = wrap_style ('trans-italic-title', TransTitle); | TransTitle = wrap_style ('trans-italic-title', TransTitle); | ||
end | end | ||
| Line 3,435: | Line 3,434: | ||
tcommon = safe_join( {Others, Title, TitleNote, Conference, Periodical, Format, TitleType, Series, Language, Edition, Publisher, Agency, Volume}, sepc ); | tcommon = safe_join( {Others, Title, TitleNote, Conference, Periodical, Format, TitleType, Series, Language, Edition, Publisher, Agency, Volume}, sepc ); | ||
elseif in_array(config.CitationClass, {"book","citation"}) and not is_set(Periodical) then -- special cases for book cites | elseif in_array(config.CitationClass, {"book","citation"}) and not is_set(Periodical) then -- special cases for book cites | ||
if is_set (Contributors) then -- when we are citing foreword, preface, introduction, etc | if is_set (Contributors) then -- when we are citing foreword, preface, introduction, etc. | ||
tcommon = safe_join( {Title, TitleNote}, sepc ); -- author and other stuff will come after this and before tcommon2 | tcommon = safe_join( {Title, TitleNote}, sepc ); -- author and other stuff will come after this and before tcommon2 | ||
tcommon2 = safe_join( {Conference, Periodical, Format, TitleType, Series, Language, Volume, Others, Edition, Publisher, Agency}, sepc ); | tcommon2 = safe_join( {Conference, Periodical, Format, TitleType, Series, Language, Volume, Others, Edition, Publisher, Agency}, sepc ); | ||
| Line 3,614: | Line 3,613: | ||
local maint_msgs = {}; -- here we collect all of the maint messages | local maint_msgs = {}; -- here we collect all of the maint messages | ||
for _, v in ipairs( z.maintenance_cats ) do -- append maintenance categories | for _, v in ipairs( z.maintenance_cats ) do -- append maintenance categories | ||
local maint = {}; -- here we assemble a | local maint = {}; -- here we assemble a maintenance message | ||
table.insert (maint, v); -- maint msg is the category name | table.insert (maint, v); -- maint msg is the category name | ||
table.insert (maint, ' ('); -- open the link text | table.insert (maint, ' ('); -- open the link text | ||
| Line 3,706: | Line 3,705: | ||
{{cite ... |title=Title access-date=2016-03-17}} | {{cite ... |title=Title access-date=2016-03-17}} | ||
cs1|2 shares some parameter names with xml/html | cs1|2 shares some parameter names with xml/html attributes: class=, title=, etc. To prevent false positives xml/html | ||
tags are removed before the search. | tags are removed before the search. | ||
| Line 3,715: | Line 3,714: | ||
local function missing_pipe_check (parameter, value) | local function missing_pipe_check (parameter, value) | ||
local capture; | local capture; | ||
value = value:gsub ('%b<>', ''); -- remove xml/html tags because attributes: class=, title=, etc | value = value:gsub ('%b<>', ''); -- remove xml/html tags because attributes: class=, title=, etc. | ||
capture = value:match ('%s+(%a[%w%-]+)%s*=') or value:match ('^(%a[%w%-]+)%s*='); -- find and categorize parameters with possible missing pipes | capture = value:match ('%s+(%a[%w%-]+)%s*=') or value:match ('^(%a[%w%-]+)%s*='); -- find and categorize parameters with possible missing pipes | ||