Module:Find sources/sandbox: Difference between revisions

Content deleted Content added
undo test
No edit summary
 
(39 intermediate revisions by 7 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 40:
end
 
function p._renderLink(code, searchTerms, display, tooltip)
-- 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 66 ⟶ 67:
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>',
mw.text.encode(tooltip), url, display or linkCfg.display)
else
return string.format('[%s %s]', url, display or linkCfg.display)
end
end
 
Line 77 ⟶ 83:
 
-- Get the template config.
local templateCfgPage = TEMPLATE_ROOT .. template .. '/sandbox'
local templateCfg = maybeLoadData(templateCfgPage)
if not templateCfg then
Line 106 ⟶ 112:
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
-- "Foo (bar)", make "Foo" the first term and "bar" the second.
local term, dabsearchTitle = args.title or title.subpageText:match('^(.*) (%b())$')
local term, dab = searchTitle:match('^(.*) (%b())$')
if dab then
dab = dab:sub(2, -2) -- Remove parens
Line 117 ⟶ 124:
searchTerms[2] = dab
else
searchTerms[1] = title.subpageTextsearchTitle
end
end
Line 130 ⟶ 137:
'&nbsp;'
)
local tooltip = templateCfg.introLink.tooltip
introLink = p._renderLink(code, searchTerms, display, tooltip)
else
introLink = ''
Line 137 ⟶ 145:
-- Make the other links
local links = {}
local separator = templateCfg.separator or cfg['default-separator']
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
end
links = table.concat(links, separator)
local separator = templateCfg.separator or cfg['default-separator']
links = table.concat(links, separator)
 
-- Make the blurb.
Line 159 ⟶ 170:
-- Invocations will look like {{#invoke:Find sources|template name}},
-- where "template name" is a subpage of [[Module:Find sources/templates]].
local tname = template
if tname:sub(-8) == '/sandbox' then
-- This makes {{Find sources/sandbox|Albert Einstein}} work.
tname = tname:sub(1, -9)
end
return function(frame)
title, n = mw.ustring.gsub(frame:getTitle(), mw.site.namespaces[828].name, mw.site.namespaces[10].name)
local args = require('Module:Arguments').getArgs(frame, {
wrappers = {mw.site.namespaces[10].name .. ':' .. template, title}tname
})
return t._main(template, args)