Jump to content

Module:For related page

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Nihiltres (talk | contribs) at 23:35, 26 June 2016 (A prototype…). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

local mFor = require('Module:For')
local mArguments = require('Module:Arguments')
local p = {}

function p.forOutline (frame)
	local args = mArguments.getArgs(frame)
	local target
	if args[1] then
		target = args[1]
	else
		local title = mw.title.getCurrentTitle().text
		local titles = {
			title,
			mw.ustring.lower(mw.ustring.sub(title, 1, 1)) .. mw.ustring.sub(title, 2)
		}
		local outlineForms = {
			'Outline of %s',
			'Outline of %ss',
			'Outline of %s topics',
			'Outline of %s-related topics',
			'List of %s topics',
			'List of %s-related topics',
			'List of topics related to the %s'
		}
		for k, v in pairs(outlineForms) do
			for i, j in pairs(titles) do
				local lookup = string.format(v, j)
				if mw.title.new(lookup, 0).exists then
					target = lookup
					break
				end
			end
			if target then break end
		end
		target = target or string.format(outlineForms[1], title)
	end

	return mFor._For({'a topical guide to this subject', target})
end

return p