Module:Citation/CS1: திருத்தங்களுக்கு இடையிலான வேறுபாடு
உள்ளடக்கம் நீக்கப்பட்டது உள்ளடக்கம் சேர்க்கப்பட்டது
Better version of strip_apostrophe_markup()? |
Synch from sandbox; |
||
வரிசை 37:
--[[
Categorize and emit an error message when the citation contains one or more deprecated parameters. Because deprecated parameters (currently
|coauthor=, and |coauthors=) aren't related to each other and because these parameters may be concatenated into the variables used by |date= and |author#= (and aliases)
details of which parameter caused the error message are not provided. Only one error message is emitted regardless of the number of deprecated parameters in the citation.
வரிசை 50:
-- 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
--[[--------------------------< K E R N _ Q U O T E S >--------------------------------------------------------
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
"'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)
Double single quotes (italic or bold wikimarkup) are not kerned.
Call this function for chapter titles, for website titles, etc; not for book titles.
]]
function kern_quotes (str)
local cap='';
local cap2='';
if is_set (cap) then
str = substitute (cfg.presentation['kern-left'], {cap, cap2});
end
cap, cap2 = str:match ("^(.+[^\'])([\"\'])$")
if is_set (cap) then
str = substitute (cfg.presentation['kern-right'], {cap, cap2});
end
return str;
வரி 110 ⟶ 118:
if is_set (name) then -- is prefix a proper ISO 639-1 language code?
script_value = script_value:gsub ('^%l%l%s*:%s*', ''); -- strip prefix from script
if inArray (lang, {'ar', 'bs', 'dv', 'el', 'fa', 'hy', 'ja', 'ko', 'ku', 'he', 'ps', 'ru', 'sd', 'sr', 'th', 'uk', 'ug', 'yi', 'zh'}) then
table.insert( z.properties_cats, 'CS1 uses ' .. name .. '-language script ('..lang..')'); -- categorize in language-specific categories
else
வரி 120 ⟶ 129:
end
end
script_value = substitute (cfg.presentation['
return script_value;
வரி 141 ⟶ 150:
end
--[[--------------------------< W R A P _ S T Y L E >----------------------------------------------------------
Applies styling to various parameters. Supplied string is wrapped using a message_list configuration taking one
argument; protects italic styled parameters. Additional text taken from citation_config.presentation - the reason
this function is similar to but separate from wrap_msg().
]]
function wrap_style (key, str)
if not is_set( str ) then
return "";
வரி 148 ⟶ 165:
str = safeforitalics( str );
end
end
--[[--------------------------< W R A P _ M S G >--------------------------------------------------------------
Applies additional message text to various parameter values. Supplied string is wrapped using a message_list
configuration taking one argument. Supports lower case text for {{citation}} templates. Additional text taken
from citation_config.messages - the reason this function is similar to but separate from wrap_style().
]]
function wrap_msg (key, str, lower)
if not is_set( str ) then
return "";
end
if true == lower then
local msg;
msg = cfg.messages[key]:lower(); -- set the message to lower case before
str = substitute( msg, {str} ); -- including template text
return str;
else
return substitute( cfg.messages[key], {str} );
end
end
--[[--------------------------< F O R M A T _ C H A P T E R _ T I T L E >--------------------------------------
Format the three chapter parameters: |chapter=, |trans-chapter=, and |chapter-url= into a single Chapter meta-
parameter (chapter_url_source used for error messages).
]]
function format_chapter_title (chapter, transchapter, chapterurl, chapter_url_source)
local chapter_error = '';
if not is_set (chapter) then
chapter = ''; -- just to be safe for concatenation
if is_set (transchapter) then
chapter = wrap_style ('trans-quoted-title', transchapter);
chapter_error = " " .. seterror ('trans_missing_chapter');
end
if is_set (chapterurl) then
chapter = externallink (chapterurl, chapter, chapter_url_source); -- adds bare_url_missing_title error if appropriate
end
return chapter .. chapter_error;
else -- here when chapter is set
chapter = kern_quotes (chapter); -- if necessary, separate chapter title's leading and trailing quote marks from Module provided quote marks
chapter = wrap_style ('quoted-title', chapter);
if is_set (transchapter) then
transchapter = wrap_style ('trans-quoted-title', transchapter);
chapter = chapter .. ' ' .. transchapter;
end
if is_set (chapterurl) then
chapter = externallink (chapterurl, chapter); -- adds bare_url_missing_title error if appropriate
end
end
return chapter;
end
வரி 233 ⟶ 304:
end
--[[--------------------------< E R R O R C O M M E N T >------------------------------------------------------
Wraps error messages with css markup according to the state of hidden.
]]
function errorcomment( content, hidden )
return
end
வரி 303 ⟶ 378:
label = URL;
if is_set( source ) then
error_str = seterror( 'bare_url_missing_title', {
else
error( cfg.messages["bare_url_no_origin"] );
வரி 314 ⟶ 389:
end
--[[--------------------------< N O W R A P _ D A T E >--------------------------------------------------------
When date is YYYY-MM-DD format wrap in nowrap span: <span ...>YYYY-MM-DD</span>. When date is DD MMMM YYYY or is
MMMM DD, YYYY then wrap in nowrap span: <span ...>DD MMMM</span> YYYY or <span ...>MMMM DD,</span> YYYY
DOES NOT yet support MMMM YYYY or any of the date ranges.
]]
function nowrap_date (date)
local cap='';
local cap2='';
if date:match("^%d%d%d%d%-%d%d%-%d%d$") then
date = substitute (cfg.presentation['nowrap1'], date);
elseif date:match("%a+%s*%d%d?,%s*%d%d%d%d") or date:match ("%d%d?%s*%a+%s*%d%d%d%d") then
cap, cap2 = string.match (date, "^(.*)%s+(%d%d%d%d)$");
date = substitute (cfg.presentation['nowrap2'], {cap, cap2});
end
return date;
end
--[[--------------------------< A M A Z O N >------------------------------------------------------------------
Formats a link to Amazon. Do simple error checking: asin must be mix of 10 numeric or uppercase alpha
characters. If a mix, first character must be uppercase alpha; if all numeric, asins must be 10-digit
isbn. If 10-digit isbn, add a maintenance category so a bot or awb script can replace |asin= with |isbn=.
Error message if not 10 characters, if not isbn10, if mixed and first character is a digit.
]]
function amazon(id, domain)
local err_cat = ""
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 = ' ' .. seterror ('bad_asin'); -- asin is not a mix of 10 uppercase alpha and numeric characters
else
if id:match("^%d%d%d%d%d%d%d%d%d%d$") then -- if 10-digit numeric
if checkisbn( id ) then -- see if asin value is isbn10
table.insert( z.maintenance_cats, "CS1 maint: ASIN uses ISBN"); -- add to maint category
elseif not is_set (err_cat) then
err_cat = ' ' .. seterror ('bad_asin'); -- asin is not isbn10
end
elseif not id:match("^%u[%d%u]+$") then
err_cat = ' ' .. seterror ('bad_asin'); -- asin doesn't begin with uppercase alpha
end
end
if not is_set(domain) then
வரி 329 ⟶ 448:
return externallinkid({link = handler.link,
label=handler.label , prefix="//www.amazon."..domain.."/dp/",id=id,
encode=handler.encode, separator = handler.separator}) .. err_cat;
end
வரி 647 ⟶ 766:
return text
end
--[[--------------------------< M E S S A G E _ I D >----------------------------------------------------------
Validate and format a usenet message id. Simple error checking, looks for 'id-left@id-right' not enclosed in
'<' and/or '>' angle brackets.
]]
function message_id (id)
local handler = cfg.id_handlers['USENETID'];
text = externallinkid({link = handler.link, label = handler.label,
prefix=handler.prefix,id=id,separator=handler.separator, encode=handler.encode})
if not id:match('^.+@.+$') or not id:match('^[^<].*[^>]$')then -- doesn't have '@' or has one or first or last character is '< or '>'
text = text .. ' ' .. seterror( 'bad_message_id' ) -- add an error message if the message id is invalid
end
return text
end
--[[
வரி 1,018 ⟶ 1,159:
end
if ( "scap" == format ) then -- apply smallcaps formatting when authorformat or editorformat set to scap
result = substitute (cfg.presentation['smallcaps'], result);
end
return result, count
வரி 1,088 ⟶ 1,228:
end
--[[--------------------------< B U I L D I D L I S T >--------------------------------------------------------
Takes a table of IDs and turns it into a table of formatted ID outputs.
]]
function buildidlist( id_list, options )
local new_list, handler = {};
function fallback(k) return { __index = function(t,i) return cfg.id_handlers[k][i] end } end;
வரி 1,126 ⟶ 1,269:
end
table.insert( new_list, {handler.label, ISBN } );
elseif k == 'USENETID' then
table.insert( new_list, {handler.label, message_id( v ) } );
else
error( cfg.messages['unknown_manual_ID'] );
வரி 1,185 ⟶ 1,330:
for _, k in ipairs( error_list ) do
if error_str ~= "" then error_str = error_str .. cfg.messages['parameter-separator'] end
error_str = error_str ..
end
if #error_list > 1 then
வரி 1,192 ⟶ 1,337:
error_str = error_str .. cfg.messages['parameter-pair-separator'];
end
error_str = error_str ..
table.insert( z.message_tail, { seterror( error_condition, {error_str}, true ) } );
end
வரி 1,220 ⟶ 1,365:
OCinSoutput.rft_val_fmt = "info:ofi/fmt:kev:mtx:book";
OCinSoutput["rft.genre"] = "bookitem";
OCinSoutput["rft.
OCinSoutput["rft.
elseif is_set(data.Periodical) then
OCinSoutput.rft_val_fmt = "info:ofi/fmt:kev:mtx:journal";
வரி 1,334 ⟶ 1,479:
the page is a mainspace page and the ISO639-1 code is not 'en'. Similarly, if the parameter is |language=Norwegian, it will be categorized in the same way.
]]
வரி 1,358 ⟶ 1,502:
if is_set (code) then
if 'no' == code then name = 'Norwegian' end; -- override wikimedia when code is 'no'
end
else
table.insert (z.maintenance_cats, 'CS1 maint: Unrecognized language'); -- add maintenance category when |language= does not appear to be ISO 639-1 language
end
return (" " .. wrap_msg ('language', name)); -- wrap with '(in ...)'
end
வரி 1,409 ⟶ 1,555:
local TitleLink = A['TitleLink'];
local Chapter = A['Chapter'];
local ChapterLink = A['ChapterLink']; -- deprecated
local TransChapter = A['TransChapter'];
local TitleType = A['TitleType'];
வரி 1,445 ⟶ 1,591:
local Language = A['Language'];
local Format = A['Format'];
local ChapterFormat = A['ChapterFormat'];
local Ref = A['Ref'];
local DoiBroken = A['DoiBroken'];
வரி 1,453 ⟶ 1,600:
local ID_list = extractids( args );
local Quote = A['Quote'];
local PostScript = A['PostScript'];
வரி 1,477 ⟶ 1,617:
local Callsign = A['Callsign'];
local City = A['City'];
local Program = A['Program'];
--local variables that are not cs1 parameters
local
local this_page = mw.title.getCurrentTitle(); -- also used for COinS and for language
local anchor_year; -- used in the CITEREF identifier
local COinS_date; -- used in the COinS metadata
வரி 1,535 ⟶ 1,672:
|trans_title maps to |trans_chapter when |title is re-mapped
|url maps to |chapterurl when |title is remapped
All other combinations of |encyclopedia, |title, and |article are not modified
வரி 1,544 ⟶ 1,682:
Chapter = Title; -- |encyclopedia and |title are set so map |title to |article and |encyclopedia to |title
TransChapter = TransTitle;
ChapterURL = URL;
Title = Periodical;
Periodical = ''; -- redundant so unset
TransTitle = ''; -- redundant so unset
URL = ''; -- redundant so unset
end
else -- |title not set
வரி 1,568 ⟶ 1,708:
end
end
use_lowercase = ( sepc ~= '.' ); -- used to control capitalization for certain static text
-- check for special case where |separator=none
வரி 1,606 ⟶ 1,747:
end
if is_set(
if is_set(TitleType) then
Others = ' ' .. TitleType .. ' with ' ..
TitleType = '';
else
Others = ' ' .. 'Interview with ' ..
end
else
வரி 1,671 ⟶ 1,809:
-- end of {{cite episode}} stuff]]
-- legacy: promote concatenation of
if
if is_set (Year) then
table.insert( z.maintenance_cats, "CS1 maint: Date and year"); -- add to maint category
end
else
Date = Year; -- promote Year to Date
Year = nil; -- make nil so Year as empty string isn't used for CITEREF
வரி 1,679 ⟶ 1,821:
if is_set(Month) then
Date = Month .. " " .. Date;
end
elseif is_set(PublicationDate) then -- use PublicationDate when |date= and |year= are not set
வரி 1,735 ⟶ 1,875:
end
]]
-- special case for cite newsgroup. Do this after COinS because we are modifying Publishername
if 'newsgroup' == config.CitationClass then
if is_set (PublisherName) then
PublisherName = '[[Newsgroup]]: ' .. externallink( 'news:' .. PublisherName, PublisherName );
end
end
வரி 1,750 ⟶ 1,890:
if not is_set(Authors) then
local Maximum = tonumber( A['DisplayAuthors'] );
if is_set (Maximum) then
if Maximum >= #a then -- if display-authors value greater than or equal to number of authors
table.insert( z.maintenance_cats, "CS1 maint: display-authors"); -- add maintenance category because display-authors parameter may be removed
end
else
Maximum = #a + 1; -- number of authors + 1
end
local control = {
sep = A["AuthorSeparator"] .. " ",
வரி 1,798 ⟶ 1,938:
maximum = Maximum,
lastauthoramp = LastAuthorAmp,
page_name = this_page.text -- get current page name so that we don't wikilink to it via
};
வரி 1,815 ⟶ 1,955:
Cartography = A['Cartography'];
if is_set( Cartography ) then
Cartography = sepc .. " " ..
end
Scale = A['Scale'];
வரி 1,823 ⟶ 1,963:
end
Format = is_set(Format) and " (" .. Format .. ")" or "";
if not is_set(URL) and
not is_set(ArchiveURL) and
not is_set(ConferenceURL) and
வரி 1,835 ⟶ 1,976:
-- 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?
table.insert( z.message_tail, { seterror( 'accessdate_missing_url', {}, true ) } );
AccessDate = '';
வரி 1,842 ⟶ 1,983:
-- Test if format is given without giving a URL
if is_set(Format) then
Format = Format .. seterror( 'format_missing_url', {'format', 'url'} );
end
end
-- Test if citation has no title
if not is_set(Title) and
வரி 1,855 ⟶ 1,996:
end
local OriginalURL;
DeadURL = DeadURL:lower(); -- used later when assembling archived text
if is_set( ArchiveURL ) then
if is_set (
OriginalURL = URL; -- save copy of original source URL
if 'no' ~= DeadURL then -- if URL set then archive-url applies to it
URL = ArchiveURL -- swap-in the archive's url
URLorigin = A:ORIGIN('ArchiveURL') -- name of archive url parameter for error messages
end
elseif is_set (ChapterURL) then -- URL not set so if chapter-url is set apply archive url to it
OriginalURL = ChapterURL; -- save copy of source chapter's url for archive text
if 'no' ~= DeadURL then
ChapterURL = ArchiveURL -- swap-in the archive's url
URLorigin = A:ORIGIN('ArchiveURL') -- name of archive url parameter for error messages
end
end
end
if inArray(config.CitationClass, {"web","news","journal","pressrelease","conference","podcast", "newsgroup"}) or ('citation' == config.CitationClass and is_set (Periodical)) then
if is_set (Chapter) or is_set (TransChapter) or is_set (ChapterURL)then -- chapter parameters not supported for these citation types
table.insert( z.message_tail, { seterror( 'chapter_ignored', {}, true ) } ); -- add error message
Chapter = ''; -- set to empty string to be safe with concatenation
TransChapter = '';
ChapterURL = '';
end
else -- otherwise, format chapter / article title
Chapter = format_chapter_title (Chapter, TransChapter, ChapterURL, ChapterURLorigin);
if is_set (Chapter) then
ChapterFormat = is_set(ChapterFormat) and " (" .. ChapterFormat .. ")" or "";
if is_set(ChapterFormat) and not is_set (ChapterURL) then -- Test if |chapter-format= is given without giving a |chapter-url=
ChapterFormat = ChapterFormat .. seterror( 'format_missing_url', {'chapter-format', 'chapter-url'} );
end
Chapter = Chapter .. ChapterFormat .. sepc .. ' ';
end
end
-- Format main title.
if is_set(TitleLink) and is_set(Title) then
வரி 1,916 ⟶ 2,038:
end
if inArray(config.CitationClass, {"web","news","journal","pressrelease","conference","podcast", "newsgroup"}) or ('citation' == config.CitationClass and is_set (Periodical)) then
Title = kern_quotes (Title); -- if necessary, separate title's leading and trailing quote marks from Module provided quote marks
Title =
Title = script_concatenate (Title, ScriptTitle); -- <bdi> tags, lang atribute, categorization, etc; must be done after title is wrapped
TransTitle
else
Title =
Title = script_concatenate (Title, ScriptTitle); -- <bdi> tags, lang atribute, categorization, etc; must be done after title is wrapped
TransTitle =
end
வரி 1,950 ⟶ 2,072:
if is_set(Place) then
Place = " " ..
end
வரி 2,011 ⟶ 2,133:
if first_set( Pages, Page, At ) ~= nil or sepc ~= '.' then
if is_set( Section ) then
Section = ", " ..
end
if is_set( Inset ) then
Inset = ", " ..
end
else
if is_set( Section ) then
Section = sepc .. " " ..
if is_set( Inset ) then
Inset = ", " ..
end
elseif is_set( Inset ) then
Inset = sepc .. " " ..
end
end
வரி 2,051 ⟶ 2,173:
TitleNote = is_set(TitleNote) and (sepc .. " " .. TitleNote) or "";
Edition = is_set(Edition) and (" " ..
Issue = is_set(Issue) and (" (" .. Issue .. ")") or "";
Series = is_set(Series) and (sepc .. " " .. Series) or "";
வரி 2,064 ⟶ 2,186:
end
------------------------------------ totally unrelated data
if is_set(Via) then
Via = " " ..
end
--[[
Subscription implies paywall; Registration does not. If both are used in a citation, the subscription required link
note is displayed. There are no error messages for this condition.
]]
if is_set(SubscriptionRequired) then
SubscriptionRequired = sepc .. " " .. cfg.messages['subscription'];
elseif is_set(RegistrationRequired) then
SubscriptionRequired = sepc .. " " .. cfg.messages['registration'];
end
if is_set(AccessDate) then
local retrv_text = " " .. cfg.messages['retrieved']
AccessDate = nowrap_date (AccessDate); -- wrap in nowrap span if date in appropriate format
if (sepc ~= ".") then retrv_text = retrv_text:lower() end -- if 'citation', lower case
AccessDate = substitute (retrv_text, AccessDate); -- add retrieved text
-- neither of these work; don't know why; it seems that substitute() isn't being called
AccessDate = substitute (cfg.presentation['accessdate'], {sepc, AccessDate}); -- allow editors to hide accessdates
end
வரி 2,103 ⟶ 2,217:
end
ID_list = buildidlist( ID_list, {DoiBroken = DoiBroken, ASINTLD = ASINTLD, IgnoreISBN = IgnoreISBN, Embargo=Embargo} );
வரி 2,114 ⟶ 2,227:
Quote = Quote:sub(2,-2);
end
Quote = sepc .." " ..
PostScript = ""; -- CS1 does not supply terminal punctuation when |quote= is set
end
வரி 2,185 ⟶ 2,298:
if is_set(PublicationDate) then
if is_set(Publisher) then
Publisher = Publisher .. ", " ..
else
Publisher = PublicationDate;
வரி 2,195 ⟶ 2,308:
else
if is_set(PublicationDate) then
PublicationDate = " (" ..
end
if is_set(PublisherName) then
வரி 2,213 ⟶ 2,326:
if is_set(Periodical) then
if is_set(Title) or is_set(TitleNote) then
Periodical = sepc .. " " ..
else
Periodical =
end
end
| |||