Module:Find sources: Difference between revisions

m
Changed protection settings for "Module:Find sources": re-raise, 1.5million transclusions and no edits from the EXCON editor ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite))
(Support custom title param per edit request)
 
imported>Primefac
m (Changed protection settings for "Module:Find sources": re-raise, 1.5million transclusions and no edits from the EXCON editor ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite)))
 
(5 intermediate revisions by 3 users not shown)
Line 5: Line 5:
local ROOT_PAGE = 'Module:Find sources'
local ROOT_PAGE = 'Module:Find sources'
local TEMPLATE_ROOT = ROOT_PAGE .. '/templates/' -- for template config modules
local TEMPLATE_ROOT = ROOT_PAGE .. '/templates/' -- for template config modules
local LINK_ROOT = ROOT_PAGE .. '/links/' -- for link config modules
local LINK_CONFIG = ROOT_PAGE .. '/links' -- for link config modules
local CONFIG_PAGE = ROOT_PAGE .. '/config' -- for global config
local CONFIG_PAGE = ROOT_PAGE .. '/config' -- for global config


Line 40: Line 40:
end
end


function p._renderLink(code, searchTerms, display)
function p._renderLink(code, searchTerms, display, tooltip)
-- Renders the external link wikicode for one link, given the link code,
-- Renders the external link wikicode for one link, given the link code,
-- a table of search terms, and an optional display value.
-- a table of search terms, and an optional display value and tooltip.


-- Get link config.
-- Get link config.
local linkCfg = maybeLoadData(LINK_ROOT .. code)
local links = maybeLoadData(LINK_CONFIG)
local linkCfg = links[code]
if not linkCfg then
if not linkCfg then
error(string.format(
error(string.format(
"invalid link code '%s'; no link config found at [[%s]]",
"invalid link code '%s'; no link config found at [[%s]]",
code,
code,
LINK_ROOT .. code
LINK_CONFIG
))
))
end
end
Line 65: Line 66:
url = substituteParams(linkCfg.url, searchString)
url = substituteParams(linkCfg.url, searchString)
end
end
 
return string.format('[%s %s]', url, display or linkCfg.display)
if tooltip then
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
end


Line 131: Line 137:
'&nbsp;'
'&nbsp;'
)
)
introLink = p._renderLink(code, searchTerms, display)
local tooltip = templateCfg.introLink.tooltip
introLink = p._renderLink(code, searchTerms, display, tooltip)
else
else
introLink = ''
introLink = ''
Line 141: Line 148:
local sep = ''
local sep = ''
for i, t in ipairs(templateCfg.links) do
for i, t in ipairs(templateCfg.links) do
links[i] = sep .. p._renderLink(t.code, searchTerms, t.display) ..
links[i] = sep .. p._renderLink(t.code, searchTerms, t.display, t.tooltip) ..
(t.afterDisplay or '')
(t.afterDisplay or '')
sep = t.separator or separator
sep = t.separator or separator
Anonymous user