Module:Catalog lookup link/sandbox: Difference between revisions

Content deleted Content added
out→out_text
positional url-access parameters
Line 21:
require('Module:No globals');
local getArgs = require ('Module:Arguments').getArgs;
local lock_icons = {
['free'] = '[[File:Lock-green.svg|9px|link=|alt=Freely accessible|Freely accessible]]',
['registration'] = '[[File:Lock-blue-alt-2.svg|9px|link=|alt=Free registration required|Free registration required]]',
['limited'] = '[[File:Lock-blue-alt-2.svg|9px|link=|alt=Free access subject to limited trial, subscription normally required|Free access subject to limited trial, subscription normally required]]',
['subscription'] = '[[File:Lock-red-alt.svg|9px|link=|alt=Paid subscription required|Paid subscription required]]',
}
 
local p = {};
Line 36 ⟶ 42:
 
 
--[=[-------------------------< M A K E _ WL IA KB IE L I N K >----------------------------------------------------------
 
Makes a wikilinkwikilinked or plain text label from arguments; when both link and display text is provided, returnsmakes a wikilink in the form [[L|D]]; if only
wikilink in the form [[L|D]]; if only link is provided, returnsmakes a wikilinkwikilinked label in the form [[L]]; if neither are provided or link is omitted, returnsonly andisplay
is provided, makes a plain-text label; if neither are provided makes a label from postfix, returns an empty string else.
empty string.
 
]=]
 
local function make_wikilinkmake_label (link, display, postfix)
local label = '';
if is_set (link) then
if is_set (display) then
returnlabel = table.concat ({'[[', link, '|', display, ']]'}); -- make [[L|D]] wikilinked label
else
returnlabel = table.concat ({'[[', link, ']]'}); -- make [[L]] wikilinked label
end
elseif is_set (display) then
label = display; -- plain-text label
return display
end
 
if is_set (articlelabel) then
return table.concat ({label, postfix, '&nbsp;'}); -- assemble the complete label
else
return postfix or ''; -- no space after postfix if no label
return ''
end
end
 
 
 
Line 68 ⟶ 78:
local args = getArgs (frame);
local out_text = '';
 
if is_set(args[1]) then
local result = {};
local articlelabel;
local lock_icons = {
['free'] = '[[File:Lock-green.svg|9px|link=|alt=Freely accessible|Freely accessible]]',
['registration'] = '[[File:Lock-blue-alt-2.svg|9px|link=|alt=Free registration required|Free registration required]]',
['limited'] = '[[File:Lock-blue-alt-2.svg|9px|link=|alt=Free access subject to limited trial, subscription normally required|Free access subject to limited trial, subscription normally required]]',
['subscription'] = '[[File:Lock-red-alt.svg|9px|link=|alt=Paid subscription required|Paid subscription required]]',
}
local article_postfix = args['article-postfix'] or '';
Line 87 ⟶ 90:
local list_separator = args['list-separator'] or ', ';
local leadout_postfix = args['leadout-postfix'] or ' ';
local access_index;
local url_access = lock_icons[mw.text.trim(args['url-access'] or '')] or '';
local list_leadout;
 
if is_set (args['list-leadout']) then
list_leadout = table.concat ({
Line 100 ⟶ 103:
end
articlelabel = make_wikilinkmake_label (args['article-link'], args['article-name'], article_postfix);
if is_set (article) then
article = table.concat ({article, article_postfix, '&nbsp;'});
elseif is_set (article_postfix) then
article = article_postfix
end
for k, item in ipairs (args) do -- for each of the positional parameters
item = mw.text.trim (item); -- remove extraneous whitespace
Line 122 ⟶ 120:
});
access_index = table.concat ({'url-access', k}); -- make an enumerated index
if is_set (url_access) then
local access_icon;
item = table.concat ({
if is_set (args[access_index]) then -- if set
access_icon = lock_icons[args[access_index]]
end
if not access_icon then -- if lock_icons[access_icon]not set
local url_access access_icon = lock_icons[mw.text.trim(args['url-access'] or '')] -- oruse '';default
end
if access_icon then
item = table.concat ({ -- add access icon markup to this item
'<span class="plainlinks">', -- this link is plain
item,
'<span style="padding-left:0.15em;">', -- and replaced with
access_icon, -- the appropriate icon
url_access,
'</span>', -- and close the spans
'</span>'
});
end
else
item = table.concat ({ -- create an unlinked item
Line 142 ⟶ 150:
if is_set (args['list-leadout']) then
out_text = table.concat ({articlelabel, mw.text.listToText (result, list_separator, list_leadout)});
else
out_text = table.concat ({articlelabel, table.concat (result, list_separator)});
end
 
end if --is_set (url_accessargs[1]) then
out_text = mw.html.create('span')
:addClass('plainlinks')
:wikitext(out_text)
end
end
return out_text