Module:Lsearch

From Wikipedia

Documentation for this module may be created at Module:Lsearch/doc

local bodge = require "Module:mw"

local z = {}

-- This is used by template {{Lstr_find}}.
function z.lua_searches(frame)
    local pframe = frame:getParent()
    local args = pframe.args -- the arguments passed TO the template, in the wikitext that instantiates the template
    local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
    local pagename = config.pagename or ""
    local namespace = config.namespace or ""
    local title, disambiguator 
    if "true" ~= args.force then -- This is a string, "true", not a boolean.
        title, disambiguator = pagename:match("(.*)(%(.*%))")
        if nil == title then
            local index = 1
            while true do
                local arg = args[index]
                if arg == nil then break end
                title, disambiguator = pagename:match("(.*)(" .. arg .. ")")
                if title ~= nil then break end
                index = index + 1
            end
        end
    end
    if nil == title then title, disambiguator = pagename, "" end
    if "" ~= namespace then namespace = namespace .. ":" end
    return frame:preprocess("{{DISPLAYTITLE:" .. namespace .. "''" .. title .. "''" .. (disambiguator or "") .. "}}")
end

-- This is used by template {{Lstr_find}}.
function z.strfind(frame)
    local pframe = frame:getParent()
    local args = pframe.args -- the arguments passed TO the template, in the wikitext that instantiates the template
    local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
    local p1 = config.p1 or ""
    local p2 = config.p2 or ""
    local p3 = config.p3 or ""
    local p4 = config.p4 or ""
    local p5 = config.p5 or ""
    local p6 = config.p6 or ""
    local p7 = config.p7 or ""
    local p8 = config.p8 or ""
    local p9 = config.p9 or ""
    local p10 = config.p10 or ""
    local p11 = config.p11 or ""
    local p12 = config.p12 or ""
    local p13 = config.p13 or ""
    local p14 = config.p14 or ""
    local p15 = config.p15 or ""
    local p16 = config.p16 or ""
    local p17 = config.p17 or ""
    local p18 = config.p18 or ""
    local p19 = config.p19 or ""
    local p20 = config.p20 or ""
    local p21 = config.p21 or ""
    local p22 = config.p22 or ""
    local p23 = config.p23 or ""
    local p24 = config.p24 or ""
    local p25 = config.p25 or ""
    local p26 = config.p26 or ""
    local p27 = config.p27 or ""
    local p28 = config.p28 or ""
    local p29 = config.p29 or ""
    local p30 = config.p30 or ""
    local p31 = config.p31 or ""
    local p32 = config.p32 or ""
    local p33 = config.p33 or ""
    local p34 = config.p34 or ""
    local p35 = config.p35 or ""
    local p36 = config.p36 or ""
    local p37 = config.p37 or ""
    local p38 = config.p38 or ""
    local p39 = config.p39 or ""
    local p40 = config.p40 or ""
    local p41 = config.p41 or ""
    local p42 = config.p42 or ""
    local p43 = config.p43 or ""
    local p44 = config.p44 or ""
    local p45 = config.p45 or ""
    local p46 = config.p46 or ""
    local p47 = config.p47 or ""
    local p48 = config.p48 or ""
    local p49 = config.p49 or ""
    local p50 = config.p50 or ""
    local p51 = config.p51 or ""
    local p52 = config.p52 or ""
    local p53 = config.p53 or ""
    local p54 = config.p54 or ""
    local p55 = config.p55 or ""
    local p56 = config.p56 or ""
    local p57 = config.p57 or ""
    local p58 = config.p58 or ""
    local p59 = config.p59 or ""
    local p60 = config.p60 or ""
    local p61 = config.p61 or ""
    local p62 = config.p62 or ""
    local p63 = config.p63 or ""
    local p64 = config.p64 or ""
    local p65 = config.p65 or ""
    local p66 = config.p66 or ""
    local p67 = config.p67 or ""
    local p68 = config.p68 or ""
    local p69 = config.p69 or ""
    local p70 = config.p70 or ""
    local p71 = config.p71 or ""
    local p72 = config.p72 or ""
    local p73 = config.p73 or ""
    local p74 = config.p74 or ""
    local p75 = config.p75 or ""
    local p76 = config.p76 or ""
    local p77 = config.p77 or ""
    local p78 = config.p78 or ""
    local p79 = config.p79 or ""
    local p80 = config.p80 or ""
    local p81 = config.p81 or ""
    local p82 = config.p82 or ""
    local p83 = config.p83 or ""
    local p84 = config.p84 or ""
    local p85 = config.p85 or ""
    local p86 = config.p86 or ""
    local p87 = config.p87 or ""
    local p88 = config.p88 or ""
    local p89 = config.p89 or ""
    local p90 = config.p90 or ""
    local p91 = config.p91 or ""

    local debugsw = config.debug or ""
    local loc1, loc2, loc3, loc4, loc5, loc6, loc7, loc8, loc9 = nil
    local loc10,loc11,loc12,loc13,loc14,loc15,loc16,loc17,loc18,loc19 = nil
    local loc20,loc21,loc22,loc23,loc24,loc25,loc26,loc27,loc28,loc29 = nil
    local loc30,loc31,loc32,loc33,loc34,loc35,loc36,loc37,loc38,loc39 = nil
    local loc40,loc41,loc42,loc43,loc44,loc45,loc46,loc47,loc48,loc49 = nil
    local loc50,loc51,loc52,loc53,loc54,loc55,loc56,loc57,loc58,loc59 = nil
    local loc60,loc61,loc62,loc63,loc64,loc65,loc66,loc67,loc68,loc69 = nil
    local loc70,loc71,loc72,loc73,loc74,loc75,loc76,loc77,loc78,loc79 = nil
    local loc80,loc81,loc82,loc83,loc84,loc85,loc86,loc87,loc88,loc89 = nil
    local loc90 = nil

    if (p2 ~= "") then loc1 = string.find (p1, p2) end
    if (p3 ~= "") then loc2 = string.find (p1, p3) end
    if (p4 ~= "") then loc3 = string.find (p1, p4) end
    if (p5 ~= "") then loc4 = string.find (p1, p5) end
    if (p6 ~= "") then loc5 = string.find (p1, p6) end
    if (p7 ~= "") then loc6 = string.find (p1, p7) end
    if (p8 ~= "") then loc7 = string.find (p1, p8) end
    if (p9 ~= "") then loc8 = string.find (p1, p9) end
    if (p10 ~= "") then loc9 = string.find (p1, p10) end
    if (p11 ~= "") then loc10 = string.find (p1, p11) end
    if (p12 ~= "") then loc11 = string.find (p1, p12) end
    if (p13 ~= "") then loc12 = string.find (p1, p13) end
    if (p14 ~= "") then loc13 = string.find (p1, p14) end
    if (p15 ~= "") then loc14 = string.find (p1, p15) end
    if (p16 ~= "") then loc15 = string.find (p1, p16) end
    if (p17 ~= "") then loc16 = string.find (p1, p17) end
    if (p18 ~= "") then loc17 = string.find (p1, p18) end
    if (p19 ~= "") then loc18 = string.find (p1, p19) end
    if (p20 ~= "") then loc19 = string.find (p1, p20) end
    if (p21 ~= "") then loc20 = string.find (p1, p21) end
    if (p22 ~= "") then loc21 = string.find (p1, p22) end
    if (p23 ~= "") then loc22 = string.find (p1, p23) end
    if (p24 ~= "") then loc23 = string.find (p1, p24) end
    if (p25 ~= "") then loc24 = string.find (p1, p25) end
    if (p26 ~= "") then loc25 = string.find (p1, p26) end
    if (p27 ~= "") then loc26 = string.find (p1, p27) end
    if (p28 ~= "") then loc27 = string.find (p1, p28) end
    if (p29 ~= "") then loc28 = string.find (p1, p29) end
    if (p30 ~= "") then loc29 = string.find (p1, p30) end
    if (p31 ~= "") then loc30 = string.find (p1, p31) end
    if (p32 ~= "") then loc31 = string.find (p1, p32) end
    if (p33 ~= "") then loc32 = string.find (p1, p33) end
    if (p34 ~= "") then loc33 = string.find (p1, p34) end
    if (p35 ~= "") then loc34 = string.find (p1, p35) end
    if (p36 ~= "") then loc35 = string.find (p1, p36) end
    if (p37 ~= "") then loc36 = string.find (p1, p37) end
    if (p38 ~= "") then loc37 = string.find (p1, p38) end
    if (p39 ~= "") then loc38 = string.find (p1, p39) end
    if (p40 ~= "") then loc39 = string.find (p1, p40) end
    if (p41 ~= "") then loc40 = string.find (p1, p41) end
    if (p42 ~= "") then loc41 = string.find (p1, p42) end
    if (p43 ~= "") then loc42 = string.find (p1, p43) end
    if (p44 ~= "") then loc43 = string.find (p1, p44) end
    if (p45 ~= "") then loc44 = string.find (p1, p45) end
    if (p46 ~= "") then loc45 = string.find (p1, p46) end
    if (p47 ~= "") then loc46 = string.find (p1, p47) end
    if (p48 ~= "") then loc47 = string.find (p1, p48) end
    if (p49 ~= "") then loc48 = string.find (p1, p49) end
    if (p50 ~= "") then loc49 = string.find (p1, p50) end
    if (p51 ~= "") then loc50 = string.find (p1, p51) end
    if (p52 ~= "") then loc51 = string.find (p1, p52) end
    if (p53 ~= "") then loc52 = string.find (p1, p53) end
    if (p54 ~= "") then loc53 = string.find (p1, p54) end
    if (p55 ~= "") then loc54 = string.find (p1, p55) end
    if (p56 ~= "") then loc55 = string.find (p1, p56) end
    if (p57 ~= "") then loc56 = string.find (p1, p57) end
    if (p58 ~= "") then loc57 = string.find (p1, p58) end
    if (p59 ~= "") then loc58 = string.find (p1, p59) end
    if (p60 ~= "") then loc59 = string.find (p1, p60) end
    if (p61 ~= "") then loc60 = string.find (p1, p61) end
    if (p62 ~= "") then loc61 = string.find (p1, p62) end
    if (p63 ~= "") then loc62 = string.find (p1, p63) end
    if (p64 ~= "") then loc63 = string.find (p1, p64) end
    if (p65 ~= "") then loc64 = string.find (p1, p65) end
    if (p66 ~= "") then loc65 = string.find (p1, p66) end
    if (p67 ~= "") then loc66 = string.find (p1, p67) end
    if (p68 ~= "") then loc67 = string.find (p1, p68) end
    if (p69 ~= "") then loc68 = string.find (p1, p69) end
    if (p70 ~= "") then loc69 = string.find (p1, p70) end
    if (p71 ~= "") then loc70 = string.find (p1, p71) end
    if (p72 ~= "") then loc71 = string.find (p1, p72) end
    if (p73 ~= "") then loc72 = string.find (p1, p73) end
    if (p74 ~= "") then loc73 = string.find (p1, p74) end
    if (p75 ~= "") then loc74 = string.find (p1, p75) end
    if (p76 ~= "") then loc75 = string.find (p1, p76) end
    if (p77 ~= "") then loc76 = string.find (p1, p77) end
    if (p78 ~= "") then loc77 = string.find (p1, p78) end
    if (p79 ~= "") then loc78 = string.find (p1, p79) end
    if (p80 ~= "") then loc79 = string.find (p1, p80) end
    if (p81 ~= "") then loc80 = string.find (p1, p81) end
    if (p82 ~= "") then loc81 = string.find (p1, p82) end
    if (p83 ~= "") then loc82 = string.find (p1, p83) end
    if (p84 ~= "") then loc83 = string.find (p1, p84) end
    if (p85 ~= "") then loc84 = string.find (p1, p85) end
    if (p86 ~= "") then loc85 = string.find (p1, p86) end
    if (p87 ~= "") then loc86 = string.find (p1, p87) end
    if (p88 ~= "") then loc87 = string.find (p1, p88) end
    if (p89 ~= "") then loc88 = string.find (p1, p89) end
    if (p90 ~= "") then loc89 = string.find (p1, p90) end
    if (p91 ~= "") then loc90 = string.find (p1, p91) end

    local say = ""
    say = "Found:  " 
    if (loc1 ~=nil) then say=say..loc1.." - "..p2..",  "  end
    if (loc2 ~=nil) then say=say..loc2.." - "..p3..",  "  end
    if (loc3 ~=nil) then say=say..loc3.." - "..p4..",  "  end
    if (loc4 ~=nil) then say=say..loc4.." - "..p5..",  "  end
    if (loc5 ~=nil) then say=say..loc5.." - "..p6..",  "  end
    if (loc6 ~=nil) then say=say..loc6.." - "..p7..",  "  end
    if (loc7 ~=nil) then say=say..loc7.." - "..p8..",  "  end
    if (loc8 ~=nil) then say=say..loc8.." - "..p9..",  "  end
    if (loc9 ~=nil) then say=say..loc9.." - "..p10..",  "  end
    if (loc10 ~=nil) then say=say..loc10.." - "..p11..",  "  end
    if (loc11 ~=nil) then say=say..loc11.." - "..p12..",  "  end
    if (loc12 ~=nil) then say=say..loc12.." - "..p13..",  "  end
    if (loc13 ~=nil) then say=say..loc13.." - "..p14..",  "  end
    if (loc14 ~=nil) then say=say..loc14.." - "..p15..",  "  end
    if (loc15 ~=nil) then say=say..loc15.." - "..p16..",  "  end
    if (loc16 ~=nil) then say=say..loc16.." - "..p17..",  "  end
    if (loc17 ~=nil) then say=say..loc17.." - "..p18..",  "  end
    if (loc18 ~=nil) then say=say..loc18.." - "..p19..",  "  end
    if (loc19 ~=nil) then say=say..loc19.." - "..p20..",  "  end
    if (loc20 ~=nil) then say=say..loc20.." - "..p21..",  "  end
    if (loc21 ~=nil) then say=say..loc21.." - "..p22..",  "  end
    if (loc22 ~=nil) then say=say..loc22.." - "..p23..",  "  end
    if (loc23 ~=nil) then say=say..loc23.." - "..p24..",  "  end
    if (loc24 ~=nil) then say=say..loc24.." - "..p25..",  "  end
    if (loc25 ~=nil) then say=say..loc25.." - "..p26..",  "  end
    if (loc26 ~=nil) then say=say..loc26.." - "..p27..",  "  end
    if (loc27 ~=nil) then say=say..loc27.." - "..p28..",  "  end
    if (loc28 ~=nil) then say=say..loc28.." - "..p29..",  "  end
    if (loc29 ~=nil) then say=say..loc29.." - "..p30..",  "  end
    if (loc30 ~=nil) then say=say..loc30.." - "..p31..",  "  end
    if (loc31 ~=nil) then say=say..loc31.." - "..p32..",  "  end
    if (loc32 ~=nil) then say=say..loc32.." - "..p33..",  "  end
    if (loc33 ~=nil) then say=say..loc33.." - "..p34..",  "  end
    if (loc34 ~=nil) then say=say..loc34.." - "..p35..",  "  end
    if (loc35 ~=nil) then say=say..loc35.." - "..p36..",  "  end
    if (loc36 ~=nil) then say=say..loc36.." - "..p37..",  "  end
    if (loc37 ~=nil) then say=say..loc37.." - "..p38..",  "  end
    if (loc38 ~=nil) then say=say..loc38.." - "..p39..",  "  end
    if (loc39 ~=nil) then say=say..loc39.." - "..p40..",  "  end
    if (loc40 ~=nil) then say=say..loc40.." - "..p41..",  "  end
    if (loc41 ~=nil) then say=say..loc41.." - "..p42..",  "  end
    if (loc42 ~=nil) then say=say..loc42.." - "..p43..",  "  end
    if (loc43 ~=nil) then say=say..loc43.." - "..p44..",  "  end
    if (loc44 ~=nil) then say=say..loc44.." - "..p45..",  "  end
    if (loc45 ~=nil) then say=say..loc45.." - "..p46..",  "  end
    if (loc46 ~=nil) then say=say..loc46.." - "..p47..",  "  end
    if (loc47 ~=nil) then say=say..loc47.." - "..p48..",  "  end
    if (loc48 ~=nil) then say=say..loc48.." - "..p49..",  "  end
    if (loc49 ~=nil) then say=say..loc49.." - "..p50..",  "  end
    if (loc50 ~=nil) then say=say..loc50.." - "..p51..",  "  end
    if (loc51 ~=nil) then say=say..loc51.." - "..p52..",  "  end
    if (loc52 ~=nil) then say=say..loc52.." - "..p53..",  "  end
    if (loc53 ~=nil) then say=say..loc53.." - "..p54..",  "  end
    if (loc54 ~=nil) then say=say..loc54.." - "..p55..",  "  end
    if (loc55 ~=nil) then say=say..loc55.." - "..p56..",  "  end
    if (loc56 ~=nil) then say=say..loc56.." - "..p57..",  "  end
    if (loc57 ~=nil) then say=say..loc57.." - "..p58..",  "  end
    if (loc58 ~=nil) then say=say..loc58.." - "..p59..",  "  end
    if (loc59 ~=nil) then say=say..loc59.." - "..p60..",  "  end
    if (loc60 ~=nil) then say=say..loc60.." - "..p61..",  "  end
    if (loc61 ~=nil) then say=say..loc61..": "..p62..", "  end
    if (loc62 ~=nil) then say=say..loc62..": "..p63..", "  end
    if (loc63 ~=nil) then say=say..loc63..": "..p64..", "  end
    if (loc64 ~=nil) then say=say..loc64..": "..p65..", "  end
    if (loc65 ~=nil) then say=say..loc65..": "..p66..", "  end
    if (loc66 ~=nil) then say=say..loc66..": "..p67..", "  end
    if (loc67 ~=nil) then say=say..loc67..": "..p68..", "  end
    if (loc68 ~=nil) then say=say..loc68..": "..p69..", "  end
    if (loc69 ~=nil) then say=say..loc69..": "..p70..", "  end
    if (loc70 ~=nil) then say=say..loc70..": "..p71..", "  end
    if (loc71 ~=nil) then say=say..loc71..": "..p72..", "  end
    if (loc72 ~=nil) then say=say..loc72..": "..p73..", "  end
    if (loc73 ~=nil) then say=say..loc73..": "..p74..", "  end
    if (loc74 ~=nil) then say=say..loc74..": "..p75..", "  end
    if (loc75 ~=nil) then say=say..loc75..": "..p76..", "  end
    if (loc76 ~=nil) then say=say..loc76..": "..p77..", "  end
    if (loc77 ~=nil) then say=say..loc77..": "..p78..", "  end
    if (loc78 ~=nil) then say=say..loc78..": "..p79..", "  end
    if (loc79 ~=nil) then say=say..loc79..": "..p80..", "  end
    if (loc80 ~=nil) then say=say..loc80..": "..p81..", "  end
    if (loc81 ~=nil) then say=say..loc81..": "..p82..", "  end
    if (loc82 ~=nil) then say=say..loc82..": "..p83..", "  end
    if (loc83 ~=nil) then say=say..loc83..": "..p84..", "  end
    if (loc84 ~=nil) then say=say..loc84..": "..p85..", "  end
    if (loc85 ~=nil) then say=say..loc85..": "..p86..", "  end
    if (loc86 ~=nil) then say=say..loc86..": "..p87..", "  end
    if (loc87 ~=nil) then say=say..loc87..": "..p88..", "  end
    if (loc88 ~=nil) then say=say..loc88..": "..p89..", "  end
    if (loc89 ~=nil) then say=say..loc89..": "..p90..", "  end
    if (loc90 ~=nil) then say=say..loc90..": "..p91..", "  end
    local p
    p = config.p92 or ""
    if (p ~= "") then 
        loc1 = string.find (p1, p)
        if (loc1 ~=nil) then say=say..loc1.." - "..p..", " end
    end
    p = config.p93 or ""
    if (p ~= "") then 
        loc1 = string.find (p1, p)
        if (loc1 ~=nil) then say=say..loc1.." - "..p..", " end
    end

    say = say .. " no others."
    if debugsw ~= "" then
      say = say.."<br>'''Lsearch (ver M2b):'''  p1=" ..p1
        .. "  p2=" ..p2 .. "  p3=" ..p3
        .. "  p4=" ..p4 .. "  p5=" ..p5 .. "  p6=" ..p6 .. "  p7=" ..p7
        .. "  p8=" ..p8 .. "  p9=" ..p9 .. "  p10=" ..p10 .. "  p11=" ..p11
        .. "  debugsw=" .. debugsw
    end

    return say
end

return z
-------------------------------------------------------------------------
--HISTORY:
--21Oct2012 Created
--14Mar2013 Fixed parameter p50 (with loc49) to not show p40.
--15Mar2013 Re-expanded from 61 parameters to 91 parameters.
--15Mar2013 Expanded to 93 parameters.
--
--
-- End Module:Lsearch