Jump to content

Module:Main list: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Codename Lisa (talk | contribs)
Implemented second parameter. Last time it didn't work because I forgot line 27 ("local text"), so the variable "text" became local to the "if" block.
Updated with Module:Hatnote list functionality, support for an indefinite number of parameters, etc.
Line 5: Line 5:


local mHatnote = require('Module:Hatnote')
local mHatnote = require('Module:Hatnote')
local mHatlist = require('Module:Hatnote list')
local mArguments -- lazily initialise
local mArguments -- lazily initialise
local mTableTools -- lazily initialise

local p = {}
local p = {}


function p.mainList(frame)
function p.mainList(frame)
mArguments = require('Module:Arguments')
mArguments = require('Module:Arguments')
mTableTools = require('Module:TableTools')
local args = mArguments.getArgs(frame, {parentOnly = true})
local args = mArguments.getArgs(frame, {parentOnly = true})
local page1 = args[1]
if not args[1] then
local page2 = args[2]
if not page1 then
return mHatnote.makeWikitextError(
return mHatnote.makeWikitextError(
'no page name specified',
'no page name specified',
Line 21: Line 21:
)
)
end
end
return p._mainList(page1, page2)
return p._mainList(mTableTools.compressSparseArray(args))
end
end


function p._mainList(page1, page2)
function p._mainList(args)
local pages = mHatlist.andList(mHatnote.formatPages(unpack(args)))
local text
local text = string.format('For a more comprehensive list, see %s.', pages)
page1 = mHatnote._formatLink(page1)
if page2 then
page2 = mHatnote._formatLink(page2)
text = string.format('For a more comprehensive list, see %s and %s.', page1, page2)
else
text = string.format('For a more comprehensive list, see %s.', page1)
end
return mHatnote._hatnote(text)
return mHatnote._hatnote(text)
end
end

Revision as of 17:21, 9 May 2016

--[[
-- This module produces a "For more details on this topic" link. It implements
-- the {{Main list}} template.
--]]

local mHatnote = require('Module:Hatnote')
local mHatlist = require('Module:Hatnote list')
local mArguments -- lazily initialise
local mTableTools -- lazily initialise
local p = {}

function p.mainList(frame)
	mArguments = require('Module:Arguments')
	mTableTools = require('Module:TableTools')
	local args = mArguments.getArgs(frame, {parentOnly = true})
	if not args[1] then
		return mHatnote.makeWikitextError(
			'no page name specified',
			'Template:Main list#Errors',
			args.category
		)
	end
	return p._mainList(mTableTools.compressSparseArray(args))
end

function p._mainList(args)
	local pages = mHatlist.andList(mHatnote.formatPages(unpack(args)))
	local text = string.format('For a more comprehensive list, see %s.', pages)
	return mHatnote._hatnote(text)
end

return p