Jump to content

Module:Subject page header

From Festipedia, hosted by the FR Heritage Group

local p = {}

p.main = function(frame)
	local title = mw.title.getCurrentTitle()
	
	-- Bail out quickly on main namespace
	if title.namespace == 0 then
		return ''
	end

	local pageName = title.fullText
	
	-- Optimization: first check page name suffix before looking up content model
	local isJsonPage = pageName:len() > 5 and pageName:sub(-5) == ".json" and title.contentModel == 'json'

	if isJsonPage then
		local Hatnote = require('Module:Hatnote')

		local docPageName = pageName .. '/doc'
		local docTitle = mw.title.new(docPageName)
		local content = ''
		if docTitle.exists then
			content = 
				'<hr>' .. 
				Hatnote._hatnote(
					'The following documentation is located at [['..docPageName..']].<span class="mw-editsection-like plainlinks">[ [[Special:EditPage/'..docPageName..'|edit]] ] [ [[Special:PageHistory/'..docPageName..'|history]] ]</span>'
				) ..
				frame:preprocess(docTitle.content)
		else 
			content = Hatnote._hatnote('Documentation for this JSON page can be created at the [['..docPageName..'|/doc]] subpage.')
		end

		return '<div class="mw-parser-output">' .. content .. '</div>'
	end
	return ''
end

return p