Difference between revisions 51791 and 51792 on wikimaniawiki

-- This module implements {{documentation}}.

-- Get required modules.
local getArgs = require('Module:Arguments').getArgs
local htmlBuilder = require('Module:HtmlBuilder')
local messageBox = require('Module:Message box')

-- Get the config table.
(contracted; show full)		if subpage == message('sandboxSubpage', 'string') or subpage == message('testcasesSubpage', 'string') then
			return title.baseText
		else
			return title.text
		end
	end


	function envFuncs.docTitle()
		local title = env.title
		local docname = args[1] -- Other docname, if fed.
		local docspace = env.docspace
		local templatePage = env.templatePage
		local docpage
		if docname then
			docpage = docname
		else
			local namespace = docspace or title.nsText
			local pagename = templatePage or title.text
			docpage = namespace .. ':' .. pagename .. '/' .. message('docSubpage', 'string')
		end
		return mw.title.new(docpage)
	end

	function env:grab(key)
		local success, val = pcall(function() return self[key] end)
		return success, val
	end

	return env
end	

(contracted; show full)			lspan.wikitext(makeUrlLink(docTitle:fullUrl{action = 'edit', preload = preload}, message('createLinkDisplay', 'string')))
		end
	end

	return tostring(sbox)
end


function p.makeStartBoxLinksData(args, env)
	local data = {}
	-- Get title objects.
	local titleSuccess, title = env:grab('title')
	if titleSuccess then
		data.title = title
	else
		return err(title)
	end
	local docTitleSuccess, docTitle = env:grab('docTitle')
	if docTitleSuccess then
		data.docTitle = docTitle
	else
		return err(docTitle)
	end
	-- View, display, edit, and purge links if /doc exists.
	data.viewLinkDisplay = message('viewLinkDisplay', 'string')
	data.editLinkDisplay = message('editLinkDisplay', 'string')
	data.historyLinkDisplay = message('historyLinkDisplay', 'string')
	data.purgeLinkDisplay = message('purgeLinkDisplay', 'string')
	-- Create link if /doc doesn't exist.
	local preload = args[message('preloadArg', 'string')]
	if not preload then
		if env.subjectSpace == 6 then -- File namespace
			preload = message('fileDocpagePreload', 'string')
		else
			preload = message('docpagePreload', 'string')
		end
	end
	data.preload = preload
	data.createLinkDisplay = message('createLinkDisplay', 'string')
	return data
end

function p.renderStartBoxLinks(data)
	-- Render the [view][edit][history][purge] or [create] links.
	local ret
	local docTitle = data.docTitle
	local title = data.title
	if docTitle.exists then
		local viewLink = makeWikilink(docpage, data.viewLinkDisplay)
		local editLink = makeUrlLink(docTitle:fullUrl{action = 'edit'}, data.editLinkDisplay)
		local historyLink = makeUrlLink(docTitle:fullUrl{action = 'history'}, data.historyLinkDisplay)
		local purgeLink = makeUrlLink(title:fullUrl{action = 'purge'}, data.purgeLinkDisplay)
		ret = '[%s] [%s] [%s] [%s]'
		ret = ret:gsub('%[', '[') -- Replace square brackets with HTML entities.
		ret = ret:gsub('%]', ']')
		ret = mw.ustring.format(ret, viewLink, editLink, historyLink, purgeLink)
	else
		lspan.wikitext(makeUrlLink(docTitle:fullUrl{action = 'edit', preload = data.preload}, data.createLinkDisplay))
	end
end

function p.renderStartBox(data)
	-- Renders the start box html.
	local sbox = htmlBuilder.create('div')
	sbox
		.css('padding-bottom', '3px')
		.css('border-bottom', '1px solid #aaa')
		.css('margin-bottom', '1ex')
		.newline()
(contracted; show full)
		local sort = (title.namespace == 0 and message('strangeUsageCategoryMainspaceSort', 'string') or '') .. title.prefixedText -- Sort on namespace.
		ret = ret .. makeCategoryLink(message('strangeUsageCategory', 'string'), sort)
	end
	return ret
end

return p