Jump to content

Module:Sandbox

From translatewiki.net

function mw.test(f)-- abbreviation for frame
	local a, c=f.args[1], function(t) return '<code style=color:red;font-weight:bold;background:lime;border-color:blue;border-radius:.4em>the '..t..'</code>' end
	return not a and c'parameter is unspecified' or a=='' and c'parameter is empty' or c('specified parameter is <q>'..a..'</q>')
end
function mw.tl(f) local a, yesno, tn=f.args, require'module:yesno'; tn=a.template~='' and a.template or a[1] 
	if not tn then return "<strong class=error>No page title specified, please specify it as the first parameter or with <q>|template=''page title here</q></strong>"
	elseif not mw.title.new(tn) then local function er(title, colour) return '<abbr title="'..title..'" style="background:'..colour..'">%0</abbr>' end
		return '<strong class=error style=white-space:pre>The title placed is bad, please check the errors that it contains: <q>'..tn
		:gsub('[<>]+', er('less-than and greater-than signs are reserved for parser extension tags/HTML tags', 'pink'))
		:gsub('[{}]+', er('Curly brackets are reserved for {&lbrace;{parameters}&rbrace;} or &lbrace;{templates}&rbrace;', 'pink'))
		:gsub('[%]%[]+', er('Square brackets are reserved for &lbrack;[internal]&rbrack; or [external] links', 'pink'))
		:gsub('|+', er('Vertical bar is reserved for separating parameters', 'pink'))
		:gsub('\t+', er('Tabs are not allowed', 'lightblue'))..'</q></strong>'
	else local o, nw, tag, bb, color, l, b, eb={}, function(t) return f:extensionTag('nowiki', t) end, a.tag~='' and a.tag or 'code', yesno(a.shl) and '</b>' or '',
		yesno(a.shl) and ' style=color:#80c' or '', {(f:callParserFunction('ucfirst', tn:gsub('[_  ]+', ' '))~=mw.title.new(tn).text and '' or 'Template:')..tn}
		l[2], b=yesno(a.shl) and tn:gsub('^([  ]*)(.-)([  ]*)$', function(t1, t2, t3) return t1..'<u'..color..'>'..nw(t2)..'</u>'..t3 end) or tn,
		yesno(a.shl) and '<b'..color..'>' or ''; function eb(t) if yesno(a.shl) and #t>0 then local m, gsub=function(t) return '([^{}]-'..t..').*' end
			function gsub(r) return t:gsub(m'{{=}}', r or ''):gsub(m'=', r or ''):gsub(m'&equals;', r or ''):gsub(m'&#[Xx]3[Dd];', r or ''):gsub(m'&#61;', r or '') end
			if t==gsub() then t=bb..nw(t)..b else gsub=gsub('%1'); local sub=t:gsub('^'..gsub, ''); t=#sub<1 and nw(t) or nw(gsub)..bb..nw(sub)..b end
		end return t end
		for i, v in ipairs(a) do o[a.template~=tn and i or 1+i]=eb(v) end; o[1]='[['..table.concat(l, '|')..']]'
		return '<'..tag..' style=white-space:pre>'..b..'{{'..table.concat(o, '|')..'}}'..bb..'</'..tag..'>'
	end
end
mw['']=function(f)
	local ns, tablens, tablef=mw.site.namespaces, {}, {}-- assign to ns that table to call it shortly and create 2 empty tables to index them and thus sort them
	for num in pairs(ns) do table.insert(tablens, num) end table.sort(tablens)-- obtain all indexes from ns and add them to tablens; sort tablens numerically
	for sort, num in pairs(tablens) do local tableidx={}-- obtain added indexes from created table; create another local table for each index from tablens
		for i, v in pairs(ns[num]) do table.insert(tableidx, i..' ('..tostring(v)..')') end-- obtain all indexes from each index of ns and add them to tableidx
		table.sort(tableidx); tablens[sort]='\n!('..tostring(sort)..') '..num..'\n|'..table.concat(tableidx, '||')--[[ sort alphabetically indexes from obtained index;
		assign each tablens' index its numerical position in parentheses, its own value, all its corresponding indexes and strings concatenated to format a wikitable ]]
	end
	for i, v in pairs(f) do table.insert(tablef, '\n|'..i..'||'..tostring(v)) end table.sort(tablef)--[[ obtain each name and value of all indexes from f and add them to
	tablef with wikitable format strings; sort tablef alphabetically ]] return [[{| class="wikitable mw-collapsible mw-collapsed" style=font-size:69%;white-space:pre
	|+All mw.site.namespaces' indexes and all indexes of each index]]..table.concat(tablens, '\n|-')..'\n|}\n{| class=wikitable\n!index||value\n|+indexes of "f"'..
	table.concat(tablef, '\n|-')..'\n|}'-- return start and end syntaxes of a wikitable along with the indexes of both tables concatenated
end
require'strict' return mw