Module:RightBox

-- local getArgs = require('Module:Arguments').getArgs local mapNamedArgs = require('Module:Arguments').mapNamedArgs local mergeArgsSyntax = require('Module:Arguments').mergeArgsSyntax local yesno = require('Module:Yesno') local string = require('Module:String') local lu = require('Module:LibraryUtil') local checkType, checkType, checkTypeField = lu.checkType, lu.checkType, lu.checkTypeField

local p = {}

local fullurl = mw.uri.fullUrl local currentTitleObj = mw.title.getCurrentTitle local fullpagename = currentTitleObj.fullText

function p.luaBox(frame) local args = getArgs(frame) local list = {} local l = mergeArgsSyntax(args) for i = 1,#l,1 do       list[#list+1] = string.wrapHtml{ {               string.makeLink({ 'Module:', l[i] }), ' (',               string.fullUrl({ 'Module:', l[i]:gsub(' ', '_'), '' }, { action="edit" }, string.wrapHtml('e', ' ', { title="Edit" })),                ' &bull; ',                string.fullUrl({ 'Module:', l[i]:gsub(' ', '_'), '/sandbox' }, nil, string.wrapHtml('s', ' ', { title="Sandbox" })),                ')', },           '', }   end

list = table.concat{ 'Invokes ', string.makeLink('Help:Lua', 'Lua'), ':',       string.wrapHtml(list, '', {            style={                ["list-style-type"]="disc";                 ["margin"]= "0 0 0 15px";                ["white-space"]="nowrap";            }        }), }   local box = mw.html.create('table') :attr({            cellpadding=0;            cellspacing=0;            style="float:right; width:240px; margin:0.1em 0 0.5em 0.25em; padding: 4px";            class="wikitable";        }) local row = box:tag('tr') row:tag('td') :attr({ style="border-right:0; padding:0 12px" }) :wikitext(string.makeImage('Lua icon.png', { size="30px" })) :done row:tag('td') :attr({                   style="border-left:0; width:100%; padding:0 5px 0 0;"                }) :wikitext(list) :done row:done box:done return frame:preprocess(tostring(box)) end

function p.userboxList(frame) local args = getArgs(frame) local list = {} local l = mergeArgsSyntax(args) for i = 1,#l,1 do       list[i] = string.wrapHtml{ {               string.wrapHtml{ l[i], ' ',                    { padding="2.5px" } }           },            ' ',        }    end return table.concat(list, '') end

function p.shortcut(frame) local args = getArgs(frame) local list = mergeArgsSyntax(args) return p._shortcut(list) end

function p._shortcut(list) checkType('_shortcut', 1, list, 'table') for i = 1,#list,1 do       title = mw.title.new(list[i]) pagename = title.fullText list[i] = (               title.exists                 and string.fullUrl(pagename, { redirect='no' }, { string.wrapHtml(pagename, '', { style="display: block;" }) })                 or string.fullUrl( title.fullText, {                       action='edit', redlink=1, preload='Template:Shortcut/preload', },                   string.wrapHtml{ { string.wrapHtml(pagename, '', { style="display: block;" }) }, ' ',                       {                            style="color: #ba0000", title={ pagename, '(page does not exist)' }, }                   }                )            )    end local separator = mw.html.create('div') :attr({ style="border-bottom:1px solid #555; padding:0 3px; clear:right;" }) :wikitext(string.makeLink('Template:Shortcut', { , 'Shortcut', #list > 1 and "s" or "",  })) local box = mw.html.create('div') :attr({ class="noprint" }) :css({           border="1px solid #5e484a";            background="#251214";            margin="5px 0 2px 5px";            padding="2px 5px";            float="right";            ["text-align"]="center";            ["font-size"]="75%"        }) :wikitext(table.concat({ tostring(separator), table.concat(list)}))

return(tostring(box)) end

function p.archivesBox(frame) local args = getArgs(frame, { removeBlanks = false }) local titles = mapNamedArgs(args, 'title') local list = mapNamedArgs(args) local showSearchBox = yesno(args["searchbox"], args["search"] or args["s"] or args["shows"], false) local floatAliases = { ['r']="right"; ['ri']="right"; ['rig']="right"; ['righ']="right"; ['right']="right"; ['l']="left"; ['le']="left"; ['lef']="left"; ['left']="left"; }   local function makeMain return mw.html.create('table') :attr({               cellspacing="0";                cellpadding="5px";            }) :css({               ["margin"] = "7px 0px";                ["border"] = "2px solid black";                ["box-shadow"] = "0 0 15px #000000";                ["float"] = floatAliases[(args["float"] or args["f"] or args["flo"] or ""):lower] or "right";            }) :tag('tr') :tag('th') :css({                       ["color"] = "white";                        ["background"] = "#542e2e";                        ["margin-left"] ="6px";                        ["padding"] = "1.5px";                    }) :wikitext(string.wrapHtml{                       string.wrapHtml{                            'Archives',                            ' ',                        },                         ' ',                        {                            style = {                                ["border"] = "4.5px outset #555";                                ["padding"] = "2px 15px";                                ["background"] = "#542e2e";                            }                        }                    }) :done :done end ret = makeMain for i = 1, #list, 1 do       local title = titles['title'..i] ~= "" and titles['title'..i] or nil local archivesText archivesText = table.concat{ (title                and string.wrapHtml{                    { , title,  },                    ' ',                    {                        style={                            ["border"] = "2.5px outset #555";                            ["padding"] = "0px 15px";                            ["background"] = "#542e2e";                            ["text-align"] = "center";                        }                    }                }                or ""            ), args[i], }       ret:tag('tr') :tag('td') :css({                   ["padding"]="2px";                     ["border-top"]="2px solid #775454"                }) :wikitext(archivesText) :done :done if i == #list and showSearchBox then ret:tag('tr') :tag('td') :css({                       ["padding"]="2px";                         ["border-top"]="2px solid #775454"                    }) :wikitext(frame:preprocess) :done :done end end return ret:done end

function p.archivesList(frame) local args = getArgs(frame); local i = 1; local list = {}; local sep = args["sep"] or args["s"] local pagename = args[1] or args["page"] or args["p"] or mw.title.getCurrentTitle.fullText while mw.title.new(table.concat{           pagename,             "/Archive ",            i        }).exists do        i = i + 1 end local limit = tonumber(args[2] or i-1); --Errors if limit == 0 then return string.error('No Archives Found') elseif limit >= i then return string.error('Limit must not be greater that the number of archives, got %d', limit) elseif limit <= 0 then return string.error('Limit must not be less than 1, got %d', limit) end for j = (limit ~= 0 and i-limit or 1), i-1, 1 do       list[#list+1] = string.wrapHtml{ {               'Archive ',                j,                '', string.wrapHtml{ {                       ' (',                        string.fullUrl( { pagename, "/Archive ", j }, { ['action']='edit' }, string.wrapHtml{ 'edit', ' ',                               {                                    title={ "Edit the Talk Archive #", j, ' of ', pagename} }                           }                        ),                        ' • ',                        string.fullUrl( { pagename, "/Archive ", j }, { ['action']='history' }, string.wrapHtml{ 'hist', ' ',                               {                                    title={ "View the history for the Talk Archive #", j, ' of ', pagename} }                           }                        ),                        ')',                    },                    ' ',                    {                        style="font-size: 10px" }               },            },            ' ',            {                style=args["style"..j] or args["s"..j]; class=args["class"..j] or args["c"..j]; id=args["id"..j]; }       }    end return string.wrapHtml{table.concat(list, sep or " "), ' '} end

return p