<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3ASandbox%2FWnt%2FNewestAtTop</id>
	<title>Module:Sandbox/Wnt/NewestAtTop - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3ASandbox%2FWnt%2FNewestAtTop"/>
	<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Sandbox/Wnt/NewestAtTop&amp;action=history"/>
	<updated>2026-05-23T03:36:05Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://stockhub.co/index.php?title=Module:Sandbox/Wnt/NewestAtTop&amp;diff=146417&amp;oldid=prev</id>
		<title>imported&gt;Pppery: Pppery moved page Module:NewestAtTop to Module:Sandbox/Wnt/NewestAtTop without leaving a redirect: Boldly userfying unused module by inactive user who has in the past asked for their abandoned modules to be userfied</title>
		<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Sandbox/Wnt/NewestAtTop&amp;diff=146417&amp;oldid=prev"/>
		<updated>2020-09-18T15:33:04Z</updated>

		<summary type="html">&lt;p&gt;Pppery moved page &lt;a href=&quot;/index.php?title=Module:NewestAtTop&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Module:NewestAtTop (page does not exist)&quot;&gt;Module:NewestAtTop&lt;/a&gt; to &lt;a href=&quot;/research/Module:Sandbox/Wnt/NewestAtTop&quot; title=&quot;Module:Sandbox/Wnt/NewestAtTop&quot;&gt;Module:Sandbox/Wnt/NewestAtTop&lt;/a&gt; without leaving a redirect: Boldly userfying unused module by inactive user who has in the past asked for their abandoned modules to be userfied&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;--This module aims to reorder the sections on a page so that, for example, you can reorder a talk page from newest sections at bottom to newest sections at top. &lt;br /&gt;
&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
-- Return the reordered page, used like this: {{#invoke:NewestAtTop|main|page=Module talk:NewestAtTop/Test|top=yes}}&lt;br /&gt;
function p.main(frame,header)&lt;br /&gt;
    local parent=frame.getParent(frame) or {}&lt;br /&gt;
    local currentpage,top&lt;br /&gt;
    ---- args in the #invoke itself trump args in the parent frame&lt;br /&gt;
    currentpage = frame.args.page&lt;br /&gt;
    header = header or frame.args.header or parent.args.header -- can get from function name&lt;br /&gt;
    top = frame.args.top or parent.args.top&lt;br /&gt;
    ---- args in the parent frame come next&lt;br /&gt;
    if parent then&lt;br /&gt;
        currentpage=currentpage or parent.args.page&lt;br /&gt;
        header=header or parent.args.header&lt;br /&gt;
        top = top or parent.args.top&lt;br /&gt;
        end&lt;br /&gt;
    ---- default values if parameters aren&amp;#039;t provided&lt;br /&gt;
    header=header or 2 -- Reorder even = = sections.  Note this isn&amp;#039;t tested and may not work...&lt;br /&gt;
    local pagepointer&lt;br /&gt;
    if top then top=1 else top=0 end&lt;br /&gt;
    if not(currentpage) then&lt;br /&gt;
        pagepointer=mw.title.getCurrentTitle()&lt;br /&gt;
        assert(pagepointer,&amp;quot;failed to access getCurrentTitle&amp;quot;)&lt;br /&gt;
        currentpage=pagepointer.fullText&lt;br /&gt;
    else pagepointer=mw.title.new(currentpage)&lt;br /&gt;
        assert(pagepointer,&amp;quot;failed to access mw.title.new(&amp;quot;..tostring(currentpage)..&amp;quot;)&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
    ---- get the text of the currentpage&lt;br /&gt;
    local text=pagepointer.getContent(pagepointer)&lt;br /&gt;
    assert (text,&amp;quot;error: failed to get text from &amp;quot;.. currentpage)&lt;br /&gt;
    local headerdef=mw.ustring.rep(&amp;quot;=&amp;quot;,header)&lt;br /&gt;
    local headermatch=&amp;quot;%s*\n%s*&amp;quot;..headerdef..&amp;quot;(=*)(.-)(=*)&amp;quot;..headerdef..&amp;quot;%s*\n%s*&amp;quot;&lt;br /&gt;
    local prowl=mw.ustring.gmatch(text,&amp;quot;(.-)&amp;quot;..headermatch)&lt;br /&gt;
    local archive={}&lt;br /&gt;
    local chunk,h1,title,h2=prowl()&lt;br /&gt;
    local level=math.min(mw.ustring.len(h1),mw.ustring.len(h2)) -- if unmatched, higher level trumps&lt;br /&gt;
    local lastchunk=&amp;quot;&amp;quot;;local lasth1=&amp;quot;==&amp;quot;;local lasth2=&amp;quot;==&amp;quot; -- keeps track of the title from the previous iteration to recover at end&lt;br /&gt;
    local tinsertpoint={};local insertpoint=1;local lastlevel=level&lt;br /&gt;
    table.insert(archive,insertpoint,chunk or &amp;quot;&amp;quot;) --- top chunk is the first thing in.  Top means display it at bottom&lt;br /&gt;
    table.insert(archive,insertpoint+top,&amp;quot;\n&amp;quot;..headerdef..title..headerdef..&amp;quot;\n&amp;quot;)&lt;br /&gt;
    repeat&lt;br /&gt;
        chunk, h1,title,h2=prowl()&lt;br /&gt;
        h1=h1 or lasth1;h2=h2 or lasth2 -- default to normal header and to avoid script error&lt;br /&gt;
        if not(chunk) then break end&lt;br /&gt;
        lastchunk=chunk; -- to find next section.  You can&amp;#039;t find a title in the string it came from.&lt;br /&gt;
        table.insert(archive,1+insertpoint+top,chunk) --- insert the OLDER chunk under LAST iteration&amp;#039;s title and level&lt;br /&gt;
        local lastlevel=level&lt;br /&gt;
        level=math.min(mw.ustring.len(h1),mw.ustring.len(h2)) -- if unmatched, higher level trumps&lt;br /&gt;
        if level&amp;gt;lastlevel then&lt;br /&gt;
            tinsertpoint[lastlevel]=insertpoint;insertpoint=insertpoint+2&lt;br /&gt;
        else if level &amp;lt; lastlevel then&lt;br /&gt;
            insertpoint=tinsertpoint[level]&lt;br /&gt;
            end&lt;br /&gt;
        end&lt;br /&gt;
        if title then&lt;br /&gt;
            lasth1=h1;lasth2=h2&lt;br /&gt;
            table.insert(archive,insertpoint+top,&amp;quot;\n&amp;quot;..string.rep(&amp;quot;=&amp;quot;,header+level)..title..string.rep(&amp;quot;=&amp;quot;,header+level)..&amp;quot;\n&amp;quot;)&lt;br /&gt;
        end --- insert the new title at the beginning&lt;br /&gt;
    until false&lt;br /&gt;
    h1,title,h2,chunk=mw.ustring.match(text,lastchunk..headermatch..&amp;quot;(.*)$&amp;quot;)-- everything from the last section header to the end of string.  Fails if two identical section headers.&lt;br /&gt;
    table.insert(archive,insertpoint+1+top,chunk)&lt;br /&gt;
    local output=&amp;quot;&amp;quot;&lt;br /&gt;
    for i = 1, table.maxn(archive) do&lt;br /&gt;
        output=output..(archive[i] or &amp;quot;&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
    return frame.preprocess(frame,output)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>imported&gt;Pppery</name></author>
	</entry>
</feed>