Module:RightBox

-- local multiRequire = require('Module:MultiRequire').multiRequire local getArgs = require('Module:Arguments').getArgs local mapNamedArgs = require('Module:Arguments').mapNamedArgs local mergeArgsSyntax = require('Module:Arguments').mergeArgsSyntax local yesno, string, table, lu = multiRequire('Module:Yesno', 'Module:String', 'Module:Table','Module:LibraryUtil')

local p = {}

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

local function createBox(...) local variant, content, options = checkArgs({ 'string', 'table', { 'table', nilOk=true } }, ...) options = options or {} options.top = options.top or {} if variant == 'small' then local separator = mw.html.create('div') :css{ ["border-bottom"] = "1px solid #555"; ["padding"] = "0 3px"; ["clear"] = "right"; }			:css(options.top.style or {}) :wikitext(string.parseDualArg(content.top)) 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%"			}) :node(separator) :wikitext(				options.listTable and string.wrapHtml(table.map(content.list, function(v)					return string.wrapHtml(v, 'li', options.listRow)				end), 'ul', options.list) or string.parseDualArg(content.body)			) return box elseif variant == 'medium' then local box = mw.html.create('table') :attr({ 				cellpadding=0;				cellspacing=0;				class="wikitable";			}) :css{ ["float"] = "right"; ["width"] = "240px"; ["margin"] = "0.1em 0 0.5em 0.25em"; ["padding"] = "4px"; }		local row = box:tag('tr') if content.image then row:tag('td') :attr({ 						style="border-right:0; padding:0 12px", 						class=type(options.top.class) == 'table' and table.concat(options.top.class) or options.top.class,					}) :css(options.top.style) :wikitext(string.makeImage(content.image, { size=content.imageSize or 30 })) :done end row:tag('td') :attr({					style="border-left:0; width:100%; padding:0 5px 0 0;"				}) :wikitext(options.listTable and content.top..string.wrapHtml(table.map(content.list, function(v)					return string.wrapHtml(v, 'li', { style=options.listRow.style, class=options.listRow.style })				end), 'ul', { style=options.list.style, class=options.list.style }) or string.parseDualArg(content.body)) :done row:done return box end end p.createBox = createBox function p.luaBox(frame) local args = getArgs(frame) local list = {} local l = mergeArgsSyntax(args) for i = 1,#l,1 do		list[#list+1] = string.wrapTag(			{				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" })), ')',			}, 'li'		) 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(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 box = createBox('small', {		top=string.makeLink('Template:Shortcut', { , 'Shortcut', #list > 1 and "s" or "",  }),		list=list,	}, { 		listTable=true,		listRow={			style={				margin=0,			},		},		list={			style={				margin=0,				['list-style-type']="none",			},		},	})

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 ret = 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 for i = 1, #list, 1 do		local title = titles['title'..i] ~= "" and titles['title'..i] or nil local 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 local function createTitle(i) return mw.title.new(table.concat{ pagename, "/Archive ", i }) end local titles = {} local currentTitle = createTitle(i) while currentTitle.exists do		table.push(titles, currentTitle) i = i + 1 currentTitle = createTitle(i) 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