Jump to content

Module:Administrators' noticeboard archives/sandbox: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
simpler mw-collapsible solution
Tag: Reverted
self-rv to Izno's version
 
Line 1: Line 1:
local archiveList = require( 'Module:Archive list' )
local archiveList = require( 'Module:Archive list' )


-- Gets wikitable rows filled with archive links, using [[Module:Archive list]].
-- A table of the archives to display.
local archives = {
an = {
root = "Wikipedia:Administrators' noticeboard",
prefix = "Archive"
},
ani = {
root = "Wikipedia:Administrators' noticeboard",
prefix = "IncidentArchive"
},
['3rr'] = {
root = "Wikipedia:Administrators' noticeboard",
prefix = "3RRArchive"
},
ae = {
root = "Wikipedia:Arbitration/Requests/Enforcement",
prefix = "Archive"
},
csn = {
root = "Wikipedia:Administrators' noticeboard/Community sanction",
prefix = "Archive"
}
}

-- Gets wikitable rows filled with archive links, using
-- [[Module:Archive list]].
local function getLinks( funcArgs )
local function getLinks( funcArgs )
if type( funcArgs ) ~= 'table' then
if type( funcArgs ) ~= 'table' then
error( 'Invalid input to getLinks', 2 )
error( 'Invalid input to getLinks', 2 )
end
end
funcArgs.sep = '\n| '
funcArgs.sep = '</li><li>'
funcArgs.linesep = '\n|-\n| '
funcArgs.links = 20
funcArgs.linesep = '&#32;' -- hacking around the wrapper to remove lineseparators
return mw.ustring.format(
return mw.ustring.format(
'|-\n| %s',
'<ol class="an-archives-list"><li>%s</li></ol>',
archiveList.main( funcArgs )
archiveList.main( funcArgs )
)
)
end
end


-- Returns a Lua table with value being a list of archive links
-- Returns a Lua table with value being a list of archive links for one of the
-- for one of the noticeboards listed in the archives table
-- noticeboards listed in the archives table at the top of the module.
-- at the top of the module.
local function getLinksTable( all )
local function getLinksTable( all )

-- A table of the archives to display.
local archives = {
an = {
root = "Wikipedia:Administrators' noticeboard",
prefix = "Archive"
},
ani = {
root = "Wikipedia:Administrators' noticeboard",
prefix = "IncidentArchive"
},
['3rr'] = {
root = "Wikipedia:Administrators' noticeboard",
prefix = "3RRArchive"
},
ae = {
root = "Wikipedia:Arbitration/Requests/Enforcement",
prefix = "Archive"
},
csn = {
root = "Wikipedia:Administrators' noticeboard/Community sanction",
prefix = "Archive"
}
}
local t = {}
local t = {}
for board, archive in pairs( archives ) do
for board, archive in pairs( archives ) do
Line 60: Line 59:
end
end
return t
return t
end

local function group (main_page, search, list)
local ret = mw.html.create('li')
ret:tag('div')
:addClass('an-archives-header')
:wikitext(main_page .. " ")
:tag('span')
:wikitext(search)
:done()
:done()
ret:wikitext(list)
:allDone()
return ret
end
end


-- Build the wikitable using mw.ustring.format.
-- Build the wikitable using mw.ustring.format.
local function buildWikitable( args )
local function buildWikitable( args )
local t = getLinksTable( args.all )
local t = getLinksTable( args.all )
local frame = mw.getCurrentFrame()
local frame = mw.getCurrentFrame()
local lists = {
group(
"[[Wikipedia:Administrators' noticeboard|Administrators']]",
"([[Wikipedia:Administrators' noticeboard/Archives|archives]], [[Template:Administrators' noticeboard archives/Search|search]])",
t.an
),
group(
"[[Wikipedia:Administrators' noticeboard/Incidents|Incidents]]",
"([[Wikipedia:Administrators' noticeboard/IncidentArchives|archives]], [[Template:Administrators' noticeboard archives/Search|search]])",
t.ani
),
group(
"[[Wikipedia:Administrators' noticeboard/Edit warring|Edit-warring/3RR]]",
"([[Wikipedia:Administrators' noticeboard/3RRArchives|archives]], [[Template:Administrators' noticeboard archives/Search|search]])",
t['3rr']
),
group(
"[[Wikipedia:Arbitration/Requests/Enforcement|Arbitration enforcement]]",
"([[Wikipedia:Arbitration/Requests/Enforcement/Archive|archives]])",
t.ae
)
}
-- optional since these haven't been used in a while
if args.csn == 'yes' then
table.insert(lists, group(
"Community sanction archives",
"([[Template:Administrators\' noticeboard archives/Search|search]])",
t.csn
))
end
local other_links = mw.html.create('li')
other_links:tag('div')
:addClass('an-archives-header')
:wikitext('Other links')
:done()
:wikitext(require('Module:List').horizontal({
"[[Wikipedia talk:Administrators' noticeboard|Talk]]",
'[[Wikipedia:Sockpuppet investigations|Sockpuppet investigations]]',
'[[:Category:Administrative backlog|Backlog]]'
}))
:allDone()
table.insert(lists, other_links)
local list = mw.html.create('ul')
for _, group in ipairs(lists) do
list:node(group)
end
list:allDone()
local box = mw.html.create('div')
box:addClass('an-archives')
:tag('div')
:addClass('an-archives-caption')
:wikitext('Noticeboard archives')
:done()
:node(list)


