Module:Asbox stubtree and Module:Asbox stubtree/sandbox: Difference between pages

(Difference between pages)
Jump to navigation Jump to search
Page 1
Page 2
imported>WOSlinker
m Changed protection level of Module:Asbox stubtree: allow template editors to modify ([Edit=Protected template] (indefinite) [Move=Protected template] (indefinite))
 
imported>Izno
save this while I'm thinking about it
 
Line 1: Line 1:
local i = {}
local p = {}


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


function i.pcase(word)
function p.pcase(word)
   return mw.ustring.upper(mw.ustring.sub(word,1,1)) .. mw.ustring.sub(word,2)
   return mw.ustring.upper(mw.ustring.sub(word,1,1)) .. mw.ustring.sub(word,2)
end
end


function i._subtree(pagename)
function p._subtree(pagename)
     local finalresult
     -- split items on dash into table
    local out = {"",pagename}
    local tt
    local temppage
    local temppageexists
     local r = 0
     local r = 0
     local t = {}
     local t = {}
    local removeditem1 = ""
    local removeditem2 = ""
   
    -- split items on dash into table
     for token in mw.ustring.gmatch(pagename, "[^-]+") do
     for token in mw.ustring.gmatch(pagename, "[^-]+") do
         -- don't add numbered items to list
         -- don't add numbered items to list
Line 32: Line 23:
     table.remove(t, #t)
     table.remove(t, #t)


    local out = {"",pagename}
    local temppage
    local temppageexists
    local removeditem1 = ""
    local removeditem2 = ""
     while (#t > 1) do
     while (#t > 1) do
         if r == 1 then
         if r == 1 then
Line 42: Line 38:


         temppage = table.concat(t, "-") .. "-stub"
         temppage = table.concat(t, "-") .. "-stub"
         temppageexists = i.exists(temppage)
         temppageexists = p.exists(temppage)
         if temppageexists == true then
         if temppageexists == true then
             table.insert(out,"[[Template:" .. temppage .. "|" .. i.pcase(temppage) .. "]]")
             table.insert(out,"[[Template:" .. temppage .. "|" .. p.pcase(temppage) .. "]]")
         else
         else
             -- If template with first item does not exist, try removing last item
             -- If template with first item does not exist, try removing last item
Line 53: Line 49:
                 temppage = removeditem1 .. "-stub"
                 temppage = removeditem1 .. "-stub"
             end
             end
             temppageexists = i.exists(temppage)
             temppageexists = p.exists(temppage)
             if temppageexists == true then
             if temppageexists == true then
                 -- if exists then add first item back to list
                 -- if exists then add first item back to list
                 table.insert(t,1,removeditem1)
                 table.insert(t,1,removeditem1)
                 table.insert(out,"[[Template:" .. temppage .. "|" .. i.pcase(temppage) .. "]]")
                 table.insert(out,"[[Template:" .. temppage .. "|" .. p.pcase(temppage) .. "]]")
             else
             else
                 -- if exists then add last item back to list
                 -- if exists then add last item back to list
Line 64: Line 60:
         end
         end
     end
     end
 
   
     finalresult = '<div style="float:right; border-style:dotted; border-width:2px; padding:5px; margin:5px;">'
    local list = mw.html.create('ul')
    finalresult = finalresult .. '<span title="This shows the hierarchy of the stub template in relation to other templates." style="font-size:125%; font-weight:bold;">Stub hierarchy</span>'
    for _, item in ipairs(out) do
    finalresult = finalresult .. table.concat(out, "\n* ")
    list:tag('li'):wikitext(item):done()
    finalresult = finalresult .. '\n* [[Template:Stub|Stub]]'
    end
    finalresult = finalresult .. '\n</div>'
    list:tag('li'):wikitext('[[Template:Stub|Stub]]'):allDone()
     return finalresult
     local finalresult = mw.html.create('div')
    finalresult:cssText('float:right; border-style:dotted; border-width:2px; padding:5px; margin:5px;')
    :tag('span')
    :attr('title', 'This shows the hierarchy of the stub template in relation to other templates.')
    :cssText('font-size:125%; font-weight:bold;')
    :wikitext('Stub hierarchy')
    :done()
    :addNode(list)
    :done()
   
     return tostring(finalresult)
end
end


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


return i
return p