మాడ్యూల్:Citation/CS1: కూర్పుల మధ్య తేడాలు

Content deleted Content added
చి en:Module:Citation/CS1 నుండి కూర్పులను దిగుమతి చేసాం: వ్యాసాలకు అవసరమైనందున
sync from sandbox;
పంక్తి 529:
lang = script_value:match('^(%l%l%l?)%s*:%s*%S.*'); -- get the language prefix or nil if there is no script
if not utilities.is_set (lang) then
utilities.set_message ('err_script_parameter', {script_param, cfg.err_msg_supl['missing title part']}); -- prefix without 'title'; add error message
return ''; -- script_value was just the prefix so return empty string
end
పంక్తి 540:
utilities.add_prop_cat ('script', {name, lang})
else
utilities.set_message ('err_script_parameter', {script_param, cfg.err_msg_supl['unknown language code']}); -- unknown script-language; add error message
end
lang = ' lang="' .. lang .. '" '; -- convert prefix into a lang attribute
else
utilities.set_message ('err_script_parameter', {script_param, cfg.err_msg_supl['invalid language code']}); -- invalid language code; add error message
lang = ''; -- invalid so set lang to empty string
end
else
utilities.set_message ('err_script_parameter', {script_param, cfg.err_msg_supl['missing prefix']}); -- no language code prefix; add error message
end
script_value = utilities.substitute (cfg.presentation['bdi'], {lang, script_value}); -- isolate in case script is RTL
పంక్తి 1,343:
 
 
--[=[--------------------------< I S _ G E N E R I C >----------------------------------------------------------
 
Compares values assigned to various parameterparameters according to the string provided as <item> in the function call:.
<item> can have on of two values:
'generic_names': |last=, |first=, |editor-last=, etc value against list of known generic name patterns
'generic_names' – for name-holding parameters: |last=, |first=, |editor-last=, etc
'generic_titles': – for |title=
Returns true when pattern matches; nil else
 
There are two types of generic tests. The 'accept' tests look for a pattern that should not be rejected by the
The k/v pairs in cfg.special_case_translation[item] each contain two tables, one for English and one for another
'reject' test. For example,
'local' language.Each of those tables contain another table that holds the string or pattern (whole or fragment)
|author=[[John Smith (author)|Smith, John]]
in index [1]. index [2] is a Boolean that tells string.find() or mw.ustring.find() to do plain-text search (true)
would be rejected by the 'author' reject test. But piped wikilinks with 'author' disambiguation should not be
rejected so the 'accept' test prevents that from happening. Accept tests are always performed before reject
tests.
 
Each of the 'accept' and 'reject' sequence tables hold tables for en.wiki (['en']) and local.wiki (['local'])
that each can hold a test sequence table The sequence table holds, at index [1], a test pattern, and, at index
in index [12]., indexa [2]boolean iscontrol avalue. The Booleancontrol thatvalue tells string.find() or mw.ustring.find() to do plain-text search (true)
or a pattern search (false). The intent of all this complexity is to make these searches as fast as possible so
that we don't run out of processing time on very large articles.
 
Returns
]]
true when a reject test finds the pattern or string
false when an accept test finds the pattern or string
nil else
 
]=]
local function is_generic (item, value)
 
local function is_generic (item, value, wiki)
local test_val;
local str_lower = { -- use string.lower() for en.wiki (['en']) and use mw.ustring.lower() or local.wiki (['local'])
['en'] = string.lower,
['local'] = mw.ustring.lower,
}
local str_find = { -- use string.find() for en.wiki (['en']) and use mw.ustring.find() or local.wiki (['local'])
['en'] = string.find,
['local'] = mw.ustring.find,
}
 
local function test (val, test_t, wiki) -- local function to do the testing; <wiki> selects lower() and find() functions
for _, generic_value in ipairs (cfg.special_case_translation[item]) do -- spin through the list of known generic value fragments
test_valval = generic_value['en']test_t[2] and value:lowerstr_lower[wiki](value) or valueval; -- when <test_t[2]> set to 'true', plaintext search using lowercase value
return str_find[wiki] (val, test_t[1], 1, test_t[2]); -- return nil when not found or matched
end
local test_types_t = {'accept', 'reject'}; -- test accept patterns first, then reject patterns
local wikis_t = {'en', 'local'}; -- do tests for each of these keys; en.wiki first, local.wiki second
 
