Module:See also

From Wikipedia, the free encyclopedia
Jump to: navigation, search
Module documentation[view] [edit] [history] [purge]

This module produces a "See also: a, b, and c" link. It implements the {{see also}} template.

Usage from wikitext[edit]

This module cannot be used directly from #invoke. Instead, it can only be used through the {{see also}} template. Please see the template page for documentation.

Usage from other Lua modules[edit]

Load the module:

local mSeealso = require('Module:See also')

You can then use the _seealso function like this:

mSeealso._seeAlso(args, options)

The args parameter should be a table of page link strings; if they use custom display values, each string should be preprocessed into a single piped string (e.g. page|display value). Links specifying a section are automatically formatted as page § section, rather than the MediaWiki default of page#section, if no custom display value is set.

The options variable is an optional configuration table. The following field is recognised:

  • selfref - set to true to flag the output as a self-reference to Wikipedia. (See the {{selfref}} template for more details on self-references.)

Example 1[edit]

mSeealso._seeAlso({'A'})

Produces:

<div role="note" class="hatnote">See also: [[A]]</div>

Displays as:

Example 2[edit]

mSeealso._seeAlso({'A', 'B', 'C#D'})

Produces:

<div role="note" class="hatnote">See also: [[A]], [[B]], and [[C#D|C § D]]</div>

Displays as:

Example 3[edit]

mSeealso._seeAlso({'A|the letter "A"', 'B|the letter "B"', 'C|the letter "C"'}, {selfref = true})

Produces:

<div role="note" class="hatnote selfref">See also: [[A|the letter "A"]], [[B|the letter "B"]], and [[C|the letter "C"]]</div>

Displays as:

Technical details[edit]

This module uses Module:Hatnote to format the hatnote text, Module:Hatnote list to process the list of links, and Module:Arguments to fetch the arguments from wikitext.

--[[
-- This module produces a "See also: a, b, and c" link. It implements the
-- template {{see also}}.
--]]

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

function p.seeAlso(frame)
	mArguments = require('Module:Arguments')
	local args = mArguments.getArgs(frame, {parentOnly = true})
	local pages = {}
	for k, v in pairs(args) do
		if type(k) == 'number' then
			local display = args['label ' .. k] or args['l' .. k]
			local page = display and
				string.format('%s|%s', string.gsub(v, '|.*$', ''), display) or v
			pages[#pages + 1] = page
		end
	end
	if not pages[1] then
		return mHatnote.makeWikitextError(
			'no page names specified',
			'Template:See also#Errors',
			args.category
		)
	end
	local options = {
		selfref = args.selfref
	}
	return p._seeAlso(pages, options)
end

function p._seeAlso(args, options)
	checkType('_seeAlso', 1, args, 'table')
	checkType('_seeAlso', 2, options, 'table', true)
	options = options or {}
	local list = mHatlist.andList(args, true)
	local text = string.format('See also: %s', list)
	-- Pass options through.
	local hnOptions = {
		selfref = options.selfref
	}
	return mHatnote._hatnote(text, hnOptions)
end

return p