添加的内容 删除的内容
(修改自此处;原许可:CC BY-SA 3.0[网站升级迁移]) |
SolidBlock(留言 | 贡献) 小 (更新(来自维基百科)) 标签:字词转换标记不匹配 |
||
第1行: | 第1行: | ||
--[[--------------------------< F O R W A R D D E C L A R A T I O N S >-------------------------------------- |
--[[--------------------------< F O R W A R D D E C L A R A T I O N S >-------------------------------------- |
||
]] |
]] |
||
local is_set, in_array, remove_wiki_link, strip_apostrophe_markup; -- functions in Module:Citation/CS1/Utilities |
local is_set, in_array, remove_wiki_link, strip_apostrophe_markup; -- functions in Module:Citation/CS1/Utilities and Module:Citation/CS1/Links |
||
local cfg; -- table of configuration tables that are defined in Module:Citation/CS1/Configuration |
local cfg; -- table of configuration tables that are defined in Module:Citation/CS1/Configuration |
||
第27行: | 第26行: | ||
script = strip_apostrophe_markup (script); -- strip any apostrophe markup |
script = strip_apostrophe_markup (script); -- strip any apostrophe markup |
||
else |
else |
||
script = ''; -- if not set, make sure script is an empty string |
script = ''; -- if not set, make sure script is an empty string |
||
end |
end |
||
if is_set (title) and is_set (script) then |
if is_set (title) and is_set (script) then |
||
第66行: | 第65行: | ||
end |
end |
||
pages = pages:gsub("[%[%]]", ""); -- remove the brackets |
pages = pages:gsub("[%[%]]", ""); -- remove the brackets |
||
pages = pages:gsub("–", "-" ); |
pages = pages:gsub("–", "-" ); -- replace endashes with hyphens |
||
pages = pages:gsub("&%w+;", "-" ); |
pages = pages:gsub("&%w+;", "-" ); -- and replace HTML entities (– etc.) with hyphens; do we need to replace numerical entities like   and the like? |
||
return pages; |
return pages; |
||
end |
end |
||
第137行: | 第136行: | ||
end |
end |
||
value = value:gsub (cfg.stripmarkers['math'], "MATH RENDER ERROR"); -- one or more couldn't be replaced; insert vague error message |
value = value:gsub (cfg.stripmarkers['math'], "MATH RENDER ERROR"); -- one or more couldn't be replaced; insert vague error message |
||
value = mw.text.unstripNoWiki (value); -- replace nowiki stripmarkers with their content |
value = mw.text.unstripNoWiki (value); -- replace nowiki stripmarkers with their content |
||
第144行: | 第143行: | ||
value = value:gsub ('\226\128\138', ' '); -- replace hair space with plain space |
value = value:gsub ('\226\128\138', ' '); -- replace hair space with plain space |
||
if not mw.ustring.find (value, cfg.indic_script) then -- don't remove zero-width joiner characters from indic script |
if not mw.ustring.find (value, cfg.indic_script) then -- don't remove zero-width joiner characters from indic script |
||
value = value:gsub ('‍', ''); -- remove ‍ entities |
value = value:gsub ('‍', ''); -- remove ‍ entities |
||
value = mw.ustring.gsub (value, '[\226\128\141\226\128\139\194\173]', ''); -- remove zero-width joiner, zero-width space, soft hyphen |
value = mw.ustring.gsub (value, '[\226\128\141\226\128\139\194\173]', ''); -- remove zero-width joiner, zero-width space, soft hyphen |
||
end |
end |
||
value = value:gsub ('[\009\010\013 ]+', ' '); -- replace horizontal tab, line feed, carriage return with plain space |
value = value:gsub ('[\009\010\013 ]+', ' '); -- replace horizontal tab, line feed, carriage return with plain space |
||
return value; |
return value; |
||
end |
end |
||
第158行: | 第157行: | ||
]] |
]] |
||
local function COinS(data, class) |
local function COinS (data, class) |
||
if 'table' ~= type(data) or nil == next(data) then |
if 'table' ~= type (data) or nil == next (data) then |
||
return ''; |
return ''; |
||
end |
end |
||
第172行: | 第171行: | ||
-- treat table strictly as an array with only set values. |
-- treat table strictly as an array with only set values. |
||
local OCinSoutput = setmetatable |
local OCinSoutput = setmetatable ({}, { |
||
__newindex = function(self, key, value) |
__newindex = function(self, key, value) |
||
if is_set(value) then |
if is_set (value) then |
||
rawset |
rawset (self, #self+1, table.concat {key, '=', mw.uri.encode (remove_wiki_link (value))}); |
||
end |
end |
||
end |
end |
||
}); |
}); |
||
if in_array (class, {'arxiv', 'biorxiv', 'citeseerx', 'ssrn', 'journal', 'news', 'magazine'}) or (in_array (class, {'conference', 'interview', 'map', 'press release', 'web'}) and is_set(data.Periodical)) or |
if in_array (class, {'arxiv', 'biorxiv', 'citeseerx', 'ssrn', 'journal', 'news', 'magazine'}) or (in_array (class, {'conference', 'interview', 'map', 'press release', 'web'}) and is_set(data.Periodical)) or |
||
('citation' == class and is_set(data.Periodical) and not is_set (data.Encyclopedia)) then |
('citation' == class and is_set(data.Periodical) and not is_set (data.Encyclopedia)) then |
||
OCinSoutput.rft_val_fmt = "info:ofi/fmt:kev:mtx:journal"; -- journal metadata identifier |
OCinSoutput.rft_val_fmt = "info:ofi/fmt:kev:mtx:journal"; -- journal metadata identifier |
||
第193行: | 第192行: | ||
end |
end |
||
OCinSoutput["rft.jtitle"] = data.Periodical; -- journal only |
OCinSoutput["rft.jtitle"] = data.Periodical; -- journal only |
||
if is_set (data.Map) then |
|||
OCinSoutput["rft.atitle"] = data. |
OCinSoutput["rft.atitle"] = data.Map; -- for a map in a periodical |
||
else |
|||
⚫ | |||
OCinSoutput["rft.atitle"] = make_coins_title (data.Title, data.ScriptTitle); |
|||
-- all other 'periodical' article titles |
|||
end |
|||
⚫ | |||
OCinSoutput["rft.ssn"] = data.Season; -- keywords: winter, spring, summer, fall |
OCinSoutput["rft.ssn"] = data.Season; -- keywords: winter, spring, summer, fall |
||
OCinSoutput["rft.quarter"] = data.Quarter; -- single digits 1->first quarter, etc. |
|||
OCinSoutput["rft.chron"] = data.Chron; -- free-form date components |
OCinSoutput["rft.chron"] = data.Chron; -- free-form date components |
||
OCinSoutput["rft.volume"] = data.Volume; -- does not apply to books |
OCinSoutput["rft.volume"] = data.Volume; -- does not apply to books |
||
OCinSoutput["rft.issue"] = data.Issue; |
OCinSoutput["rft.issue"] = data.Issue; |
||
OCinSoutput["rft.pages"] = data.Pages; |
OCinSoutput["rft.pages"] = get_coins_pages (data.Pages); -- also used in book metadata |
||
elseif 'thesis' ~= class then -- all others except cite thesis are treated as 'book' metadata; genre distinguishes |
elseif 'thesis' ~= class then -- all others except cite thesis are treated as 'book' metadata; genre distinguishes |
||
第209行: | 第211行: | ||
elseif 'conference' == class then -- cite conference when Periodical not set |
elseif 'conference' == class then -- cite conference when Periodical not set |
||
OCinSoutput["rft.genre"] = "conference"; |
OCinSoutput["rft.genre"] = "conference"; |
||
OCinSoutput["rft.atitle"] = data.Chapter; -- conference paper as chapter in proceedings (book) |
|||
elseif in_array (class, {'book', 'citation', 'encyclopaedia', 'interview', 'map'}) then |
elseif in_array (class, {'book', 'citation', 'encyclopaedia', 'interview', 'map'}) then |
||
if is_set (data.Chapter) then |
if is_set (data.Chapter) or is_set (data.ScriptChapter) then |
||
OCinSoutput["rft.genre"] = "bookitem"; |
OCinSoutput["rft.genre"] = "bookitem"; |
||
OCinSoutput["rft.atitle"] = data.Chapter |
OCinSoutput["rft.atitle"] = make_coins_title (data.Chapter, data.ScriptChapter); |
||
-- book chapter, encyclopedia article, interview in a book, or map title |
|||
else |
else |
||
if 'map' == class or 'interview' == class then |
if 'map' == class or 'interview' == class then |
||
第221行: | 第223行: | ||
end |
end |
||
end |
end |
||
else -- |
else --{'AV media', 'AV media notes', 'episode', 'interview', 'mailinglist', 'map', 'newsgroup', 'podcast', 'press release', 'serial', 'sign', 'speech', 'web'} |
||
OCinSoutput["rft.genre"] = "unknown"; |
OCinSoutput["rft.genre"] = "unknown"; |
||
end |
end |
||
OCinSoutput["rft.btitle"] = data.Title |
OCinSoutput["rft.btitle"] = make_coins_title (data.Title, data.ScriptTitle); |
||
-- book only |
|||
OCinSoutput["rft.place"] = data.PublicationPlace; -- book only |
OCinSoutput["rft.place"] = data.PublicationPlace; -- book only |
||
OCinSoutput["rft.series"] = data.Series; -- book only |
OCinSoutput["rft.series"] = data.Series; -- book only |
||
OCinSoutput["rft.pages"] = data.Pages; |
OCinSoutput["rft.pages"] = get_coins_pages (data.Pages); -- book, journal |
||
OCinSoutput["rft.edition"] = data.Edition; -- book only |
OCinSoutput["rft.edition"] = data.Edition; -- book only |
||
OCinSoutput["rft.pub"] = data.PublisherName; -- book and dissertation |
OCinSoutput["rft.pub"] = data.PublisherName; -- book and dissertation |
||
第233行: | 第236行: | ||
else -- cite thesis |
else -- cite thesis |
||
OCinSoutput.rft_val_fmt = "info:ofi/fmt:kev:mtx:dissertation"; -- dissertation metadata identifier |
OCinSoutput.rft_val_fmt = "info:ofi/fmt:kev:mtx:dissertation"; -- dissertation metadata identifier |
||
OCinSoutput["rft.title"] = data.Title |
OCinSoutput["rft.title"] = make_coins_title (data.Title, data.ScriptTitle); |
||
-- dissertation (also patent but that is not yet supported) |
|||
OCinSoutput["rft.degree"] = data.Degree; -- dissertation only |
OCinSoutput["rft.degree"] = data.Degree; -- dissertation only |
||
OCinSoutput['rft.inst'] = data.PublisherName; -- book and dissertation |
OCinSoutput['rft.inst'] = data.PublisherName; -- book and dissertation |
||
end |
end |
||
-- NB. Not currently supported are "info:ofi/fmt:kev:mtx:patent", "info:ofi/fmt:kev:mtx:dc", "info:ofi/fmt:kev:mtx:sch_svc", "info:ofi/fmt:kev:mtx:ctx" |
|||
-- and now common parameters (as much as possible) |
-- and now common parameters (as much as possible) |
||
OCinSoutput["rft.date"] = data.Date; -- book, journal, dissertation |
OCinSoutput["rft.date"] = data.Date; -- book, journal, dissertation |
||
for k, v in pairs( |
for k, v in pairs (data.ID_list) do -- what to do about these? For now assume that they are common to all? |
||
if k == 'ISBN' then v = v:gsub( |
if k == 'ISBN' then v = v:gsub ("[^-0-9X]", ""); end |
||
local id = cfg.id_handlers[k].COinS; |
local id = cfg.id_handlers[k].COinS; |
||
if string.sub( |
if string.sub (id or "", 1, 4) == 'info' then -- for ids that are in the info:registry |
||
OCinSoutput["rft_id"] = table.concat{ |
OCinSoutput["rft_id"] = table.concat {id, "/", v}; |
||
elseif string.sub (id or "", 1, 3 |
elseif string.sub (id or "", 1, 3) == 'rft' then -- for isbn, issn, eissn, etc that have defined COinS keywords |
||
OCinSoutput[ |
OCinSoutput[id] = v; |
||
elseif |
elseif id then -- when cfg.id_handlers[k].COinS is not nil |
||
OCinSoutput["rft_id"] = table.concat |
OCinSoutput["rft_id"] = table.concat {cfg.id_handlers[k].prefix, v};-- others; provide a url |
||
elseif id then -- when cfg.id_handlers[k].COinS is not nil so urls created here |
|||
OCinSoutput["rft_id"] = table.concat{ cfg.id_handlers[k].prefix, v, cfg.id_handlers[k].suffix or '', "#id-name=", cfg.id_handlers[k].label }; -- others; provide a URL and indicate identifier name as #fragment (human-readable, but transparent to browsers) |
|||
end |
end |
||
end |
end |
||
local last, first; |
local last, first; |
||
for k, v in ipairs( |
for k, v in ipairs (data.Authors) do |
||
last, first = coins_cleanup (v.last), coins_cleanup (v.first or ''); -- replace any nowiki |
last, first = coins_cleanup (v.last), coins_cleanup (v.first or ''); -- replace any nowiki strip markers, non-printing or invisible characers |
||
if k == 1 then -- for the first author name only |
if k == 1 then -- for the first author name only |
||
if is_set(last) and is_set(first) then |
if is_set (last) and is_set (first) then -- set these COinS values if |first= and |last= specify the first author name |
||
OCinSoutput["rft.aulast"] = last; -- book, journal, dissertation |
OCinSoutput["rft.aulast"] = last; -- book, journal, dissertation |
||
OCinSoutput["rft.aufirst"] = first; -- book, journal, dissertation |
OCinSoutput["rft.aufirst"] = first; -- book, journal, dissertation |
||
第267行: | 第268行: | ||
else -- for all other authors |
else -- for all other authors |
||
if is_set(last) and is_set(first) then |
if is_set(last) and is_set(first) then |
||
OCinSoutput["rft.au"] = table.concat{ |
OCinSoutput["rft.au"] = table.concat {last, ", ", first}; -- book, journal, dissertation |
||
elseif is_set(last) then |
elseif is_set(last) then |
||
OCinSoutput["rft.au"] = last; -- book, journal, dissertation |
OCinSoutput["rft.au"] = last; -- book, journal, dissertation |
||
end |
end |
||
-- TODO: At present we do not report "et al.". Add anything special if this condition applies? |
|||
end |
end |
||
end |
end |
||
OCinSoutput.rft_id = data.URL; |
OCinSoutput.rft_id = data.URL; |
||
OCinSoutput.rfr_id = table.concat |
OCinSoutput.rfr_id = table.concat {"info:sid/", mw.site.server:match( "[^/]*$" ), ":", data.RawPage}; |
||
⚫ | |||
-- TODO: Add optional extra info: |
|||
-- rfr_dat=#REVISION<version> (referrer private data) |
|||
-- ctx_id=<data.RawPage>#<ref> (identifier for the context object) |
|||
-- ctx_tim=<ts> (timestamp in format yyyy-mm-ddThh:mm:ssTZD or yyyy-mm-dd) |
|||
-- ctx_enc=info:ofi/enc:UTF-8 (character encoding) |
|||
⚫ | |||
-- sort with version string always first, and combine. |
-- sort with version string always first, and combine. |
||
table.sort (OCinSoutput); |
|||
table.insert |
table.insert (OCinSoutput, 1, "ctx_ver=" .. ctx_ver); -- such as "Z39.88-2004" |
||
return table.concat(OCinSoutput, "&"); |
return table.concat (OCinSoutput, "&"); |
||
end |
end |
||
第299行: | 第292行: | ||
]] |
]] |
||
local function set_selected_modules (cfg_table_ptr, utilities_page_ptr) |
local function set_selected_modules (cfg_table_ptr, utilities_page_ptr, links_page_ptr) |
||
cfg = cfg_table_ptr; |
cfg = cfg_table_ptr; |
||
is_set = utilities_page_ptr.is_set; -- import functions from selected Module:Citation/CS1/Utilities module |
is_set = utilities_page_ptr.is_set; -- import functions from selected Module:Citation/CS1/Utilities module |
||
in_array = utilities_page_ptr.in_array; |
in_array = utilities_page_ptr.in_array; |
||
⚫ | |||
strip_apostrophe_markup = utilities_page_ptr.strip_apostrophe_markup; |
strip_apostrophe_markup = utilities_page_ptr.strip_apostrophe_markup; |
||
⚫ | |||
end |
end |
||
第313行: | 第307行: | ||
return { |
return { |
||
make_coins_title = make_coins_title, |
|||
get_coins_pages = get_coins_pages, |
|||
COinS = COinS, |
COinS = COinS, |
||
set_selected_modules = set_selected_modules, |
set_selected_modules = set_selected_modules, |
||
} |
} |