Module:Portal toolbox

local getArgs = require('Module:Arguments').getArgs

p = {}

local function add_header_row(frame, tbl, text)
	local row = tbl:tag('tr')
	row:tag('th')
		:attr('colspan', '2')
		:wikitext(text)
end

local function edit(frame, pagename)
	return frame:expandTemplate{ title='edit', args={ pagename } }
end

local function add_template_row(frame, tbl, pagename)
	local row = tbl:tag('tr')
	row:tag('td')
		:wikitext(frame:expandTemplate{ title='tl', args={ pagename } })
	row:tag('td')
		:wikitext(edit(frame, 'Template:' .. pagename))
end

local function add_wikilink_row(frame, tbl, pagename, text, right)
	local row = tbl:tag('tr')
	row:tag('td')
		:wikitext('[[' .. pagename .. '|' .. (text or pagename) .. ']]')
	row:tag('td')
		:wikitext(right or edit(frame, pagename))
end

local function add_section(frame, args, tbl, add_section_header, arg_prefix, page_prefix, row_function)
	if row_function == nil then
		row_function = add_wikilink_row
	end
	local nums = {}
	for k, _ in pairs(args) do
		if type(k) == 'string' then
			local num = k:match('^' .. arg_prefix .. '(%d+)$')
			if num then
				table.insert(nums, tonumber(num))
			end
		end
	end
	if #nums == 0 then
		return
	end
	table.sort(nums)
	add_header_row(frame, tbl, add_section_header)
	for _, num in ipairs(nums) do
		local arg_name = arg_prefix .. num
		local arg = args[arg_name]
		local pagename = page_prefix .. arg
		local text = args[arg_name .. 'text']
		local right = args[arg_name .. 'right']
		row_function(frame, tbl, pagename, text or arg, right)
	end
end

local function main(frame)
	local args = getArgs(frame)
	local tbl = mw.html.create('table')
		:cssText('clear: right; float:right; border:1px navy solid;')
	tbl:tag('caption')
		:wikitext('Portal toolbox')
	add_header_row(frame, tbl, 'Main portal page')
	local rootTitle = mw.title.getCurrentTitle().rootPageTitle.subjectPageTitle
	add_wikilink_row(frame, tbl, rootTitle.fullText)
	
	add_section(frame, args, tbl, 'Static subpages', 'static', rootTitle.fullText .. '/')
	add_section(frame, args, tbl, 'Dynamic subpages', 'dynamic', rootTitle.fullText .. '/')
	add_section(frame, args, tbl, 'Templates', 'template', '', add_template_row)
	add_section(frame, args, tbl, 'Other', 'other', '')
	return tbl
end

p.main = main

return p

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.