Modul:Citation/CS1: Perbedaan antara revisi
Konten dihapus Konten ditambahkan
maaf saya revert dulu karena catatan kakinya jadi error semua |
Tidak ada ringkasan suntingan |
||
Baris 123:
]]
local added_maint_cats = {}
local function add_maint_cat (key, arguments)
if not added_maint_cats [key] then
added_maint_cats [key] = true; -- note that we've added this category
table.insert( z.maintenance_cats, substitute (cfg.maint_cats [key], arguments)); -- make name then add to table
end
end
Baris 137:
]]
local added_prop_cats = {}
local function add_prop_cat (key, arguments)
if not added_prop_cats [key] then
added_prop_cats [key] = true; -- note that we've added this category
table.insert( z.properties_cats, substitute (cfg.prop_cats [key], arguments)); -- make name then add to table
end
end
Baris 152:
]]
local added_vanc_errs;
local function add_vanc_error ()
if not added_vanc_errs then
added_vanc_errs = true;
table.insert( z.message_tail, { set_error( 'vancouver', {}, true ) } );
end
Baris 282:
if not page_in_deprecated_cat then
page_in_deprecated_cat = true; -- note that we've added this category
table.insert( z.message_tail, { set_error( 'deprecated_params', {name}, true ) } ); -- add error message
end
end
Baris 302:
local cap2='';
cap, cap2 = str:match ("^([\"\'])([^\'].+)"); -- match leading double or single quote but not double single quotes
if is_set (cap) then
str = substitute (cfg.presentation['kern-left'], {cap, cap2});
Baris 340:
local function format_script_value (script_value)
local lang='';
local name;
if script_value:match('^%l%l%s*:') then
lang = script_value:match('^(%l%l)%s*:%s*%S.*'); -- get the language prefix or nil if there is no script
if not is_set (lang) then
return '';
end
name = mw.language.fetchLanguageName( lang, "en" ); -- get language name so that we can use it to categorize
if is_set (name) then
script_value = script_value:gsub ('^%l%l%s*:%s*', ''); -- strip prefix from script
if in_array (lang, {'ar', 'bg', 'bs', 'dv', 'el', 'fa', 'hy', 'ja', 'ka', 'ko', 'ku', 'he', 'ps', 'ru', 'sd', 'sr', 'th', 'uk', 'ug', 'yi', 'zh'}) then
add_prop_cat ('script_with_name', {name, lang})
Baris 357:
add_prop_cat ('script')
end
lang = ' lang="' .. lang .. '" ';
else
lang = '';
end
end
script_value = substitute (cfg.presentation['bdi'], {lang, script_value}); -- isolate in case script is rtl
return script_value;
Baris 375:
local function script_concatenate (title, script)
if is_set (script) then
script = format_script_value (script);
if is_set (script) then
title = title .. ' ' .. script;
end
end
Baris 398:
if true == lower then
local msg;
msg = cfg.messages[key]:lower();
str = substitute( msg, {str} );
return str;
else
Baris 478:
if not is_set (chapter) then
chapter = '';
if is_set (transchapter) then
chapter = wrap_style ('trans-quoted-title', transchapter);
Baris 484:
end
if is_set (chapterurl) then
chapter = external_link (chapterurl, chapter, chapter_url_source); -- adds bare_url_missing_title error if appropriate
end
return chapter .. chapter_error;
else
chapter = kern_quotes (chapter);
chapter = wrap_style ('quoted-title', chapter);
if is_set (transchapter) then
Baris 565:
if true == state then return true; end -- valid actively supported parameter
if false == state then
deprecated_parameter (name);
return true;
end
-- Arguments with numbers in them
name = name:gsub( "%d+", "#" );
state = whitelist.numbered_arguments[ name ];
if true == state then return true; end -- valid actively supported parameter
if false == state then
deprecated_parameter (name);
return true;
end
return false;
end
Baris 626:
local function is_valid_isxn (isxn_str, len)
local temp = 0;
isxn_str = { isxn_str:byte(1, len) }; -- make a table of byte values '0' → 0x30 .. '9' → 0x39, 'X' → 0x58
len = len+1;
for i, v in ipairs( isxn_str ) do -- loop through all of the bytes and calculate the checksum
if v == string.byte( "X" ) then -- if checkdigit is X (compares the byte value of 'X' which is 0x58)
Baris 635:
end
end
return temp % 11 == 0;
end
Baris 650:
local temp=0;
isxn_str = { isxn_str:byte(1, 13) };
for i, v in ipairs( isxn_str ) do
temp = temp + (3 - 2*(i % 2)) * tonumber( string.char(v) ); -- multiply odd index digits by 1, even index digits by 3 and sum; includes check digit
end
return temp % 10 == 0;
end
Baris 664:
local function check_isbn( isbn_str )
if nil ~= isbn_str:match("[^%s-0-9X]") then return false; end -- fail if isbn_str contains anything but digits, hyphens, or the uppercase X
isbn_str = isbn_str:gsub( "-", "" ):gsub( " ", "" ); -- remove hyphens and spaces
local len = isbn_str:len();
Baris 677:
else
local temp = 0;
if isbn_str:match( "^97[89]%d*$" ) == nil then return false; end -- isbn13 begins with 978 or 979; ismn begins with 979
return is_valid_isxn_13 (isbn_str);
end
Baris 695:
local valid_ismn = true;
id=id:gsub( "[%s-–]", "" );
if 13 ~= id:len() or id:match( "^9790%d*$" ) == nil then -- ismn must be 13 digits and begin 9790
valid_ismn = false;
else
valid_ismn=is_valid_isxn_13 (id);
end
-- text = internal_link_id({link = handler.link, label = handler.label, -- use this (or external version) when there is some place to link to
-- prefix=handler.prefix,id=id,separator=handler.separator, encode=handler.encode})
Baris 709:
if false == valid_ismn then
text = text .. ' ' .. set_error( 'bad_ismn' )
end
Baris 729:
local function issn(id)
local issn_copy = id; -- save a copy of unadulterated issn; use this version for display if issn does not validate
local handler = cfg.id_handlers['ISSN'];
local text;
Baris 736:
id=id:gsub( "[%s-–]", "" ); -- strip spaces, hyphens, and endashes from the issn
if 8 ~= id:len() or nil == id:match( "^%d*X?$" ) then -- validate the issn: 8 digits long, containing only 0-9 or X in the last position
valid_issn=false;
else
valid_issn=is_valid_isxn(id, 8); -- validate issn
end
if true == valid_issn then
id = string.sub( id, 1, 4 ) .. "-" .. string.sub( id, 5 ); -- if valid, display correctly formatted version
else
id = issn_copy;
end
Baris 752:
if false == valid_issn then
text = text .. ' ' .. set_error( 'bad_issn' ) -- add an error message if the issn is invalid
end
Baris 771:
if not id:match("^[%d%u][%d%u][%d%u][%d%u][%d%u][%d%u][%d%u][%d%u][%d%u][%d%u]$") then
err_cat = ' ' .. set_error ('bad_asin');
else
if id:match("^%d%d%d%d%d%d%d%d%d[%dX]$") then
if check_isbn( id ) then
add_maint_cat ('ASIN');
elseif not is_set (err_cat) then
err_cat = ' ' .. set_error ('bad_asin');
end
elseif not id:match("^%u[%d%u]+$") then
err_cat = ' ' .. set_error ('bad_asin');
end
end
if not is_set(domain) then
domain = "com";
elseif in_array (domain, {'jp', 'uk'}) then -- Japan, United Kingdom
domain = "co." .. domain;
elseif in_array (domain, {'au', 'br', 'mx'}) then -- Australia, Brazil, Mexico
domain = "com." .. domain;
end
Baris 835:
year = tonumber(year);
month = tonumber(month);
if ((not (90 < year or 8 > year)) or (1 > month or 12 < month)) or -- if invalid year or invalid month
((91 == year and 7 > month) or (7 == year and 3 < month)) then -- if years ok, are starting and ending months ok?
err_cat = ' ' .. set_error( 'bad_arxiv' ); -- set error message
end
elseif id:match("^%d%d[01]%d%.%d%d%d%d$") or id:match("^%d%d[01]%d%.%d%d%d%dv%d+$") then -- test for the 0704-1412 w/ & w/o version
year, month = id:match("^(%d%d)([01]%d)%.%d%d%d%d[v%d]*$");
year = tonumber(year);
month = tonumber(month);
if ((7 > year) or (14 < year) or (1 > month or 12 < month)) or -- is year invalid or is month invalid? (doesn't test for future years)
((7 == year) and (4 > month)) then --or
err_cat = ' ' .. set_error( 'bad_arxiv' ); -- set error message
end
elseif id:match("^%d%d[01]%d%.%d%d%d%d%d$") or id:match("^%d%d[01]%d%.%d%d%d%d%dv%d+$") then -- test for the 1501- format w/ & w/o version
year, month = id:match("^(%d%d)([01]%d)%.%d%d%d%d%d[v%d]*$");
year = tonumber(year);
month = tonumber(month);
if ((15 > year) or (1 > month or 12 < month)) then -- is year invalid or is month invalid? (doesn't test for future years)
err_cat = ' ' .. set_error( 'bad_arxiv' ); -- set error message
end
Baris 862:
if is_set (class) then
class = ' [[' .. '//arxiv.org/archive/' .. class .. ' ' .. class .. ']]'; -- external link within square brackets, not wikilink
else
class = '';
end
Baris 892:
local prefix
local suffix
prefix, suffix = lccn:match ("(.+)%-(.+)"); -- 3.a remove hyphen by splitting the string into prefix and suffix
if nil ~= suffix then
suffix=string.rep("0", 6-string.len (suffix)) .. suffix; -- 3.b.2 left fill the suffix with 0s if suffix length less than 6
lccn=prefix..suffix;
end
Baris 924:
if 8 == len then
if id:match("[^%d]") then -- if LCCN has anything but digits (nil if only digits)
err_cat = ' ' .. set_error( 'bad_lccn' ); -- set an error message
end
elseif 9 == len then -- LCCN should be adddddddd
if nil == id:match("%l%d%d%d%d%d%d%d%d") then -- does it match our pattern?
err_cat = ' ' .. set_error( 'bad_lccn' ); -- set an error message
end
elseif 10 == len then -- LCCN should be aadddddddd or dddddddddd
if id:match("[^%d]") then
if nil == id:match("^%l%l%d%d%d%d%d%d%d%d") then -- ... see if it matches our pattern
err_cat = ' ' .. set_error( 'bad_lccn' ); -- no match, set an error message
Baris 1.755:
local function get_iso639_code (lang)
if 'norwegian' == lang:lower() then
return 'Norwegian', 'no';
end
local languages = mw.language.fetchLanguageNames('en', 'all') -- get a list of language names known to Wikimedia
local langlc = mw.ustring.lower(lang); -- lower case version for comparisons
for code, name in pairs(languages) do -- scan the list to see if we can find our language
if langlc == mw.ustring.lower(name) then
if 2 ~= code:len() then
return name;
end
return name, code;
end
end
return lang;
end
Baris 1.795:
local function language_parameter (lang)
local code;
local name;
local language_list = {};
local names_table = {};
names_table = mw.text.split (lang, '%s*,%s*'); -- names should be a comma separated list
for _, lang in ipairs (names_table) do -- reuse lang
if 2 == lang:len() then
name = mw.language.fetchLanguageName( lang:lower(), "en" ); -- get ISO 639-1 language name if Language is a proper code
end
if is_set (name) then
code = lang:lower();
else
name, code = get_iso639_code (lang); -- attempt to get code from name (assign name here so that we are sure of proper capitalization)
Baris 1.815:
if is_set (code) then
if 'no' == code then name = 'Norwegian' end; -- override wikimedia when code is 'no'
if 'en' ~= code then
add_prop_cat ('foreign_lang_source', {name, code})
end
else
add_maint_cat ('unknown_lang');
end
table.insert (language_list, name);
name = '';
end
code = #language_list
if 2 >= code then
name = table.concat (language_list, ' and ') -- insert '<space>and<space>' between two language names
elseif 2 < code then
language_list[code] = 'and ' .. language_list[code]; -- prepend last name with 'and<space>'
name = table.concat (language_list, ', ') -- and concatenate with '<comma><space>' separators
end
if 'English' == name then
return '';
end
return (" " .. wrap_msg ('language', name)); -- otherwise wrap with '(in ...)'
end
Baris 1.847:
local function set_cs1_style (ps)
if not is_set (ps) then
ps = '.';
end
return '.', ps;
end
Baris 1.860:
local function set_cs2_style (ps, ref)
if not is_set (ps) then
ps = '';
end
if not is_set (ref) then
ref = "harv";
end
return ',', ps, ref;
end
Baris 1.878:
local function get_settings_from_cite_class (ps, ref, cite_class)
local sep;
if (cite_class == "citation") then
sep, ps, ref = set_cs2_style (ps, ref);
else
sep, ps = set_cs1_style (ps);
end
return sep, ps, ref
end
|