[go: up one dir, main page]

Jump to content

Module:Portal header

Permanently protected module
From Wikisource

require('strict')

local p = {}

local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')
local construct_header = require('Module:Header structure').construct_header
local portal_class = require('Module:Portal class')._portal_class
local portal_parent = require('Module:Portal parent').portal_parent

function p._portal_header(args)
	local current_title = mw.title.getCurrentTitle()
	local namespace = args.namespace or current_title.nsText
	local cats = {}
	
	local categorize = not yesno(args.nocat) or args.forcecat == 'forced' or (yesno(args.forcecat) ~= false and namespace == 'Portal')
	
	args.header_class = 'wst-portal-header'
	args.main_class = 'wst-portal-header-mainblock ws-header ws-noexport noprint'
	args.main_title = args.title or current_title.subpageText
	
	if not yesno(args.noparent) then
		if args.parent then
			-- use the explicit parent
			args.previous = 'Parent portal: [[Portal:' .. args.parent .. '|' .. args.parent .. ']]'
			-- tracking cat
			if categorize then
				table.insert(cats, '[[Category:' .. 'Portals linking to a parent' .. ']]')
			end
		else
			args.previous = tostring(mw.html.create('div'):addClass('wst-portal-parentlink'):wikitext(portal_parent(args)))
		end
	end
	
	args.notes_class = 'wst-portal-header-notes'
	
	if not yesno(args.noclass) then
		args.notes_left_content = portal_class(args)
	end
	
	if categorize then
		if args.shortcut then
			table.insert(cats, '[[Category:' .. 'Portals with shortcuts' .. ']]')
		end

		if args.forcecat ~= 'forced' and current_title.isSubpage then
			table.insert(cats, '[[Category:' .. 'Portal subpages' .. ']]')
		else
			if args.sortkey then
				table.insert(cats, '[[Category:' .. 'Portals|' .. args.sortkey .. ']]')
			else
				table.insert(cats, '[[Category:' .. 'Portals' .. ']]')
			end
			if not yesno(args.reviewed) then
				table.insert(cats, '[[Category:' .. 'Portals needing review' .. ']]')
			end
		end
	end
	args.post_notes = table.concat(cats)
	
	local stylesheet = tostring(mw.html.create('div'):addClass('ws-noexport'):wikitext(mw.getCurrentFrame():extensionTag('templatestyles', '', {src = 'Portal header/styles.css'})))
	
	return stylesheet .. construct_header(args)
end

function p.portal_header(frame)
	return p._portal_header(getArgs(frame))
end

return p