---  
For functions related to Internet Archive  
Notes:  
1. Internet Archive runs Elasticsearch search engine as of 4 Nov 2015  
2. Program flowchart:  
Break name down into number of words
Build a base URL based on number of words (1,2,3,4,5+), use of sopt=t switch, and availability of birth-death dates
If any words contain extended-ascii characters
append extra code for wildcards based on sopt=t or w
return finished URL  
3. URL length should not exceed 2000 characters or it will break certain popular browsers  
4. Wildcard (*) replacements should be avoided in the first letter of the first word, and with any single-letter words  
5. Changing search formulations will have impacts on existing uses of the template and off-line tools which are optimized for these search recipes.  
local p = {}  
---  
For Template:Internet Archive author  
function p.author  
local pframe = :getParent
local args = pframe.args  
local tname = "Internet Archive author" -- name of calling template. Change if template rename.  
local name = nil -- article name (default: current page name)
dname = nil -- display name (default: current page name)
local sname = nil -- search name (default: current page name)
local sopt = nil -- search options (default: nil)
byabout = "ஆக்கங்கள்"
tagline = "இணைய ஆவணகத்தில்"
urlhead = "//archive.org/search.php?query="
mydate = "" -- birth-death date  
--- Determine name
name = trimArg(args.name) -- When using template outside main article space, the 'name' parameter is required (not optional)
if not name then
name = mw.title.getCurrentTitle.text
end
dname = mw.ustring.gsub(name,'%s+%([^%(]-%)$', '') -- Remove the final disambig parentheses
sname = dname
if trimArg(args.sname) then
sname = trimArg(args.sname)
end
if trimArg(args.dname) then
dname = trimArg(args.dname)
end  
--- Determine search option
sopt = trimArg(args.sopt)
if sopt then
sopt = mw.ustring.lower(sopt)
if sopt == "tight" then sopt = "t" end
if sopt == "tightx" then sopt = "tx" end
if sopt == "wild" then sopt = "w" end
if sopt ~= "t" and sopt ~= "tx" and sopt ~= "w" then sopt = "unknown" end
end  
--- Determine tagline
if trimArg(args.coda) then
tagline = tagline .. " " .. trimArg(args.coda)
end  
--- Custom search. Do early to avoid unnecessary processing.
if trimArg(args.search) then
local search = p.ia_url_encode(trimArg(args.search))
return "[" .. urlhead .. search .. " " .. byabout .. " " .. dname .. "] " .. tagline
end  
-- Determine media string
media = p.mediaTypes(args.media)
if media == "" then
mediaopen = "%28" -- added a default mediatype Dec 2015 see p.mediaTypes
else
mediaopen = "%28"
end  
-- Determine date of birth and death
local temp = mw.text.split(p.bdDate(args.birth, args.death, name), " ")
local birth = temp[1]
local death = temp[2]
if birth == "Error" or death == "Error" then
return "Error in :Template:"..tname..": " ..name.. " doesn't exist."
end  
--- Split sname into words and count words
local N = mw.text.split(sname, " ")
local l, count = mw.ustring.gsub(sname, "%S+", "")
if count == 0 then
return "Error in :Template:"..tname..": Zero-word name."
end  
--- Date string
if birth ~= "" and death ~= "" then
if p.ia_extendedascii(N[count]) == 1 then
mydate = "%20OR%20%28%22"..birth.."-"..death.."%22%20AND%20%28%22"..p.urlX(N[count]).."%22%20OR%20"..p.urlX(p.ia_deaccent(N[count])).."%29%29"
else
mydate = "%20OR%20%28%22"..birth.."-"..death.."%22%20AND%20"..p.urlX(N[count]).."%29"
end
end  
--- wild string
wild = "%29"
if sopt == "w" and p.ia_extendedascii(sname) == 1 then
if p.wildcheck(N, count) == 1 then
myurl = p.wildfix(N, count)
return p.IArender
end
if count < 3 or count > 3 then
-- (first last)
wild = "%20OR%20%28" .. p.ia_url_encode(p.ia_extendedascii2wildcard(sname)) .. "%29%29"
end
if count == 3 then
-- (first last)
wild = "%20OR%20%28" .. p.ia_url_encode(p.ia_extendedascii2wildcard(N[1])) .. "%20" .. p.ia_url_encode(p.ia_extendedascii2wildcard(N[3])) .. "%29%29"
end
end  
---  
Format URL  
if count == 1 then  
myurl = p.oneWord(sname)  
if sopt == "t" and p.ia_extendedascii(sname) == 1 then
local plainname = p.ia_deaccent(sname)
local A1 = "%20OR%20%22"..p.urlX(plainname)
myurl = myurl .. A1 .. "%22"
return p.IArender
end  
return p.IArender  
end  
if count == 2 then  
myurl = p.twoWords(N, sopt)  
if sopt == "t" and p.ia_extendedascii(sname) == 1 then
local plainname = p.ia_deaccent(sname)
local PN = mw.text.split(plainname, " ")
-- Last, First
local A1 = "%20OR%20%22"..p.urlX(PN[2]).."%2C%20"..p.urlX(PN[1])
-- First Last
local A2 = "%22%20OR%20%22"..p.urlX(PN[1]).."%20"..p.urlX(PN[2])
myurl = myurl .. A1 .. A2 .. "%22"
return p.IArender
end  
return p.IArender  
end  
if count == 3 then  
myurl = p.threeWords(N, sopt)  
if sopt == "t" and p.ia_extendedascii(sname) == 1 then
local plainname = p.ia_deaccent(sname)
local PN = mw.text.split(plainname, " ")
local FIRST = p.urlX(PN[1])
local MIDDLE = p.urlX(PN[2])
local LAST = p.urlX(PN[3])
local firstinitialp = p.urlX( p.firstLetter(PN[1]) )
local middleinitialp = p.urlX( p.firstLetter(PN[2]) )
-- First Middle Last
local A1 = "%20OR%20%22"..FIRST.."%20"..MIDDLE.."%20"..LAST
-- Last, First Middle
local A2 = "%22%20OR%20%22"..LAST.."%2C%20"..FIRST.."%20"..MIDDLE
-- Last, First M.
local A3 = "%22%20OR%20%22"..LAST.."%2C%20"..FIRST.."%20"..middleinitialp.."%2E"
-- Last, F. M.
local A4 = "%22%20OR%20%22"..LAST.."%2C%20"..firstinitialp..".%20"..middleinitialp.."%2E"
local ALL = A1 .. A2 .. A3 .. A4 .. "%22"
myurl = myurl .. ALL
return p.IArender
end  
return p.IArender  
end  
if count == 4 then  
myurl = p.fourWords(N, sopt)  
if sopt == "t" and p.ia_extendedascii(sname) == 1 then
local plainname = p.ia_deaccent(sname)
local PN = mw.text.split(plainname, " ")
local FIRST = p.urlX(PN[1])
local SECOND = p.urlX(PN[2])
local THIRD = p.urlX(PN[3])
local LAST = p.urlX(PN[4])
local firstinitialp = p.urlX( p.firstLetter(PN[1]) )
local secondinitialp = p.urlX( p.firstLetter(PN[2]) )
local thirdinitialp = p.urlX( p.firstLetter(PN[3]) )
-- Last, First Second Third
local A1 = "%20OR%20%22"..LAST.."%2C%20"..FIRST.."%20"..SECOND.."%20"..THIRD
-- First Second Third Last
local A2 = "%22%20OR%20%22"..FIRST.."%20"..SECOND.."%20"..THIRD.."%20"..LAST
-- Last, F. S. T.
local A3 = "%22%20OR%20%22"..LAST.."%2C%20"..firstinitialp.."%2E%20"..secondinitialp.."%2E%20"..thirdinitialp.."%2E"
local ALL = A1 .. A2 .. A3 .. "%22"
myurl = myurl .. ALL
return p.IArender
end  
return p.IArender  
end  
if count > 4 then  
myurl = ""  
if sopt == "w" and p.ia_extendedascii(sname) == 1 then
myurl = "%28"
end  
myurl = myurl .. "%28" .. p.ia_url_encode(sname)  
if sopt == "w" and p.ia_extendedascii(sname) == 1 then
myurl = myurl .. "%29"
end  
if sopt == "t" and p.ia_extendedascii(sname) == 1 then
local plainname = p.ia_deaccent(sname)
local A1 = "%29%20OR%20%28"..p.ia_url_encode(plainname)
myurl = myurl .. A1
return p.IArender
end  
return p.IArender  
end  
return "Unknown error (1). Please check documentation for Template:"..tname..""  
end  
-- Build final output and render
function p.IArender  
return "[" .. urlhead .. mediaopen .. myurl .. wild .. mydate .. media .. " " .. byabout .. " " .. dname .. "] " .. tagline  
end  
function p.oneWord(sname)  
local nameurl = p.ia_url_encode(sname)
local A1 = "%28subject%3A%22"..nameurl
local A2 = "%22%20OR%20creator%3A%22"..nameurl
local A3 = "%22%20OR%20description%3A%22"..nameurl
local A4 = "%22%20OR%20title%3A%22"..nameurl
return A1 .. A2 .. A3 .. A4 .. "%22"
end  
function p.twoWords(N, sopt)
local FIRST = p.urlX(N[1])
local LAST = p.urlX(N[2])
local firstinitial = p.urlX( p.firstLetter(N[1]) )  
-- Last, First
local S1 = "%28subject%3A%22"..LAST.."%2C%20"..FIRST
-- First Last
local S2 = "%22%20OR%20subject%3A%22"..FIRST.."%20"..LAST
local SALL = S1..S2
-- Last, First
local C1 = "%22%20OR%20creator%3A%22"..LAST.."%2C%20"..FIRST
-- First Last
local C2 = "%22%20OR%20creator%3A%22"..FIRST.."%20"..LAST
local CALL = C1..C2
-- First Last