-- This module implements
local p =
local searchProfiles =
local function escapeTemplate(s) s = s:gsub('[{}|=]', function(match) return mw.text.nowiki(match) end) return send
local function parseNamespaceList(ns) -- s can be a search profile, a comma-separated list of namespaces, or a -- Lua array. -- Items in the list can be any valid key to mw.site.namespaces. -- We return either a profile string or a table of namespace numbers.
-- Check for no input or search profile strings. local default = 'default' if not ns then return default elseif searchProfiles[ns] then return ns end -- Parse the string for valid namespaces local ret = local keys if type(ns)
'string' and key:lower
-- Check that we were passed at least one namespace, and return the table. if #ret < 1 then return default else return ret endend
local function makeLink(searchString, display, ns) -- Normalise the input. if not searchString then -- Show the correct syntax if we are not passed a search string. return '' ..
escapeTemplate("{{search link|''search string''|''link text''}}") ..
'
' end display = display or searchString ns = parseNamespaceList(ns)
-- Build the query table local query = if searchProfiles[ns] then query.profile = ns else query.profile = 'advanced' for _, nsid in ipairs(ns) do query['ns' .. tostring(nsid)] = '1' end end -- Make the URL. local url = mw.uri.fullUrl('Special:Search', query) url = tostring(url) -- Add the span tags and display value. return string.format('
[%s %s]', url, display )endlocal function makeNamespaceWarningBanner(title) if title.namespace
function p._main(searchString, display, ns, title) title = title or mw.title.getCurrentTitle return makeLink(searchString, display, ns) .. makeNamespaceWarningBanner(title)end
function p.main(frame) local args = require('Module:Arguments').getArgs(frame,) local searchString = args[1] local display = args[2] local ns = args.ns return p._main(searchString, display, ns)end
return p