-- The following are defined here for convenience, as they recur frequently
-- in the wikitable.
local headerStyle = 'style="background-color: #ccf; font-size: 111%; line-height: 1.25em;" colspan="10"'
local openSpan = '<span class="plainlinks" style="font-size: smaller;">'
local closeSpan = '</span>'
local searchLink = "[[Template:Administrators' noticeboard archives/Search|search]]"
-- Community sanction archive links plus header. We define it here as it is optional.
local csn = ''
if args.csn == 'yes' then
csn = '\n|-\n! '
.. headerStyle
.. ' | Community sanction archives '
.. openSpan
.. "([[Template:Administrators' noticeboard archives/Search|search]])"
.. closeSpan
.. '\n'
.. t.csn
end
-- The inputbox plus header. We define it here as it is optional.
local inputbox = ''
if args.search == 'yes' then
if args.search == 'yes' then
box:tag('div')
inputbox = '\n|-\n! colspan="10" style="white-space: nowrap;" | '
:addClass('an-archives-search')
.. frame:preprocess(
:wikitext(frame:preprocess(
[==[
[==[
<inputbox>
<inputbox>
Line 102: Line 153:
placeholder=Search noticeboards archives
placeholder=Search noticeboards archives
</inputbox>]==]
</inputbox>]==]
))
)

end
end
box:allDone()
local bottom_list = require('Module:List').horizontal({
return frame:extensionTag {
"[[Wikipedia talk:Administrators' noticeboard|Talk]]",
name = 'templatestyles', args = { src = 'Module:Administrators\' noticeboard archives/styles.css' }
'[[Wikipedia:Sockpuppet investigations|Sockpuppet investigations]]',
} .. '__NOINDEX__' .. tostring(box)
'[[:Category:Administrative backlog|Backlog]]'
})


