Module:Find sources/sandbox: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
 
(29 intermediate revisions by 5 users not shown)
Line 5:
local ROOT_PAGE = 'Module:Find sources'
local TEMPLATE_ROOT = ROOT_PAGE .. '/templates/' -- for template config modules
local LINK_ROOTLINK_CONFIG = ROOT_PAGE .. '/links/sandbox' -- for link config modules
local CONFIG_PAGE = ROOT_PAGE .. '/config' -- for global config
 
Line 39:
return table.concat(searchStrings, separator)
end
 
local function extractTerms(args, title)
function p._renderLink(code, searchTerms, display, tooltip)
-- Get the search terms from the arguments.
local searchTerms = {}
for i, s in ipairs(args) do
searchTerms[i] = s
end
if not searchTerms[1] then
-- Use the current subpage name as the default search term. If the page
-- uses a disambiguator like "Foo (bar)", make "Foo" the first term and
-- "bar" the second.
local term, dab = title.subpageText:match('^(.*) (%b())$')
if dab then
dab = dab:sub(2, -2) -- Remove parens
end
if term and dab then
searchTerms[1] = term
searchTerms[2] = dab
else
searchTerms[1] = title.subpageText
end
end
searchTerms[1] = '"' .. searchTerms[1] .. '"'
return searchTerms
end
function p._renderLink(code, searchTerms, display)
-- Renders the external link wikicode for one link, given the link code,
-- a table of search terms, and an optional display value and tooltip.
 
-- Get link config.
local linkCfglinks = maybeLoadData(LINK_ROOT .. codeLINK_CONFIG)
local linkCfg = links[code]
if not linkCfg then
error(string.format(
"invalid link code '%s'; no link config found at [[%s]]",
code,
LINK_CONFIG
LINK_ROOT .. code
))
end
Line 88 ⟶ 66:
url = substituteParams(linkCfg.url, searchString)
end
 
if tooltip then
return string.format('[%s %s]', url, display or linkCfg.display)
return string.format('<span title="%s" style="border-bottom: 1px dotted;">[%s %s]</span>',
end
mw.text.encode(tooltip), url, display or linkCfg.display)
function p.onelink(frame)
else
local linkcode = frame.args[1]
return string.format('[%s %s]', url, display or linkCfg.display)
local searchTerms = extractTerms(frame.args, frame.title)
local display = frame.args.display
if display == "intro" then
display = renderSearchString(
searchTerms,
'&nbsp;'
)
end
return p._renderLink(code, searchTerms, display)
end
 
Line 112 ⟶ 83:
 
-- Get the template config.
local templateCfgPage = TEMPLATE_ROOT .. template .. '/sandbox'
local templateCfg = maybeLoadData(templateCfgPage)
if not templateCfg then
Line 136 ⟶ 107:
 
-- Get the search terms from the arguments.
local searchTerms = extractTerms(args, title){}
for i, s in ipairs(args) do
local searchTerms[i] = {}s
end
if not searchTerms[1] then
-- Use the current subpage name as the default search term., Ifunless the page
-- another title is provided. If the page uses a disambiguator like
-- uses a disambiguator like "Foo (bar)", make "Foo" the first term and "bar" the second.
searchTerms[1]local searchTitle = args.title or title.subpageText
local term, dab = title.subpageTextsearchTitle:match('^(.*) (%b())$')
if dab then
dab = dab:sub(2, -2) -- Remove parens
end
if term and dab then
searchTerms[1] = term
searchTerms[i2] = sdab
else
searchTerms[21] = dabsearchTitle
end
end
searchTerms[1] = '"' .. searchTerms[1] .. '"'
 
-- Make the intro link
Line 146 ⟶ 137:
'&nbsp;'
)
local tooltip = templateCfg.introLink.tooltip
introLink = p._renderLink(code, searchTerms, display)
return introLink = p._renderLink(code, searchTerms, display, tooltip)
else
introLink = ''
Line 156 ⟶ 148:
local sep = ''
for i, t in ipairs(templateCfg.links) do
links[i] = sep .. p._renderLink(t.code, searchTerms, t.display, t.tooltip) ..
(t.afterDisplay or '')
sep = t.separator or separator