Module:CS1 identifiers: Difference between revisions

Content deleted Content added
create;
 
No edit summary
 
(6 intermediate revisions by 2 users not shown)
Line 15:
identifiers.set_selected_modules (cfg, utilities); -- so that functions in Identifiers can see the selected cfg tables and selected Utilities module
 
local Frame; -- local copy of <frame> from main(); nil else
local this_page = mw.title.getCurrentTitle(); -- used to limit categorization to certain namepsaces
 
Line 123 ⟶ 124:
 
 
--[[--------------------------< _R ME AN D E R _ F I N A L >--------------------------------------------------------------------
 
this function applies cs1|2 template style sheet to a rendered identifier or error message
supported identifier templates are:
{{arxiv}} {{bibcode}} {{biorxiv}} {{citeseerx}} {{doi}}
{{hdl}} {{isbn}} {{issn}} {{jfm}} {{jstor}}
{{medrxiv}} {{mr}} {{oclc}} {{osti}} {{pmc}}
{{pmid}} {{ssrn}} {{zbl}}
 
]]
|leadout=, |plainlink=, and |link= are supported by most identifier templates use {{Catalog lookup link}}. These
parameters are supported by this module.
 
local function render_final (output)
Some identifier templates have special features that are not supported by this module:
if not Frame then -- not set when this module called from another module
{{lccn}} – supported by Module:LCCN so not supported here
Frame = mw.getCurrentFrame(); -- get the calling module's frame so that we can call extensionTag()
end
 
return substitute ('$1$2', {
frameFrame:extensionTag ('templatestyles', '', {src='Module:Citation/CS1/styles.css'}), -- apply templatestyles
output -- to the rendered identifier or error message
});
 
end
 
 
--[[--------------------------< _ M A I N >--------------------------------------------------------------------
 
entry point when called from another module; example:
local rendered_identifier = require ('Module:CS1 identifiers')._main ({'10.4231/sommat', _template = 'doi', ['doi-access'] = 'free', ['doi-broken-date'] = 'June 2025'});
 
supported identifier templates are:
{{arxiv}} {{asin}} {{bibcode}} {{biorxiv}} {{citeseerx}} {{doi}}
{{hdl}} {{isbn}} {{ismn}} {{issn}} {{jfm}} {{jstor}}
{{medrxiv}} {{mr}} {{oclc}} {{ol}} {{osti}} {{pmc}}
{{pmid}} {{sbn}} {{ssrn}} {{s2cid}} {{zbl}}
 
<args_t> is a table of all parameters needed to properly render the identifier
{{hdl}} – supports |hdl-access= limited, registration, subscription though these are not used anywhere
{{ISBN}} – supports:
|invalid<n>= ~100 article uses; can be replaced with accept-as-written markup ((..))
|template_name= does not appear to be used
{{ISSN}} – supports |invalid<n>= ~0 article uses; can be replaced with accept-as-written markup ((..))
{{JSTOR}} – supports:
|stable= ~5 article uses; alias of {{{1}}}
|sici= does not appear to be used
|issn= ~5 article uses
|no= does not appear to be used; alias of |issn=
{{OCLC}} – supports |show=; ~10 article uses
 
]]
Line 170 ⟶ 177:
repeat -- loop until no
local params_t = params_get (args_t, i); -- get the parameters associated with enumerator <i>
params_t[template_name] = params_t[1] or params_t['id']; -- assign value from {{{1}}} or |id= to |<identifier>=
params_t._template = nil; -- unset as no longer needed
if not params_t[template_name] then -- in case params_t[1] and params_t.id are nil
params_t[template_name] = ''; -- set <id> to empty string
return render_final ( -- make an error message and done
return substitute ('<span class="cs1-visible-error citation-comment">' .. message_prefix .. '$1: required identifier missing ($2)</span>$3'; --, abandon when no identifier{
message_prefix,
substitute ('[[Template:$1|help]]', template_name),
no_cat and '' or substitute ('[[Category:Pages with $1 errors]]', template_name:upper())
}));
end
params_t[i] = nil; -- unset these as no longer needed
Line 182 ⟶ 194:
local Embargo = params_t['pmc-embargo-date']; -- {{pmc}} only
local Class = params_t['class']; -- {{arxiv}} only
local AsinTLD = params_t['asin-tld']; -- {{asin}} only
 
ID_list_t, ID_list_coins_t = identifiers.identifier_lists_get (params_t, {DoiBroken = DoiBroken, Embargo = Embargo, Class = Class, ASINTLD = AsinTLD}, {}); -- {} is a placeholder for unused ID_support{}
rendered_id = ID_list_t[1];
 
Line 220 ⟶ 233:
 
if leadout then -- extra text goes between last two identifiers in the list
return render_final (mw.text.listToText (rendered_ids_t, list_separator, leadout)); -- make a list, add templatestyles, and done
end
 
return render_final (table.concat (rendered_ids_t, list_separator)); -- make a list, add templatestyles, and done
end
 
Line 229 ⟶ 242:
--[[--------------------------< M A I N >----------------------------------------------------------------------
 
entry point from an invoke
{{#invoke:identifiers|main|_template=<identifier name>}}
 
{{#invoke:CS1 identifiers|main|_template=<identifier name>}}
]]
 
local function main (frame)
Frame = frame; -- make a copy for rendering final output
local args_t = get_args (frame); -- extract the arguments
 
return _main (args_t); -- render the identifier and done
return substitute ('$1$2', {
frame:extensionTag ('templatestyles', '', {src='Module:Citation/CS1/styles.css'}),
_main (args_t)
});
end
 
Line 247 ⟶ 260:
 
return {
main = main, -- entry point from an invoke (in a template usually)
main = main
_main = _main -- entry point when called from another module
}