local collapsedStyle = 'mw-collapsible'
if args.all then
collapsedStyle = 'mw-collapsible mw-collapsed'
end
return mw.ustring.format(
[==[
<div style="float: right; clear: right; margin: 0 0 1em 1em; text-align: right">
{| class="noprint %s" style="background-color: #fdfdfd; clear: both; padding: 1px; box-sizing: border-box; border: 1px solid #a2a9b1; font-size:88%%; line-height:1.2em; margin:0; width:auto; text-align:center"
|+ Noticeboard archives
|-
! %s | [[Wikipedia:Administrators' noticeboard|Administrators']] %s([[Wikipedia:Administrators' noticeboard/Archives|archives]], %s)%s
%s
|-
! %s | [[Wikipedia:Administrators' noticeboard/Incidents|Incidents]] %s([[Wikipedia:Administrators' noticeboard/IncidentArchives|archives]], %s)%s
%s
|-
! %s | [[Wikipedia:Administrators' noticeboard/Edit warring|Edit-warring/3RR]] %s([[Wikipedia:Administrators' noticeboard/3RRArchives|archives]], %s)%s
%s
|-
! %s | [[Wikipedia:Arbitration/Requests/Enforcement|Arbitration enforcement]] %s([[Wikipedia:Arbitration/Requests/Enforcement/Archive|archives]])%s
%s%s
|-
! %s |Other links
|-
|colspan="10" style="text-align: center;"| %s%s
|}
</div>__NOINDEX__]==],
collapsedStyle,
headerStyle, openSpan, searchLink, closeSpan,
t.an,
headerStyle, openSpan, searchLink, closeSpan,
t.ani,
headerStyle, openSpan, searchLink, closeSpan,
t['3rr'],
headerStyle, openSpan, closeSpan,
t.ae, csn,
headerStyle,
bottom_list, inputbox
)
end
end



Latest revision as of 19:54, 21 August 2024

local archiveList = require( 'Module:Archive list' )

-- Gets wikitable rows filled with archive links, using [[Module:Archive list]].
local function getLinks( funcArgs )
    if type( funcArgs ) ~= 'table' then
        error( 'Invalid input to getLinks', 2 )
    end
    funcArgs.sep = '</li><li>'
    funcArgs.links = 20
    funcArgs.linesep = '&#32;' -- hacking around the wrapper to remove lineseparators
    return  mw.ustring.format(
        '<ol class="an-archives-list"><li>%s</li></ol>',
        archiveList.main( funcArgs )
    )
end

-- Returns a Lua table with value being a list of archive links for one of the
-- noticeboards listed in the archives table at the top of the module.
local function getLinksTable( all )

	-- A table of the archives to display.
	local archives = {
	    an = { 
	        root = "Wikipedia:Administrators' noticeboard",
	        prefix = "Archive"
	    },
	    ani = {
	        root = "Wikipedia:Administrators' noticeboard",
	        prefix = "IncidentArchive"
	    },
	    ['3rr'] = {
	        root = "Wikipedia:Administrators' noticeboard",
	        prefix = "3RRArchive"
	    },
	    ae = {
	        root = "Wikipedia:Arbitration/Requests/Enforcement",
	        prefix = "Archive"
	    },
	    csn = {
	        root = "Wikipedia:Administrators' noticeboard/Community sanction",
	        prefix = "Archive"
	    }
	}
    local t = {}
    for board, archive in pairs( archives ) do
        local funcArgs = archive
        if not all then
            local archiveMax = archiveList.count( funcArgs )
            if type( archiveMax ) == 'number' and archiveMax >= 0 then
                funcArgs.max = math.floor( archiveMax )
                local start = funcArgs.max -19
                if start < 1 then
                    start = 1
                end
                funcArgs.start = start
            end
        end
        t[board] = getLinks( funcArgs )
    end
    return t
end

local function group (main_page, search, list)
	local ret = mw.html.create('li')
		ret:tag('div')
			:addClass('an-archives-header')
			:wikitext(main_page .. " ")
				:tag('span')
					:wikitext(search)
				:done()
			:done()
		ret:wikitext(list)
		:allDone()
	return ret
end

-- Build the wikitable using mw.ustring.format.
local function buildWikitable( args )
	local t = getLinksTable( args.all )
	local frame = mw.getCurrentFrame()
	local lists = {
		group(
			"[[Wikipedia:Administrators' noticeboard|Administrators']]",
			"([[Wikipedia:Administrators' noticeboard/Archives|archives]], [[Template:Administrators' noticeboard archives/Search|search]])",
			t.an
		),
		group(
			"[[Wikipedia:Administrators' noticeboard/Incidents|Incidents]]",
			"([[Wikipedia:Administrators' noticeboard/IncidentArchives|archives]], [[Template:Administrators' noticeboard archives/Search|search]])",
			t.ani
    	),
		group(
			"[[Wikipedia:Administrators' noticeboard/Edit warring|Edit-warring/3RR]]",
			"([[Wikipedia:Administrators' noticeboard/3RRArchives|archives]], [[Template:Administrators' noticeboard archives/Search|search]])",
			t['3rr']
		),
		group(
			"[[Wikipedia:Arbitration/Requests/Enforcement|Arbitration enforcement]]",
			"([[Wikipedia:Arbitration/Requests/Enforcement/Archive|archives]])",
			t.ae
		)
	}
	-- optional since these haven't been used in a while
	if args.csn == 'yes' then
		table.insert(lists, group(
			"Community sanction archives",
			"([[Template:Administrators\' noticeboard archives/Search|search]])",
			t.csn
		))
	end
	
	local other_links = mw.html.create('li') 
		other_links:tag('div')
			:addClass('an-archives-header')
			:wikitext('Other links')
			:done()
		:wikitext(require('Module:List').horizontal({
	    	"[[Wikipedia talk:Administrators' noticeboard|Talk]]",
	    	'[[Wikipedia:Sockpuppet investigations|Sockpuppet investigations]]',
	    	'[[:Category:Administrative backlog|Backlog]]'
	    }))
	    :allDone()
	
	table.insert(lists, other_links)
	
	local list = mw.html.create('ul')
	
	for _, group in ipairs(lists) do
		list:node(group)
	end
	list:allDone()
	
    local box = mw.html.create('div')
    box:addClass('an-archives')
    	:tag('div')
    		:addClass('an-archives-caption')
    		:wikitext('Noticeboard archives')
    		:done()
    	:node(list)

    if args.search == 'yes' then
    	box:tag('div')
			:addClass('an-archives-search')
			:wikitext(frame:preprocess(
[==[
<inputbox>
bgcolor=transparent
type=fulltext
prefix=Wikipedia:Administrators' noticeboard
break=no
width=32
searchbuttonlabel=Search
placeholder=Search noticeboards archives
</inputbox>]==]
			))
    end
    box:allDone()
        	
    return frame:extensionTag {
		name = 'templatestyles', args = { src = 'Module:Administrators\' noticeboard archives/styles.css' }
	} .. '__NOINDEX__' .. tostring(box)

end

function makeWrapper( all )
    return function( frame )
        -- If we are being called from #invoke, get the args from #invoke
        -- if they exist, or else get the arguments passed to the parent
        -- frame. Otherwise, assume the arguments are being passed directly
        -- in from another module or from the debug console.
        local origArgs
        if frame == mw.getCurrentFrame() then
            origArgs = frame:getParent().args
            for k, v in pairs( frame.args ) do
                origArgs = frame.args
                break
            end
        else
            origArgs = frame
        end
 
        -- Ignore blank values for parameters.
        local args = {}
        for k, v in pairs( origArgs ) do
            if v ~= '' then
                args[k] = v
            end
        end
        
        -- Find whether we are getting all the links or just the
        -- last 20 links.
        args.all = all
        
        return buildWikitable( args )
    end
end
 
return {
    compact = makeWrapper(),
    all = makeWrapper( true )
}