Jump to content

Module:Administrators' noticeboard archives

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 14:17, 3 July 2013 (mostly done). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local dts = require( 'Module:User:Anomie/deepToString' ).deepToString

local archiveList = require( '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"
    }
}

local function getLinks( funcArgs )
    if type( funcArgs ) ~= 'table' then
        error( 'Invalid input to getLinks', 2 )
    end
    funcArgs.sep = '\n| '
    funcArgs.linesep = '\n|-\n| '
    return  mw.ustring.format(
        '|-\n| %s',
        archiveList.main( funcArgs )
    )
end

local function getLinksTable( all )
    local t = {}
    for board, archive in pairs( archives ) do
        local funcArgs = archive
        if not all then
            funcArgs.max = archiveList.count( funcArgs )
            funcArgs.start = math.ceil( funcArgs.max / 10 ) * 10 - 19
        end
        t[board] = getLinks( funcArgs )
    end
    return t
end

local function buildTable( args )
    local t = getLinksTable( args.all )
    local frame = mw.getCurrentFrame()
    local inputbox = frame:preprocess(
        [==[
<inputbox>
bgcolor=transparent
type=fulltext
prefix=Wikipedia:Administrators' noticeboard
break=yes
width=35
searchbuttonlabel=Search noticeboards & archives
</inputbox>]==]
    )
    local navbar = frame:preprocess(
        "{{navbar|Module:Administrators' noticeboard navbox|mini=1}}"
    )
    local headerStyle = 'style="font-size: 111%; line-height: 1.25em;" colspan="10"'
    local openSpan = '<span class="plainlinks" style="font-size: x-small;">'
    local closeSpan = '</span>'
    local searchLink = "[[Template:Administrators' noticeboard navbox/Search|search]]"
    return mw.ustring.format(
        [==[
<div style="float: right; clear: right; margin: 0 0 1em 1em; text-align: right">
<span style="float: left">'''Noticeboard archives'''</span>
%s
{| class="navbox noprint" style="font-size:88%%; line-height:1.2em; margin:0; width:auto; text-align:center"
|-
! %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/3RR|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 | Community sanction archives %s([[Template:Administrators' noticeboard navbox/Search|search]])%s
%s
|-
! %s |Other links
|-
|colspan="10" align="center"|[[Wikipedia talk:Administrators' noticeboard|Talk]] | [[Wikipedia:Sockpuppet investigations|Checkuser]] | [[:Category:Administrative backlog|Backlog]]
|}
</div>__NOINDEX__]==],
        navbar,
        headerStyle, openSpan, searchLink, closeSpan,
        t.an,
        headerStyle, openSpan, searchLink, closeSpan,
        t.ani,
        headerStyle, openSpan, searchLink, closeSpan,
        t['3rr'],
        headerStyle, openSpan, closeSpan,
        t.ae,
        headerStyle, openSpan, closeSpan,
        t.csn,
        headerStyle
    )        
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 buildTable( args )
    end
end
 
return {
    main = makeWrapper(),
    all = makeWrapper( true )
}