Jump to content

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

(Difference between pages)
Page 1
Page 2
Content deleted Content added
m Changed protection level of Module:Asbox stubtree: allow template editors to modify ([Edit=Protected template] (indefinite) [Move=Protected template] (indefinite))
 
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)
-- split items on dash into table
local finalresult
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

local list = mw.html.create('ul')
finalresult = '<div style="float:right; border-style:dotted; border-width:2px; padding:5px; margin:5px;">'
for _, item in ipairs(out) do
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>'
list:tag('li'):wikitext(item):done()
finalresult = finalresult .. table.concat(out, "\n* ")
end
finalresult = finalresult .. '\n* [[Template:Stub|Stub]]'
list:tag('li'):wikitext('[[Template:Stub|Stub]]'):allDone()
finalresult = finalresult .. '\n</div>'
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