Modul:Vyhledávací šablony
Dokumentaci tohoto modulu lze vytvořit na stránce Nápověda:Modul:Vyhledávací šablony
p = {}
function p.Wikisource(frame)
-- Handle Wikisource.
-- Search each argument in quotes, regardless whether it is passed with quotes.
-- The language has to be passed as 1st param.
local languageCode, pageName, search, searchTerms, expressions, url, out
if frame:getParent().args[1] and frame:getParent().args[1] ~= "" then
languageCode = frame:getParent().args[1]
else
return "Wikizdroje: První parametr s kódem jazyka je povinný."
end
if frame:getParent().args[2] and frame:getParent().args[2] ~= "" then
pageName = frame:getParent().args[2]
else
local title = mw.title.getCurrentTitle()
pageName = title.text
end
local numOfArgs = 0
for p in pairs(frame:getParent().args) do
numOfArgs = numOfArgs + 1
end
search = ""
searchTerms = ""
if numOfArgs > 2 then
n = 2
while n <= numOfArgs do
if n > 2 then
search = search .. "+OR+"
searchTerms = searchTerms .. ", "
end
argN = frame:getParent().args[n]
argNQuoteless = mw.ustring.gsub(argN, "\"", "")
argNQuoted = "\"" .. argNQuoteless .. "\""
search = search .. mw.uri.encode(argNQuoted, "QUERY" )
searchTerms = searchTerms .. argNQuoted
n = n + 1
end
else
impliedArg = pageName
impliedArgQuoteless = mw.ustring.gsub(impliedArg, "\"", "")
impliedArgQuoted = "\"" .. impliedArgQuoteless .. "\""
search = mw.uri.encode(impliedArgQuoted, "QUERY")
searchTerms = impliedArgQuoted
end
if numOfArgs > 2 then
expressions = "výrazů"
else
expressions = "výrazu"
end
url = "https://" .. languageCode .. ".wikisource.org/w/index.php?search=" .. search .. "&title=Special:Search&profile=advanced&fulltext=1&ns0=1"
out = "Wikizdroje. Vyhledávání " .. expressions .. " [" .. url .. " " .. searchTerms .. "]."
return out
end
local langCodeToCzechLabel = {}
langCodeToCzechLabel["cs"] = "češtinu"
langCodeToCzechLabel["da"] = "dánštinu"
langCodeToCzechLabel["de"] = "němčinu"
langCodeToCzechLabel["en"] = "angličtinu"
langCodeToCzechLabel["pl"] = "polštinu"
langCodeToCzechLabel["sk"] = "slovenštinu"
langCodeToCzechLabel["ru"] = "ruštinu"
langCodeToCzechLabel["sv"] = "švédštinu"
langCodeToCzechLabel["ar"] = "arabštinu"
langCodeToCzechLabel["fr"] = "francouzštinu"
langCodeToCzechLabel["he"] = "hebrejštinu"
function p.GBK(frame)
-- Handle Google Books.
-- Search each argument in quotes, regardless whether it is passed with quotes.
-- The language has to be passed as 1st param.
local languageCode, pageName, search, searchTerms, expressions, url, out
if frame:getParent().args[1] and frame:getParent().args[1] ~= "" then
languageCode = frame:getParent().args[1]
else
return "Google Books: První parametr s kódem jazyka je povinný."
end
if frame:getParent().args[2] and frame:getParent().args[2] ~= "" then
pageName = frame:getParent().args[2]
else
local title = mw.title.getCurrentTitle()
pageName = title.text
end
local numOfArgs = 0
for p in pairs(frame:getParent().args) do
numOfArgs = numOfArgs + 1
end
search = ""
searchTerms = ""
if numOfArgs > 2 then
n = 2
while n <= numOfArgs do
if n > 2 then
search = search .. "+OR+"
searchTerms = searchTerms .. ", "
end
argN = frame:getParent().args[n]
argNQuoteless = mw.ustring.gsub(argN, "\"", "")
argNQuoted = "\"" .. argNQuoteless .. "\""
search = search .. mw.uri.encode(argNQuoted, "QUERY" )
searchTerms = searchTerms .. argNQuoted
n = n + 1
end
else
impliedArg = pageName
impliedArgQuoteless = mw.ustring.gsub(impliedArg, "\"", "")
impliedArgQuoted = "\"" .. impliedArgQuoteless .. "\""
search = mw.uri.encode(impliedArgQuoted, "QUERY")
searchTerms = impliedArgQuoted
end
if numOfArgs > 2 then
expressions = "výrazů"
else
expressions = "výrazu"
end
langCzechLabelAccusative = langCodeToCzechLabel[languageCode]
if langCzechLabelAccusative == nil then
langCzechLabelAccusative = "jazyk s kódem " .. languageCode
end
url = "https://www.google.com/search?tbm=bks&nfpr=1&q=" .. search .. "&lr=lang_" .. languageCode
out = "Google Books. Vyhledávání " .. expressions .. " [" .. url .. " " .. searchTerms .. "] pro " .. langCzechLabelAccusative .. "."
return out
end
return p