Module:Asbox stubtree and Module:Asbox stubtree/sandbox: Difference between pages
Appearance
(Difference between pages)
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 |
local p = {} |
||
function |
function p.exists(pagename) |
||
return mw.title.new(pagename, "Template").exists |
|||
return t.exists |
|||
end |
end |
||
function |
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 |
function p._subtree(pagename) |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
local temppageexists |
|||
local r = 0 |
local r = 0 |
||
local t = {} |
local t = {} |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
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) |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
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 = |
temppageexists = p.exists(temppage) |
||
if temppageexists == true then |
if temppageexists == true then |
||
table.insert(out,"[[Template:" .. 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 = |
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 .. "|" .. |
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') |
|||
⚫ | |||
for _, item in ipairs(out) do |
|||
⚫ | |||
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() |
|||
⚫ | |||
return finalresult |
|||
⚫ | |||
⚫ | |||
:tag('span') |
|||
⚫ | |||
:cssText('font-size:125%; font-weight:bold;') |
|||
:wikitext('Stub hierarchy') |
|||
:done() |
|||
:addNode(list) |
|||
:done() |
|||
⚫ | |||
end |
end |
||
function |
function p.subtree(frame) |
||
return |
return p._subtree(frame.args["pagename"]) |
||
end |
end |
||
return |
return p |