Module:Asbox stubtree: Difference between revisions

From Zoophilia Wiki
Jump to navigationJump to search
meta>WOSlinker
No edit summary
meta>WOSlinker
exists
Line 2: Line 2:


function i.exists(pagename)
function i.exists(pagename)
     return 1
    local t = mw.title.new(pagename, "Template")
     return t.exists
end
end



Revision as of 20:14, 6 March 2013

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

local i = {}

function i.exists(pagename)
    local t = mw.title.new(pagename, "Template")
    return t.exists
end

function i._subtree(pagename)
    local out = {"",pagename}
    local tt
    local temppage
    local temppageexists
    local r = 0
    local t = {}
    
    -- split items on dash into table
    for token in mw.ustring.gmatch(pagename, "[^-]+") do
        -- don't add numbered items to list
        if tonumber(mw.ustring.sub(token,1,1)) == nil then
            table.insert(t,token)
            r = 1
        end
    end
    table.remove(t, #t)

    while (#t > 1) do
        if r == 1 then
            r = 0
        else
            table.remove(t, 1)
            temppage = table.concat(t, "-") .. "-stub"
            temppageexists = i.exists(temppage)
            if temppageexists == 0 then
                --TODO
            end
        end
        table.insert(out,temppage)
    end

    return table.concat(out, "\n* ")
end

function i.subtree(frame)
    return i._subtree(frame.args["pagename"])
end

return i