Module:Citation/CS1: Difference between revisions
Synch from sandbox;
m>Trappist the monk (Synch from sandbox;) |
m>Trappist the monk (Synch from sandbox;) |
||
Line 173: | Line 173: | ||
Split a url into a scheme, authority indicator, and domain. | Split a url into a scheme, authority indicator, and domain. | ||
First remove Fully Qualified Domain Name terminator (a dot following tld) (if any) and any path(/), query(?) or fragment(#). | |||
If protocol relative url, return nil scheme and domain else return nil for both scheme and domain. | If protocol relative url, return nil scheme and domain else return nil for both scheme and domain. | ||
Line 185: | Line 188: | ||
local scheme, authority, domain; | local scheme, authority, domain; | ||
url_str = url_str:gsub ('([%a%d])%.?/.*$', '%1'); | url_str = url_str:gsub ('([%a%d])%.?[/%?#].*$', '%1'); -- strip FQDN terminator and path(/), query(?), fragment (#) (the capture prevents false replacement of '//') | ||
if url_str:match ('^//%S*') then -- if there is what appears to be a protocol relative url | if url_str:match ('^//%S*') then -- if there is what appears to be a protocol relative url | ||
Line 242: | Line 245: | ||
if not link_param_ok (link) then -- check |<param>-link= markup | if not link_param_ok (link) then -- check |<param>-link= markup | ||
orig = lorig; -- identify the failing link parameter | orig = lorig; -- identify the failing link parameter | ||
elseif | elseif title:find ('%[%[') then -- check |title= for wikilink markup | ||
orig = torig; -- identify the failing link parameter | orig = torig; -- identify the failing link parameter | ||
end | end | ||
Line 458: | Line 461: | ||
script_value = script_value:gsub ('^%l%l%s*:%s*', ''); -- strip prefix from script | script_value = script_value:gsub ('^%l%l%s*:%s*', ''); -- strip prefix from script | ||
-- is prefix one of these language codes? | -- is prefix one of these language codes? | ||
if in_array (lang, {'am', 'ar', 'bg', 'bs', 'dv', 'el', 'fa', 'he', 'hy', 'ja', 'ka', 'ko', 'ku', 'mk', 'ml', 'ps', 'ru', 'sd', 'sr', 'th', 'uk', 'ug', 'yi', 'zh'}) then | if in_array (lang, {'am', 'ar', 'be', 'bg', 'bs', 'dv', 'el', 'fa', 'he', 'hy', 'ja', 'ka', 'ko', 'ku', 'mk', 'ml', 'ps', 'ru', 'sd', 'sr', 'th', 'uk', 'ug', 'yi', 'zh'}) then | ||
add_prop_cat ('script_with_name', {name, lang}) | add_prop_cat ('script_with_name', {name, lang}) | ||
else | else | ||
Line 1,080: | Line 1,083: | ||
--[[--------------------------< G E T _ I S O 6 3 9 _ C O D E >------------------------------------------------ | --[[--------------------------< G E T _ I S O 6 3 9 _ C O D E >------------------------------------------------ | ||
Validates language names provided in |language= parameter if not an ISO639-1 code | Validates language names provided in |language= parameter if not an ISO639-1 code. | ||
Returns the language name and associated ISO639-1 code. Because case of the source may be incorrect or different from the case that Wikimedia | Returns the language name and associated ISO639-1 code. Because case of the source may be incorrect or different from the case that Wikimedia | ||
Line 1,096: | Line 1,098: | ||
]] | ]] | ||
local function get_iso639_code (lang) | local function get_iso639_code (lang, this_wiki_code) | ||
local languages = mw.language.fetchLanguageNames(this_wiki_code, 'all') -- get a list of language names known to Wikimedia | |||
local languages = mw.language.fetchLanguageNames( | |||
-- ('all' is required for North Ndebele, South Ndebele, and Ojibwa) | -- ('all' is required for North Ndebele, South Ndebele, and Ojibwa) | ||
local langlc = mw.ustring.lower(lang); -- lower case version for comparisons | local langlc = mw.ustring.lower(lang); -- lower case version for comparisons | ||
Line 1,119: | Line 1,117: | ||
Get language name from ISO639-1 code value provided. If a code is valid use the returned name; if not, then use the value that was provided with the language parameter. | Get language name from ISO639-1 code value provided. If a code is valid use the returned name; if not, then use the value that was provided with the language parameter. | ||
When |language= contains a valid ISO639-1 code, the page is assigned to the category for that code: Category:Norwegian-language sources (no) if | When |language= contains a valid ISO639-1 code, the page is assigned to the category for that code: Category:Norwegian-language sources (no) if | ||
the page is a mainspace page and the ISO639-1 code is not ' | the page is a mainspace page and the ISO639-1 code is not the local wiki's language code. Similarly, if the parameter is |language=Norwegian, | ||
it will be categorized in the same way. | |||
This function supports multiple languages in the form |language=nb, French, th where the language names or codes are separated from each other by commas. | This function supports multiple languages in the form |language=nb, French, th where the language names or codes are separated from each other by commas. | ||
Line 1,141: | Line 1,131: | ||
local language_list = {}; -- table of language names to be rendered | local language_list = {}; -- table of language names to be rendered | ||
local names_table = {}; -- table made from the value assigned to |language= | local names_table = {}; -- table made from the value assigned to |language= | ||
local this_wiki = mw.getContentLanguage(); -- get a language object for this wiki | |||
local this_wiki_code = this_wiki:getCode() -- get this wiki's language code | |||
local this_wiki_name = mw.language.fetchLanguageName(this_wiki_code, this_wiki_code); -- get this wiki's language name | |||
names_table = mw.text.split (lang, '%s*,%s*'); -- names should be a comma separated list | names_table = mw.text.split (lang, '%s*,%s*'); -- names should be a comma separated list | ||
Line 1,150: | Line 1,144: | ||
end | end | ||
if 2 == lang:len() then -- ISO639-1 language code are 2 characters (fetchLanguageName also supports 3 character codes) | if 2 == lang:len() then -- ISO639-1 language code are 2 characters (fetchLanguageName also supports 3 character codes) | ||
name = mw.language.fetchLanguageName( lang:lower(), | name = mw.language.fetchLanguageName( lang:lower(), this_wiki_code); -- get ISO 639-1 language name if Language is a proper code | ||
end | end | ||
Line 1,160: | Line 1,154: | ||
if is_set (code) then | if is_set (code) then | ||
if | if this_wiki_code ~= code then -- when the language is not the same as this wiki's language | ||
add_prop_cat ('foreign_lang_source', {name, code}) -- categorize it | |||
add_prop_cat ('foreign_lang_source', {name, code}) | |||
end | end | ||
else | else | ||
Line 1,179: | Line 1,172: | ||
name = table.concat (language_list, ', ') -- and concatenate with '<comma><space>' separators | name = table.concat (language_list, ', ') -- and concatenate with '<comma><space>' separators | ||
end | end | ||
if | if this_wiki_name == name then | ||
return ''; -- if one language and that language is | return ''; -- if one language and that language is this wiki's return an empty string (no annotation) | ||
end | end | ||
return (" " .. wrap_msg ('language', name)); -- otherwise wrap with '(in ...)' | return (" " .. wrap_msg ('language', name)); -- otherwise wrap with '(in ...)' | ||
Line 1,370: | Line 1,363: | ||
This function sets the vancouver error when a reqired comma is missing and when there is a space between an author's initials. | This function sets the vancouver error when a reqired comma is missing and when there is a space between an author's initials. | ||
TODO: check for names like Coon V JS (Coon JS 5th at PMID 25205766, John S. Coon V at doi:10.1093/humupd/dmu048)? | |||
]] | ]] | ||
Line 2,345: | Line 2,340: | ||
end | end | ||
if | if not is_set(URL) then | ||
if in_array(config.CitationClass, {"web","podcast", "mailinglist"}) then -- | if in_array(config.CitationClass, {"web","podcast", "mailinglist"}) then -- test if cite web or cite podcast |url= is missing or empty | ||
table.insert( z.message_tail, { set_error( 'cite_web_url', {}, true ) } ); | table.insert( z.message_tail, { set_error( 'cite_web_url', {}, true ) } ); | ||
end | end | ||
-- | -- test if accessdate is given without giving a URL | ||
if is_set(AccessDate) and not is_set(ChapterURL)then -- ChapterURL may be set when the others are not set; TODO: move this to a separate test? | if is_set(AccessDate) and not is_set(ChapterURL)then -- ChapterURL may be set when the others are not set; TODO: move this to a separate test? | ||
table.insert( z.message_tail, { set_error( 'accessdate_missing_url', {}, true ) } ); | table.insert( z.message_tail, { set_error( 'accessdate_missing_url', {}, true ) } ); | ||
Line 2,414: | Line 2,409: | ||
Chapter = format_chapter_title (ScriptChapter, Chapter, TransChapter, ChapterURL, ChapterURLorigin, no_quotes); -- Contribution is also in Chapter | Chapter = format_chapter_title (ScriptChapter, Chapter, TransChapter, ChapterURL, ChapterURLorigin, no_quotes); -- Contribution is also in Chapter | ||
if is_set (Chapter) then | if is_set (Chapter) then | ||
Chapter = Chapter .. ChapterFormat ; | |||
if 'map' == config.CitationClass and is_set (TitleType) then | if 'map' == config.CitationClass and is_set (TitleType) then | ||
Chapter = Chapter .. ' ' .. TitleType; | Chapter = Chapter .. ' ' .. TitleType; -- map annotation here; not after title | ||
end | end | ||
Chapter = Chapter | Chapter = Chapter.. sepc .. ' '; | ||
elseif is_set (ChapterFormat) then -- |chapter= not set but |chapter-format= is so ... | elseif is_set (ChapterFormat) then -- |chapter= not set but |chapter-format= is so ... | ||
Chapter = ChapterFormat .. sepc .. ' '; -- ... ChapterFormat has error message, we want to see it | Chapter = ChapterFormat .. sepc .. ' '; -- ... ChapterFormat has error message, we want to see it | ||
Line 2,888: | Line 2,884: | ||
end | end | ||
if is_set(options.id) then | if is_set(options.id) then -- here we wrap the rendered citation in <cite ...>...</cite> tags | ||
text = ' | text = substitute (cfg.presentation['cite-id'], {mw.uri.anchorEncode(options.id), mw.text.nowiki(options.class), text}); -- when |ref= is set | ||
else | else | ||
text = ' | text = substitute (cfg.presentation['cite'], {mw.text.nowiki(options.class), text}); -- all other cases | ||
end | end | ||
text = text .. substitute (cfg.presentation['ocins'], {OCinSoutput}); -- append metadata to the citation | |||
-- | |||
if #z.message_tail ~= 0 then | if #z.message_tail ~= 0 then |