Module:Citation/CS1: திருத்தங்களுக்கு இடையிலான வேறுபாடு
உள்ளடக்கம் நீக்கப்பட்டது உள்ளடக்கம் சேர்க்கப்பட்டது
Fix for broken |ref=harv; |
Synch from sandbox; |
||
வரிசை 53:
-- Populates numbered arguments in a message string using an argument table.
function substitute( msg, args )
return args and mw.message.newRawMessage( msg, args ):plain() or msg;
end
--[[
Apply kerning to open the space between the quote mark provided by the Module and a leading or trailing quote mark contained in a |title= or |chapter= parameter's value.
This function will positive kern either single or double quotes:
"'Unkerned title with leading and trailing single quote marks'"
" 'Kerned title with leading and trailing single quote marks' " (in real life the kerning isn't as wide as this example)
]]
function kern_quotes (str)
local left='<span style="padding-left:0.2em;">%1</span>'; -- spacing to use when title contains leading single or double quote mark
local right='<span style="padding-right:0.2em;">%1</span>'; -- spacing to use when title contains trailing single or double quote mark
str = string.gsub( str, "^([\"\'])", left, 1 ); -- replace (captured) leading single or double quote with left-side <span>
str = string.gsub( str, "([\"\'])$", right, 1 ); -- replace (captured) trailing single or double quote with right-side <span>
return str;
end
வரி 120 ⟶ 136:
Looks for a parameter's name in the whitelist.
Parameters in the whitelist can have three
true - active, supported parameters
false - deprecated, supported parameters
வரி 240 ⟶ 256:
label=handler.label , prefix="//www.amazon."..domain.."/dp/",id=id,
encode=handler.encode, separator = handler.separator})
end
--[[
Format PMID and do simple error checking. PMIDs are sequential numbers beginning at 1 and counting up. This code checks the PMID to see that it
contains only digits and is less than test_limit; the value in local variable test_limit will need to be updated periodically as more PMIDs are issued.
]]
function pmid(id)
local test_limit = 30000000; -- update this value as PMIDs approach
local handler = cfg.id_handlers['PMID'];
local err_cat = ''; -- presume that PMID is valid
if id:match("[^%d]") then -- if PMID has anything but digits
err_cat = ' ' .. seterror( 'bad_pmid' ); -- set an error message
else -- PMID is only digits
local id_num = tonumber(id); -- convert id to a number for range testing
if 1 > id_num or test_limit < id_num then -- if PMID is outside test limit boundaries
err_cat = ' ' .. seterror( 'bad_pmid' ); -- set an error message
end
end
return externallinkid({link = handler.link, label = handler.label,
prefix=handler.prefix,id=id,separator=handler.separator, encode=handler.encode}) .. err_cat;
end
வரி 299 ⟶ 337:
inactive = ""
end
if nil == id:match("^10%.[^%s–]-[^%p]$") then -- doi must begin with '10.', must not contain spaces or endashes, and must not end with punctuation
cat = seterror( 'bad_doi' );
end
return text .. inactive .. ' ' .. cat
end
வரி 381 ⟶ 420:
end
if "
return "Podcast"; -- display podcast annotation
elseif "pressrelease" == cite_class then -- if this citation is cite press release
return "Press release"; -- display press release annotation
elseif "techreport" == cite_class then -- if this citation is cite techreport
return "Technical report"; -- display techreport annotation
வரி 395 ⟶ 434:
end
-- returns a number according to the month in a date: 1 for January, etc. Capitalization and spelling must be correct. If not a valid month, returns 0
function get_month_number (month)
local long_months = {['
local short_months = {['
local temp;
temp=long_months[month
if temp then return temp; end -- if month is the long-form name
temp=short_months[month
if temp then return temp; end -- if month is the short-form name
return 0; -- misspelled, improper case, or not a month name
end
-- returns a number according to the sequence of seasons in a year: 1 for Winter, etc. Capitalization and spelling must be correct. If not a valid season, returns 0
function
local temp;
temp=season_list[season];
if temp then return temp; end -- if season is a valid name return its number
return 0; -- misspelled, improper case, or not a season name
end
வரி 445 ⟶ 485:
end
--[[
Month pairs are expected to be left to right, earliest to latest in time. Similarly, seasons are also left to right, earliest to latest in time. There is
an oddity with seasons. Winter is assigned a value of 1, spring 2, ..., fall and autumn 4. Because winter can follow fall/autumn at the end of a calender year, a special test
is made to see if |date=Fall-Winter yyyy (4-1) is the date.
]]
function is_valid_month_season_range(range_start, range_end)
if 0 == range_start_number then -- is this a month range?
local range_start_number = get_season_number (range_start); -- not a month; is it a season? get start season number
local range_end_number = get_season_number (range_end); -- get end season number
if 0 ~= range_start_number then -- is start of range a season?
if range_start_number < range_end_number then -- range_start is a season
return true; -- return true when range_end is also a season and follows start season; else false
end
if 4 == range_start_number and 1 == range_end_number then -- special case when range is Fall-Winter or Autumn-Winter
return true;
end
end
return false; -- range_start is not a month or a season; or range_start is a season and range_end is not; or improper season sequence
end
local range_end_number = get_month_number (range_end); -- get end month number
if range_start_number < range_end_number then -- range_start is a month; does range_start precede range_end?
return true; -- if yes, return true
end
return false; -- range_start month number is greater than or equal to range end number; or range end isn't a month
end
வரி 480 ⟶ 537:
function check_date (date_string)
local year;
local month=0; -- assume that month and day are not used; if either is zero then final year/month/day validation is not necessary
local day=0;
local day2=0; -- second day in a day range
local anchor_year;
local coins_date;
if date_string:match("^%d%d%d%d%-%d%d%-%d%d$") then -- Year-initial numerical year month day format
year, month, day=string.match(date_string, "(%d%d%d%d)%-(%d%d)%-(%d%d)");
month=tonumber(month);
if 12 < month or 1 > month or 1583 > tonumber(year) then return false; end -- month number not valid or not Gregorian calendar
anchor_year = year;
elseif date_string:match("^%a+
month = get_month_number (month);
if 0 == month then return false; end -- return false if month text isn't one of the twelve months
elseif date_string:match("^
if tonumber(day) >= tonumber(day2) then return false; end -- date range order is left to right: earlier to later; dates may not be the same;
month = get_month_number (month);
if 0 == month then return false; end -- return false if month text isn't one of the twelve months
elseif date_string:match("^[1-9]%d? +%a+ +[1-9]%d%d%d%a?$") then -- day-initial: day month year
day, month, anchor_year, year=string.match(date_string, "(%d%d*)%s*(%a+)%s*((%d%d%d%d)%a?)");
month = get_month_number (month
if 0 == month then return false; end -- return false if month text isn't one of the twelve months
elseif
day, day2, month, anchor_year, year=string.match(date_string, "(%d%d?)–(%d%d?) +(%a+) +((%d%d%d%d)%a?)");
if tonumber(day) >= tonumber(day2) then return false; end -- date range order is left to right: earlier to later; dates may not be the same;
month = get_month_number (month);
if 0 == month then return false; end -- return false if month text isn't one of the twelve months
elseif mw.ustring.match (date_string, "^%a+–%a+ +[1-9]%d%d%d%a?$") then -- month/season range year; months separated by endash
local month2
if false == is_valid_month_season_range(month, month2) then
return false;
end
elseif date_string:match("^%a+
month, anchor_year, year=string.match(date_string, "(%a+)%s*((%d%d%d%d)%a?)");
if 0 == get_month_number (month) then -- if month text isn't one of the twelve months, might be a season
return false; -- return false not a month or one of the five seasons
end
end
elseif date_string:match("^
anchor_year, year=string.match(date_string, "((%d%d%d%d?)%a?)");
else
return false; -- date format not one of the MOS:DATE approved formats
வரி 535 ⟶ 594:
if 0~=month and 0~=day then -- check year month day dates for validity
if 0~=day2 then -- If there is a second day (d–d Mmm YYYY or Mmm d–d, YYYY) test the second date
if false==is_valid_date(year,month,day2) then
return false; -- second date in date range string is not a real date return false; unset anchor_year and coins_date
end -- if second date range string is valid, fall through to test the first date range
end
if false==is_valid_date(year,month,day) then
return false; -- date string is not a real date return false; unset anchor_year and coins_date
end
end
coins_date= mw.ustring.gsub( date_string, "–", "-" ); -- if here, then date_string is valid; set coins_date and replace any ndash with a hyphen
return true, anchor_year, coins_date; -- format is good and date string represents a real date
வரி 561 ⟶ 627:
for k, v in pairs(date_parameters_list) do -- for each date-holding parameter in the list
if is_set(v) then -- if the parameter has a value
if v:match("^c%.
if 'date'==k then
good_date, anchor_year, COinS_date = true, v:match("((c%.
elseif 'year'==k then
good_date = true;
end
elseif 'year'==k then -- if the parameter is |year= (but not c. year)
if v:match("^
good_date = true;
end
வரி 912 ⟶ 978:
elseif k == 'PMC' then
table.insert( new_list, {handler.label, pmc( v, options.Embargo ) } );
elseif k == 'PMID' then
table.insert( new_list, {handler.label, pmid( v ) } );
elseif k == 'ISSN' then
table.insert( new_list, {handler.label, issn( v ) } );
வரி 1,278 ⟶ 1,346:
if not is_embargoed(Embargo) then
URL=cfg.id_handlers['PMC'].prefix .. ID_list['PMC']; -- set url to be the same as the PMC external link if not embargoed
URLorigin = cfg.id_handlers['PMC'].parameters[1]; -- set URLorigin to parameter name for use in error message if citation is missing a |title=
end
end
வரி 1,430 ⟶ 1,499:
not is_set(TranscriptURL) then
-- Test if cite web
-- Test if accessdate is given without giving a URL
வரி 1,476 ⟶ 1,545:
TransChapter = wrap( 'trans-italic-title', TransChapter );
else
Chapter = kern_quotes (Chapter); -- if necessary, separate chapter title's leading and trailing quote marks from Module provided quote marks
Chapter = wrap( 'quoted-title', Chapter );
TransChapter = wrap( 'trans-quoted-title', TransChapter );
வரி 1,523 ⟶ 1,593:
if is_set(Periodical) then
Title = kern_quotes (Title); -- if necessary, separate title's leading and trailing quote marks from Module provided quote marks
Title = wrap( 'quoted-title', Title );
TransTitle = wrap( 'trans-quoted-title', TransTitle );
elseif inArray(config.CitationClass, {"web","news","pressrelease","conference","podcast"}) and
not is_set(Chapter) then
Title = kern_quotes (Title); -- if necessary, separate title's leading and trailing quote marks from Module provided quote marks
Title = wrap( 'quoted-title', Title );
TransTitle = wrap( 'trans-quoted-title', TransTitle );
வரி 1,593 ⟶ 1,665:
if is_set(Pages) then
if is_set(Periodical) and
not inArray(config.CitationClass, {"encyclopaedia","web","book","news","podcast"}) then
Pages = ": " .. Pages;
elseif tonumber(Pages) ~= nil then
வரி 1,603 ⟶ 1,675:
else
if is_set(Periodical) and
not inArray(config.CitationClass, {"encyclopaedia","web","book","news","podcast"}) then
Page = ": " .. Page;
else
வரி 1,641 ⟶ 1,713:
]]
if is_set (Language) then
-- local name = mw.language.fetchLanguageName( Language:lower(), "en" ); -- experiment: this seems to return correct ISO 639-1 language names
local name = cfg.iso639_1[Language:lower()]; -- get the language name if Language parameter has a valid iso 639-1 code
if nil == name then
வரி 1,659 ⟶ 1,732:
-- handle type parameter for those CS1 citations that have default values
if inArray(config.CitationClass, {"
TitleType = set_titletype (config.CitationClass, TitleType);
if is_set(Degree) and "Thesis" == TitleType then -- special case for cite thesis
வரி 1,782 ⟶ 1,855:
local Publisher;
if is_set(Periodical) and
not inArray(config.CitationClass, {"encyclopaedia","web","pressrelease","podcast"}) then
if is_set(PublisherName) then
if is_set(PublicationPlace) then
வரி 1,829 ⟶ 1,902:
end
end
--[[
Handle the oddity that is cite speech. This code overrides whatever may be the value assigned to TitleNote (through |department=) and forces it to be " (Speech)" so that
the annotation directly follows the |title= parameter value in the citation rather than the |event= parameter value (if provided).
]]
if "speech" == config.CitationClass then -- cite speech only
TitleNote = " (Speech)"; -- annotate the citation
if is_set (Periodical) then -- if Periodical, perhaps because of an included |website= or |journal= parameter
if is_set (Conference) then -- and if |event= is set
Conference = Conference .. sepc .. " "; -- then add appropriate punctuation to the end of the Conference variable before rendering
end
end
end
-- Piece all bits together at last. Here, all should be non-nil.
வரி 1,951 ⟶ 2,037:
end
names[ #names + 1 ] = first_set(Year, anchor_year); -- Year first for legacy citations
id = anchorid(names)
end
| |||