Module:Details

From validwiki
Jump to: navigation, search

This module produces a "for more details on this topic" link. It implements the {{details}} template.

Use from wikitext

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

Use from other Lua modules

Load the module:

local mDetails = require('Module:Details')

You can then use the _details function like this:

mDetails._details(page, topic, options)

The page variable is the page to be linked to, and is required. The page name can include a section link if desired. If the page includes a section link, it is automatically formatted as page § section, rather than the MediaWiki default of page#section.

The topic variable is a description of the topic, and is optional. The default topic value is "this topic".

The options table can be used to configure the function's output. At current, the only option available is "selfref", which is used when the output is a self-reference to Wikipedia. to set this option, use {selfref = true}. (See the {{selfref}} template for more details on self-references.)

Example 1

mDetails._details('Carbon dioxide data')

Produces:

<div role="note" class="hatnote">For more details on this topic, see [[Carbon dioxide data]].</div>

Displays as:

Lua error: Internal error: The interpreter has terminated with signal "11".

Example 2

mDetails._details('Carbon dioxide data', 'the physical properties of carbon dioxide')

Produces:

<div role="note" class="hatnote">For more details on the physical properties of carbon dioxide, see [[Carbon dioxide data]].</div>

Displays as:

Lua error: Internal error: The interpreter has terminated with signal "11".

Example 3

mDetails._details('Lua programming on Wikipedia', 'Wikipedia:Lua', {selfref = true})

Produces:

<div role="note" class="hatnote selfref">For more details on Lua programming on Wikipedia, see [[Wikipedia:Lua]].</div>

Displays as:

Lua error: Internal error: The interpreter has terminated with signal "11".

Technical details

This module uses Module:Hatnote to format the hatnote text and Module:Arguments to fetch the arguments from wikitext.


Script error: Lua error: Internal error: The interpreter has terminated with signal "11".

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

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

function p.details (frame)
	mArguments = require('Module:Arguments')
	mTableTools = require('Module:TableTools')
	local args = mArguments.getArgs(frame, {parentOnly = true})
	local topic, category = args.topic, args.category
	local options = {selfref = args.selfref}
	args = mTableTools.compressSparseArray(args)
	if #args == 0 then
		return mHatnote.makeWikitextError(
			'no page name specified',
			'Template:Details#Errors',
			category
		)
	end
	return p._details(args, topic, options)
end

function p._details (list, topic, options)
	list = mHatlist.andList(list, true)
	topic = topic or 'this topic'
	local text = string.format('For more details on %s, see %s.', topic, list)
	return mHatnote._hatnote(text, options)
end

return p