Module:Catalog lookup link: Difference between revisions

Content deleted Content added
m documentation;
+templatestyles
 
(17 intermediate revisions by 5 users not shown)
Line 5:
|article-name=: Optional alternative text to be displayed for |article-link= link in front of catalog link.
If not specified, |article-link= is used for display as well. If both parameters are not specified, the prefix is omitted completely.
|article-postfixsuffix=: Optional symbol to be displayed after article name or link (f.e. ":"; omitted, if not defined).
|link-prefix=: Optional prefix portion of url to external catalog item(s).
|link-postfixsuffix=: Optional postfixsuffix portion of url to external catalog item(s).
|item-prefix=: Optional text displayed in front of each external link (omitted, if not defined)
|item-postfixsuffix=: Optional text displayed immediately after each external link (omitted, if not defined)
|list-separator=: Optional alternative separator displayed between list items (default: ", ", if not specified). Whitespace must be encoded.
|list-leadout=: Optional alternative leadout text displayed between the last two list items (f.e. "and", "or", "as well as", etc., default is the |list-separator= or ", ".)
|leadout-postfixsuffix=: Optional alternative postfixsuffix text of the leadout (see |list-leadout=) displayed between the last two list items.
This gets added in front of the last list item instead of the default whitespace which is added without this parameter.
This may be necessary if |list-separator= is used not only to define the list separator but also parts of the item prefix
Line 19:
 
new parameters that support access icons:
|allowed_icons= – comma-separated list of keywords: free, limited, registration, subscription, none, all (default; same'all' asimplied when this parameter empty or omitted)
the icons specified in the following parameters are checked agains the list in |allowed-icons=; not in the list? not displayed
|url-access-all= – applies specified icon to all items in the list; accepted keywords: free, limited, registration, subscription;
Line 26:
]]
 
require('Module:No globalsstrict');
local getArgs = require ('Module:Arguments').getArgs;
local lock_icons = { --icon classes are defined in Module:Citation/CS1/styles.css
['free'] = {'[[File:Lockid-green.svg|9px|link=|alt=Freelylock-free', accessible|'Freely accessible]]'},
['registration'] = {'[[File:Lockid-bluelock-alt-2.svg|9px|link=|alt=Free registration', required|'Free registration required]]'},
['limited'] = {'[[File:Lockid-bluelock-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:Lockid-redlock-alt.svg|9px|link=|alt=Paid subscription', required|'Paid subscription required]]'},
}
 
local p = {};
 
 
Line 53 ⟶ 51:
Makes a wikilinked or plain text label from arguments; when both link and display text is provided, makes a
wikilink in the form [[L|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 postfixsuffix, returns an empty string else.
 
]=]
 
local function make_label (link, display, postfixsuffix)
local label = '';
if is_set (link) then
Line 69 ⟶ 67:
end
 
if is_set (label) or is_set (postfix) then -- label can be empty string here
return table.concat ({label, postfixsuffix, ' '}); -- assemble the complete label
else
return ''suffix; -- no inputsspace soafter returnsuffix emptyif string forno concatenationlabel
end
end
Line 86 ⟶ 84:
<comma-separated list of allowed icons> may be any of the keywords: free, limited, registration, subscription, none, all
 
keyword 'all' is default condition; same'all' is implied when |allowed=icons= is empty ofor omitted
 
keyword 'none' for use with identifiers where icons are inappropriate (isbn, issn, oclc)
Line 93 ⟶ 91:
|allow_icons=free for most identifiers;
|allow_icons=none for isbn, issn, oclc, etc
 
|url-access= is alias of |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_icons[args['url-access-all']] then -- if set and valid
Line 105:
elseif is_set (args[param_name]) and lock_icons[args[param_name]] then -- if set and valid
icon = args[param_name]; -- tentatively
 
else
return nil; -- neither |url-access-all= nor |url-accessn= set so return nil
Line 126 ⟶ 127:
]]
 
local function p.main (frame)
local args = getArgs (frame);
local out_text = '';
Line 134 ⟶ 135:
local label;
local article_postfixarticle_suffix = args['article-suffix'] or args['article-postfix'] or '';
local link_prefix = args['link-prefix'] or '';
local link_postfixlink_suffix = args['link-suffix'] or args['link-postfix'] or '';
local item_prefix = args['item-prefix'] or '';
local item_postfixitem_suffix = args['item-suffix'] or args['item-postfix'] or '';
local list_separator = args['list-separator'] or ', ';
local leadout_postfixleadout_suffix = args['leadout-suffix'] or args['leadout-postfix'] or ' ';
local list_leadout;
 
Line 147 ⟶ 148:
if is_set (args['list-leadout']) then
list_leadout = table.concat ({
mw.ustring.match(mw.ustring.subgsub (args['list-leadout'],1,1 '^(%a)', '[ %a]1'), -- andinsert 'leading 'space orif '',first character is a letter
leadout_suffix,
args['list-leadout'],
leadout_postfix,
});
else
Line 155:
end
label = make_label (args['article-link'], args['article-name'], article_postfixarticle_suffix);
 
for k, item in ipairs (args) do -- for each of the positional parameters
Line 164:
link_prefix, -- url prefix
mw.uri.encode (item), -- item is part of url
link_postfixlink_suffix, -- url postfixsuffix
' ', -- required space between url and label
item_prefix, -- label prefix
item, -- item as label
item_postfixitem_suffix, -- item postfixsuffix
']' -- close ext link markup
});
Line 175:
if icon_index then
item = table.concat ({ -- add access icon markup to this item
'<span class="plainlinks">', -- thisopen the opening span tag; icon classes are linkdefined isin plainModule:Citation/CS1/styles.css
lock_icons[icon_index][1], -- add the appropriate lock icon class
'</span>" title="', -- and close the spanstitle attribute
lock_icons[icon_index][2], -- for an appropriate tool tip
'">', -- close the opening span tag
item,
'</span style="padding-left:0.15em;">', -- and replacedclose withthe span
lock_icons[icon_index], -- the appropriate icon
'</span>', -- and close the spans
'</span>'
});
end
Line 187 ⟶ 188:
item_prefix, -- label prefix
item, -- item as label
item_postfixitem_suffix, -- item postfixsuffix
});
end
Line 194 ⟶ 195:
end
out_text = frame:callParserFunction('#tag', {'templatestyles', '', src=table.concat({
'Module:Citation/CS1',
mw.ustring.match(frame:getTitle(), '/sandbox$') or '',
'/styles.css',
})});
if is_set (args['list-leadout']) then
out_text = table.concat ({out_text, label, mw.text.listToText (result, list_separator, list_leadout)});
else
out_text = table.concat ({out_text, label, table.concat (result, list_separator)});
end
 
end --is_set (args[1])
 
return out_text
end
 
return p{main = main};