Module:Catalog lookup link/sandbox: Difference between revisions

Content deleted Content added
tweak output
tweak output
Line 32:
 
local function is_set( var )
return not (var == nil orand mw.ustring.match(var == ,'%S')) and true or false;
end
 
Line 67:
function p.main (frame)
local args = getArgs (frame);
if is_set (articleargs[1]) then
local result = {};
 
local article;
 
local article_postfix = args['article-postfix'] or ' ';
local link_prefixarticle_postfix = args['linkarticle-prefixpostfix'] or '';
local link_postfixlink_prefix = args['link-postfixprefix'] or '';
local item_prefixlink_postfix = args['itemlink-prefixpostfix'] or '';
local item_postfixitem_prefix = args['item-postfixprefix'] or '';
local list_separatoritem_postfix = args['listitem-separatorpostfix'] or ', ';
local leadout_postfixlist_separator = args['leadoutlist-postfixseparator'] or ', ';
local article_postfixleadout_postfix = args['articleleadout-postfix'] or '  ';
local list_leadout;
 
if is_set (args['list-leadout']) then
list_leadout = table.concat ({
mw.ustring.match(mw.ustring.sub(args['list-leadout'],1,1), '[%a]') and ' ' or '',
mw.ustring.match(mw.ustring.sub(args['list-leadout'],1,1), '[%a]') and ' ' or '',
if is_set ( args['list-leadout']) then,
leadout_postfix,
});
else
list_leadout = '';
end
 
if args['article-link'] or args['article-name'] then end
article = make_wikilink (args['article-link'], args['article-name']);
if is_set (article) then
article = table.concat ({article, article_postfix});
end
 
if args['article-link'] or args['article-name'] then end
for k, item in ipairs (args) do -- for each of the positional parameters
article = make_wikilink (args['article-link'], args['article-name']);
item = mw.text.trim (item); -- remove extraneous whitespace
if is_set (link_prefixarticle) then -- if there is link prefix...
itemarticle = table.concat ({ --article, createarticle_postfix, an external link item' '});
elseif is_set (article_postfix) then
'[', -- open ext link markup
article = table.concat ({article, article_postfix});
link_prefix, -- url prefix
end
mw.uri.encode (item), -- item is part of url
link_postfix, -- url postfix
'for 'k, item in ipairs (args) do -- requiredfor spaceeach betweenof urlthe andpositional labelparameters
item_prefix, item = mw.text.trim (item); -- labelremove extraneous prefixwhitespace
item, if is_set (link_prefix) then -- itemif there is aslink labelprefix...
item_postfix, item = table.concat ({ -- itemcreate postfixan external link item
'][' , -- closeopen ext link markup
link_prefix, -- url prefix
});
mw.uri.encode (item), -- item is part of url
link_postfix, -- url postfix
item ' ', -- itemrequired space between url asand label
item_prefix, -- label prefix
item_postfix item, -- item postfixas label
item_postfix, -- item postfix
'[]', -- openclose ext link markup
});
});else
item = table.concat ({ -- create an unlinked item
item_prefix, -- label prefix
item, -- item as label
item_postfix, -- item postfix
});
end
table.insert (result, item); -- add the item to the result list
end
if is_set (args['list-leadout']) then
return table.concat ({article, mw.text.listToText (result, list_separator, list_leadout)});
else
item =return table.concat ({ --article, createtable.concat an unlinked(result, itemlist_separator)});
item_prefix, -- label prefix
item, -- item as label
item_postfix, -- item postfix
});
end
 
table.insert (result, item); -- add the item to the result list
end
 
if is_set (args['list-leadout']) then
return table.concat ({article, mw.text.listToText (result, list_separator, list_leadout)});
else
return ''
return table.concat ({article, table.concat (result, list_separator)});
end
end