Module:Find sources/sandbox: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 39:
return table.concat(searchStrings, separator)
end
 
local function extractTerms(args, title)
-- 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,
Line 90 ⟶ 67:
 
return string.format('[%s %s]', url, display or linkCfg.display)
end
function p.onelink(frame)
local linkcode = frame.args[1]
local searchTerms = extractTerms(frame:getParent().args, mw.title.getCurrentTitle())
local display = frame.args.display
if display == "intro" then
display = renderSearchString(
searchTerms,
' '
)
end
return p._renderLink(linkcode, searchTerms, display)
end
 
Line 136 ⟶ 101:
 
-- 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. 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[i2] = sdab
else
searchTerms[21] = dabtitle.subpageText
end
end
searchTerms[1] = '"' .. searchTerms[1] .. '"'
 
-- Make the intro link