for _, test_type in ipairs (test_types_t) do -- for each test type
if test_val:find (generic_value['en'][1], 1, generic_value['en'][2]) then
for _, generic_value in ipairspairs (cfg.special_case_translation[item][test_type]) do -- spin through the list of known generic value fragments to accept or reject
return true; -- found English generic value so done
for _, wiki in ipairs (wikis_t) do
 
if generic_value[wiki] then
elseif generic_value['local'] then -- to keep work load down, generic_<value>['local'] should be nil except when there is a local version of the generic value
if test (value, generic_value[wiki], wiki) then -- go do the test
test_val = generic_value['local'][2] and mw.ustring.lower(value) or value; -- when set to 'true', plaintext search using lowercase value
return ('reject' == test_type); -- param value rejected, return true; false else
 
end
if mw.ustring.find (test_val, generic_value['local'][1], 1, generic_value['local'][2]) then -- mw.ustring() because might not be Latin script
end
return true; -- found local generic value so done
end
end
Line 1,521 ⟶ 1,546:
and look for the new <lang_param> in cfg.mw_languages_by_tag_t{}
 
on success, returnreturns name (in properly capitalized form) and matching tag (in lowercase); on failure returnreturns nil
 
]]
Line 1,532 ⟶ 1,557:
name = cfg.lang_code_remap[lang_param_lc]; -- assume <lang_param_lc> is a tag; attempt to get remapped language name
if name then -- when <name>, <lang_param> is a tag for a remapped language name
return name, lang_paramlang_param_lc; -- so return <name> from remap and <lang_paramlang_param_lc>
end
 
Line 1,554 ⟶ 1,579:
if name then
return name, lang_paramlang_param_lc; -- <lang_param_lc> is a tag so return it and <name> and the tag
end
Line 1,601 ⟶ 1,626:
 
for _, lang in ipairs (names_t) do -- reuse lang here because we don't yet know if lang is a language name or a language tag
name, tag = name_tag_get (lang); -- attempt to get name/tag pair for <lang>; <name> has proper capitalization; <tag> is lowercase
 
if utilities.is_set (tag) then
lang_subtag = tag:lower():gsub ('^(%a%a%a?)%-.*', '%1'); -- for categorization, strip any IETF-like tags from language tag
 
if cfg.this_wiki_code ~= lang_subtag then -- when the language is not the same as this wiki's language
if 2 == lang_subtag:len() then -- and is a two-character tag
-- utilities.add_prop_cat ('foreign-lang-source', {name, lang_subtag}, lang_subtag); -- categorize it; tag appended to allow for multiple language categorization
utilities.add_prop_cat ('foreign-lang-source', {name, tag}, lang_subtag); -- categorize it; tag appended to allow for multiple language categorization
else -- or is a recognized language (but has a three-character tag)
utilities.add_prop_cat ('foreign-lang-source-2', {lang_subtag}, lang_subtag); -- categorize it differently TODO: support multiple three-character tag categories per cs1|2 template?
Line 2,501 ⟶ 2,527:
if 'citation' == config.CitationClass then
if utilities.is_set (Periodical) then
if not utilities.in_array (Periodical_origin, {'website', 'mailinglist'}cfg.citation_no_volume_t) then -- {{citation}} does not render |volume= forwhen these 'periodicals' --TODO: move 'array'parameters toare ~/Configurationused
Volume = A['Volume']; -- but does for all other 'periodicals'
end
Line 2,518 ⟶ 2,544:
local Issue;
if 'citation' == config.CitationClass then
if utilities.is_set (Periodical) and utilities.in_array (Periodical_origin, {'journal', 'magazine', 'newspaper', 'periodical', 'work'}cfg.citation_issue_t) orthen -- {{citation}} rendersmay render |issue= forwhen these 'periodicals'--TODO: move 'array'parameters toare ~/Configurationused
Issue = utilities.hyphen_to_dash (A['Issue']);
utilities.is_set (ScriptPeriodical) and utilities.in_array (ScriptPeriodical_origin, {'script-journal', 'script-magazine', 'script-newspaper', 'script-periodical', 'script-work'}) then -- and these 'script-periodicals'
Issue = utilities.hyphen_to_dash (A['Issue']);
end
elseif utilities.in_array (config.CitationClass, cfg.templates_using_issue) then -- conference & map books do not support issue; {{citation}} listed here because included in settings table
Line 2,806 ⟶ 2,831:
ChapterUrlAccess = UrlAccess;
ChapterURL_origin = URL_origin;
ChapterFormat = Format;
 
