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&#039;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, &quot;Template&quot;).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, &quot;[^-]+&quot;) do<br /> -- don&#039;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 = {&quot;&quot;,pagename}<br /> local temppage<br /> local temppageexists<br /> local removeditem1 = &quot;&quot;<br /> local removeditem2 = &quot;&quot;<br /> while (#t &gt; 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, &quot;-&quot;) .. &quot;-stub&quot;<br /> temppageexists = p.exists(temppage)<br /> if temppageexists == true then<br /> table.insert(out,&quot;[[Template:&quot; .. temppage .. &quot;|&quot; .. p.pcase(temppage) .. &quot;]]&quot;)<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 .. &quot;-&quot; .. table.concat(t, &quot;-&quot;) .. &quot;-stub&quot;<br /> if #t == 0 then<br /> temppage = removeditem1 .. &quot;-stub&quot;<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,&quot;[[Template:&quot; .. temppage .. &quot;|&quot; .. p.pcase(temppage) .. &quot;]]&quot;)<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(&#039;ul&#039;)<br /> for _, item in ipairs(out) do<br /> list:tag(&#039;li&#039;):wikitext(item):done()<br /> end<br /> list:tag(&#039;li&#039;):wikitext(&#039;[[Template:Stub|Stub]]&#039;):allDone()<br /> <br /> local finalresult = mw.html.create(&#039;div&#039;)<br /> finalresult:cssText(&#039;float:right; border-style:dotted; border-width:2px; padding:5px; margin:5px;&#039;)<br /> :tag(&#039;span&#039;)<br /> :attr(&#039;title&#039;, &#039;This shows the hierarchy of the stub template in relation to other templates.&#039;)<br /> :cssText(&#039;font-size:125%; font-weight:bold;&#039;)<br /> :wikitext(&#039;Stub hierarchy&#039;)<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[&quot;pagename&quot;])<br /> end<br /> <br /> return p</div> Izno