モジュール:Catalog lookup link

--url-accessn= – applies specified icon to item n of the list (the nth positional parameter); accepted keywords: free, limited, registration, subscription;
require('strict');
local getArgs = require ('Module:Arguments').getArgs;
local lock_icons = {															--icon classes are defined in Module:Citation/CS1/styles.css
	'free' = {'cs1-lock-free', 'Freely accessible'},
	'registration' = {'cs1-lock-registration', 'Free registration required'},
	'limited' = {'cs1-lock-limited', 'Free access subject to limited trial, subscription normally required'},
	'subscription' = {'cs1-lock-subscription', 'Paid subscription required'},
	}
----------------------------------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
local function is_set( var )
	return not (var == nil or var == );
end
--=-----------------------------------------------------------------------------------
Makes a wikilinked or plain text label from arguments; when both link and display text is provided, makes a
wikilink in the form D; if only link is provided, makes a wikilinked label in the form L; if only display
is provided, makes a plain-text label; if neither are provided makes a label from suffix, returns an empty string else.
**
local function make_label (link, display, suffix)
local label = ;
	if is_set (link) then
		if is_set (display) then
			label = table.concat ({, display, });			-- make D wikilinked label
		else
			label = table.concat ({, link, });							-- make L wikilinked label
		end
	elseif is_set (display) then
		label = display;														-- plain-text label
	end
	if is_set (label) then														
		return table.concat ({label, suffix, ' '});						-- assemble the complete label
	else
		return suffix;															-- no space after suffix if no label
	end
end
--allow_icons=none for isbn, issn, oclc, etc
url-access1=
local function icon_index_get (args, k)
	local icon;
	local param_name = (1 == k and is_set (args'url-access') and 'url-access') or table.concat ({'url-access', k});	-- make an enumerated parameter name
	if is_set (args'url-access-all') and lock_iconsargs'url-access-all' then	-- if set and valid
		icon = args'url-access-all';											-- tentatively 
	elseif is_set (argsparam_name) and lock_iconsargsparam_name then		-- if set and valid
		icon = argsparam_name;												-- tentatively
	else
		return nil;																-- neither |url-access-all= nor |url-accessn= set so return nil
	end
	if args'allow_icons' and args'allow_icons':find ('none') then			-- if 'none' keyword is present
		return nil;																-- icons display not allowed
	end
	if not is_set (args'allow_icons') or args'allow_icons':find ('all') or args'allow_icons':find (icon) then	--if all allowed or specified icon is allowed
		return icon;															-- return selected icon as index into icon table
	end
end
--allowed-icons= is typically set, if needed, in the .
local function main (frame)
	local args = getArgs (frame);
	local out_text = ;
	if is_set(args1) then
		local result = {};
		local label;
		
		local article_suffix = args'article-suffix' or args'article-postfix' or ;
		local link_prefix = args'link-prefix' or ;
		local link_suffix = args'link-suffix' or args'link-postfix' or ;
		local item_prefix = args'item-prefix' or ;
		local item_suffix = args'item-suffix' or args'item-postfix' or ;
		local list_separator = args'list-separator' or ', ';
		local leadout_suffix = args'leadout-suffix' or args'leadout-postfix' or ' ';
		local list_leadout;
		local icon_index;
		
		if is_set (args'list-leadout') then
			list_leadout = table.concat ({
				mw.ustring.gsub (args'list-leadout', '^(%a)', ' %1'),			-- insert leading space if first character is a letter
				leadout_suffix,
			});
		else
			list_leadout = ;
		end
		
		label = make_label (args'article-link', args'article-name', article_suffix);
		for k, item in ipairs (args) do											-- for each of the positional parameters
			item = mw.text.trim (item);											-- remove extraneous whitespace
			if is_set (link_prefix) then										-- if there is link prefix...
				item = table.concat ({											-- create an external link item
					,														-- open ext link markup
					link_prefix,												-- url prefix
					mw.uri.encode (item),										-- item is part of url
					link_suffix,												-- url suffix
					' ',														-- required space between url and label
					item_prefix,												-- label prefix
					item,														-- item as label
					item_suffix,												-- item suffix
																				-- close ext link markup
				});
				icon_index = icon_index_get (args, k);							-- set if icon specified and allowed for this item; nil else
				if icon_index then
					item = table.concat ({										-- add access icon markup to this item
						,													-- close the opening span tag
						item,
						,												-- and close the span
					});
				end	
			else
				item = table.concat ({											-- create an unlinked item
					item_prefix,												-- label prefix
					item,														-- item as label
					item_suffix,												-- item suffix
				});
			end
	
			table.insert (result, item);										-- add the item to the result list
		end
	
		if is_set (args'list-leadout') then
			out_text = table.concat ({label, mw.text.listToText (result, list_separator, list_leadout)});
		else
			out_text = table.concat ({label, table.concat (result, list_separator)});
		end
	end	--is_set (args1)
	
	return out_text
end
return {main = main};