https://en.wikipedia.org/w/index.php?action=history&feed=atom&title=Module%3AAsbox_stubtree%2Fsandbox
Module:Asbox stubtree/sandbox - Revision history
2025-05-30T06:35:32Z
Revision history for this page on the wiki
MediaWiki 1.45.0-wmf.3
https://en.wikipedia.org/w/index.php?title=Module:Asbox_stubtree/sandbox&diff=1213112348&oldid=prev
Izno: save this while I'm thinking about it
2024-03-11T05:08:43Z
<p>save this while I'm thinking about it</p>
<p><b>New page</b></p><div>local p = {}<br />
<br />
function p.exists(pagename)<br />
return mw.title.new(pagename, "Template").exists<br />
end<br />
<br />
function p.pcase(word)<br />
return mw.ustring.upper(mw.ustring.sub(word,1,1)) .. mw.ustring.sub(word,2)<br />
end<br />
<br />
function p._subtree(pagename)<br />
-- split items on dash into table<br />
local r = 0<br />
local t = {}<br />
for token in mw.ustring.gmatch(pagename, "[^-]+") do<br />
-- don't add numbered items to list<br />
if tonumber(mw.ustring.sub(token,1,1)) == nil then<br />
table.insert(t,token)<br />
else<br />
r = 1<br />
end<br />
end<br />
table.remove(t, #t)<br />
<br />
local out = {"",pagename}<br />
local temppage<br />
local temppageexists<br />
local removeditem1 = ""<br />
local removeditem2 = ""<br />
while (#t > 1) do<br />
if r == 1 then<br />
r = 0<br />
else<br />
-- Remove 1st item from list<br />
removeditem1 = t[1]<br />
table.remove(t, 1)<br />
end<br />
<br />
temppage = table.concat(t, "-") .. "-stub"<br />
temppageexists = p.exists(temppage)<br />
if temppageexists == true then<br />
table.insert(out,"[[Template:" .. temppage .. "|" .. p.pcase(temppage) .. "]]")<br />
else<br />
-- If template with first item does not exist, try removing last item<br />
removeditem2 = t[#t]<br />
table.remove(t, #t)<br />
temppage = removeditem1 .. "-" .. table.concat(t, "-") .. "-stub"<br />
if #t == 0 then<br />
temppage = removeditem1 .. "-stub"<br />
end<br />
temppageexists = p.exists(temppage)<br />
if temppageexists == true then<br />
-- if exists then add first item back to list<br />
table.insert(t,1,removeditem1)<br />
table.insert(out,"[[Template:" .. temppage .. "|" .. p.pcase(temppage) .. "]]")<br />
else<br />
-- if exists then add last item back to list<br />
table.insert(t,removeditem2)<br />
end<br />
end<br />
end<br />
<br />
local list = mw.html.create('ul')<br />
for _, item in ipairs(out) do<br />
list:tag('li'):wikitext(item):done()<br />
end<br />
list:tag('li'):wikitext('[[Template:Stub|Stub]]'):allDone()<br />
<br />
local finalresult = mw.html.create('div')<br />
finalresult:cssText('float:right; border-style:dotted; border-width:2px; padding:5px; margin:5px;')<br />
:tag('span')<br />
:attr('title', 'This shows the hierarchy of the stub template in relation to other templates.')<br />
:cssText('font-size:125%; font-weight:bold;')<br />
:wikitext('Stub hierarchy')<br />
:done()<br />
:addNode(list)<br />
:done()<br />
<br />
return tostring(finalresult)<br />
end<br />
<br />
function p.subtree(frame)<br />
return p._subtree(frame.args["pagename"])<br />
end<br />
<br />
return p</div>
Izno