Difference between revisions of Module:Citation/CS1/sandbox
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, supress → suppress, atribute → attribute (7) |
||
| Line 252: | Line 252: | ||
--[[--------------------------< 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 475: | Line 475: | ||
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 584: | Line 584: | ||
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 606: | Line 606: | ||
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 684: | Line 683: | ||
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 725: | Line 724: | ||
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 965: | Line 964: | ||
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,097: | Line 1,096: | ||
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 char']); | add_vanc_error (cfg.err_msg_supl['non-Latin char']); | ||
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,109: | Line 1,108: | ||
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,120: | Line 1,119: | ||
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,152: | Line 1,151: | ||
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,424: | Line 1,423: | ||
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,554: | Line 1,553: | ||
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,846: | Line 1,845: | ||
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,856: | Line 1,855: | ||
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 3,024: | Line 3,023: | ||
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 3,042: | Line 3,041: | ||
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,196: | Line 3,195: | ||
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,492: | Line 3,491: | ||
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,672: | Line 3,671: | ||
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,764: | Line 3,763: | ||
{{cite ... |title=Title access-date=2016-03-17}} -- the first parameter has a value and whitespace separates that value from the missing pipe parameter name | {{cite ... |title=Title access-date=2016-03-17}} -- the first parameter has a value and whitespace separates that value from the missing pipe parameter name | ||
{{cite ... |title=access-date=2016-03-17}} -- the first parameter has no value (whitespace after the first = is trimmed by mediawiki) | {{cite ... |title=access-date=2016-03-17}} -- the first parameter has no value (whitespace after the first = is trimmed by mediawiki) | ||
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,773: | Line 3,772: | ||
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 | ||