-- <-- this denotes a comment (two hyphens), from wherever it is to the end of the line
-- we can also do block comments by following the -- by [=[, and close with ]=]
--[=[ eg
this is a block comment
-- it is good to have a nowiki or a pre at the start of the module to stop nonsense wanted pages
-- <nowiki>
-- define a master object
-- you can call it whatever, but convention is to call it 'p' and have it be the first line (though it doesn't have to be)
-- we're going to put functions inside the object
local p = {}
-- imports - other modules that have already been written with useful functions
-- this takes the 'has_content' function from [[Module:Paramtest]], and saves it here as 'hc'
--   this function is basically the same as the #if parser function
local hc = require('Module:Paramtest').has_content
-- the main function, with the parameter frame
-- again, conventionally called 'main' and 'frame', as this is the main function which takes a Frame object
function p.main(frame)
	--[=[ a bit on frames:
	 using a module is done with #invoke
	 the call to #invoke creates a frame, which is passed to the function specified, and you can access arguments there
	     {{#invoke:Sandbox/User:Gaz Lloyd|main|hello|goodbye|name=cheese|number=1337}}    
	 we access the args of this call using `frame.args`
	 which contains an object of form:
	   1 = 'hello',
	   2 = 'goodbye',
	   name = 'cheese',
	   number = '1337'
	 (note that everything is a string, so you'll have to use tonumber(x) to convert that string '1337' to a number 1337, if needed
	 however, this does not allow access to the parameters of a template call, eg
	     {{User:Gaz Lloyd/dpl17/t|hi|bye|name=chedder|number=9001}}
	 to get these, we need the parent frame of the frame passed to the function:
	 this is a very common construct, so expect to see it a lot and understand what it means
	 there are other things that can be done with frames, but we don't need them at the mo
	local args = frame:getParent().args
	-- pagename from the DPL
	local page = args['%PAGE%']
	-- storage variables
	local link = ''
	local str = ''
	-- number of versions
	local i = 1
	if hc(args.version1) or hc(args.id1) then
		-- if version1 is defined, we have a switchfobox, so we have to account for that here
		local ids = {}
		while hc(args['version'..i]) or hc(args['id' .. i]) do
			-- what you actually do here may vary
			-- i'm going to collect all the IDs and put them into a table, in order
			-- this is a library function that adds the second param to the end of the first param (a table)
			table.insert(ids, args['id' .. i])
			-- don't forget to increment i
			i = i + 1
		-- correct total number of versions
		i = i - 1
		--library function to join all the items in the table together, separated by '%20' (urlencode for a space, since this is going into cook's thing)
		link = table.concat(ids, '%20')
		--this one joined by comma space so we can list them as the link text
		str = table.concat(ids, ', ')
		-- not a switchfobox, don't need to do anything special
		str =
		link =
	-- quick bit of error checking
	if str == nil then
		str = ''
	if link == nil or link == '' then
		link="''no id(s) specified''"
		link = string.format('[ %s]', link, str)
	local pagelink = page:gsub(' ', '%%20')
	pagelink = string.format('[ %s]', pagelink, page)
	-- now we construct the table row to be returned
	-- string.format takes the first param (a string) and substitutes %s for each other parameter in order
	-- (often called printf or sprintf in other languages)
	local ret = string.format('\n|-\n| [[%s]]\n| [%s edit]\n| %s<br />%s\n| %s', page, tostring(mw.uri.fullUrl(page, 'action=edit')), pagelink, link, i)
	--return the table row string
	return ret
end --remember to end the function!
-- the object with the functions we defined is returned
-- this should always be the last line - no code that appears after it will be evaluated
return p

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.