Title = Series; -- promote series to title
TitleLink = SeriesLink;
Line 2,819 ⟶ 2,845:
TransTitle = '';
ScriptTitle = '';
Format = '';
else -- now oddities that are cite serial
Line 2,991 ⟶ 3,018:
end
 
if utilities.is_set (URL) andthen -- set when using an identifier-created URL
if utilities.is_set (AccessDate) then -- |access -date= requires |url=; identifier-created URL is not |url=
utilities.set_message ('err_accessdate_missing_url'); -- add an error message
AccessDate = ''; -- unset
end
 
if utilities.is_set (ArchiveURL) then -- |archive-url= requires |url=; identifier-created URL is not |url=
utilities.set_message ('err_archive_missing_url'); -- add an error message
ArchiveURL = ''; -- unset
end
end
end
Line 3,822 ⟶ 3,856:
 
local template_name = ('citation' == config.CitationClass) and 'citation' or 'cite ' .. (cfg.citation_class_map_t[config.CitationClass] or config.CitationClass);
local template_link = '[[Template:' .. template_name .. '|' .. template_name .. ']]'; -- TODO: if kept, these require some sort of i18n
local msg_prefix = '<code class="cs1-code">{{' .. template_link .. '}}</code>: ';
 
Line 4,042 ⟶ 4,076:
local function citation(frame)
Frame = frame; -- save a copy in case we need to display an error message in preview mode
local sandbox = '/sandbox' -- i18n: replace this rvalue with the name that your wiki uses to identify sandbox subpages
is_sandbox = nil ~= string.find (frame:getTitle(), 'sandbox', 1, true); -- is this invoke the sandbox module?
sandbox = is_sandbox and sandbox or ''; -- use i18n sandbox to load sandbox modules when this module is the sandox; live modules else
 
local pframe = frame:getParent()
local styles;
cfg = mw.loadData ('Module:Citation/CS1/Configuration' .. sandbox); -- load livesandbox versions of support modules when {{#invoke:Citation/CS1/sandbox|...}}; live modules else
if is_sandbox then -- did the {{#invoke:}} use sandbox version?
cfg whitelist = mw.loadData ('Module:Citation/CS1/Configuration/sandboxWhitelist'); -- load.. sandbox versions of support modules);
whitelist utilities = mw.loadDatarequire ('Module:Citation/CS1/Whitelist/sandboxUtilities' .. sandbox);
utilities validation = require ('Module:Citation/CS1/Utilities/sandboxDate_validation' .. sandbox);
validation identifiers = require ('Module:Citation/CS1/Date_validation/sandboxIdentifiers' .. sandbox);
identifiers metadata = require ('Module:Citation/CS1/Identifiers/sandboxCOinS' .. sandbox);
metadata styles = require ('Module:Citation/CS1/COinS/' .. sandbox .. '/styles.css');
styles = 'Module:Citation/CS1/sandbox/styles.css';
else -- otherwise
cfg = mw.loadData ('Module:Citation/CS1/Configuration'); -- load live versions of support modules
whitelist = mw.loadData ('Module:Citation/CS1/Whitelist');
utilities = require ('Module:Citation/CS1/Utilities');
validation = require ('Module:Citation/CS1/Date_validation');
identifiers = require ('Module:Citation/CS1/Identifiers');
metadata = require ('Module:Citation/CS1/COinS');
styles = 'Module:Citation/CS1/styles.css';
end
 
utilities.set_selected_modules (cfg); -- so that functions in Utilities can see the selected cfg tables
"https://te.wikipedia.org/wiki/మాడ్యూల్:Citation/CS1" నుండి వెలికితీశారు