Difference between revisions of "Module:Broader"

From blackwiki
Jump to navigation Jump to search
blackwiki>Pppery
(module has been nominated for deletion (dummy edit))
blackwiki>Nihiltres
(New version (after undeletion to make history visible); supports unlimited parameters and uses new named "topic" parameter)
Line 4: Line 4:
 
--]]
 
--]]
 
   
 
   
 +
local mHatlist = require('Module:Hatnote list')
 
local mHatnote = require('Module:Hatnote')
 
local mHatnote = require('Module:Hatnote')
local mArguments -- lazily initialise
+
local mArguments -- lazily initialize
 +
local mTableTools --lazily initialize
  
 
local p = {}
 
local p = {}
 +
 +
local s = { --localizable strings
 +
broaderForm = 'For broader coverage of %s, see %s.',
 +
defaultTopic = 'this topic'
 +
}
  
 
function p.broader(frame)
 
function p.broader(frame)
 
mArguments = require('Module:Arguments')
 
mArguments = require('Module:Arguments')
local args = mArguments.getArgs(frame, {parentOnly = true})
+
mTableTools = require('Module:TableTools')
local page = args[1]
+
local originalArgs = mArguments.getArgs(frame, {parentOnly = true})
local topic = args[2]
+
local args = mTableTools.compressSparseArray(originalArgs)
if not page then
+
-- re-add non-numeric arguments omitted by compressSparseArray
 +
for name in {'category', 'selfref', 'topic'} do
 +
args[name] = originalArgs[name]
 +
end
 +
return p._broader(args)
 +
end
 +
 
 +
function p._broader(args)
 +
if not args[1] then
 
return mHatnote.makeWikitextError(
 
return mHatnote.makeWikitextError(
 
'no page name specified',
 
'no page name specified',
Line 21: Line 36:
 
)
 
)
 
end
 
end
local options = {
+
local list = mHatlist.andList(args, true)
selfref = args.selfref,
+
local topic = args.topic or s.defaultTopic
}
+
local text = string.format(s.broaderForm, topic, list)
return p._broader(page, topic, options)
+
options = {selfref = args.selfref}
end
 
 
 
function p._broader(page, topic, options)
 
page = mHatnote._formatLink(page)
 
topic = topic or 'this topic'
 
local text = string.format('For a broader coverage related to  %s, see %s.', topic, page)
 
options = options or {}
 
 
 
 
return mHatnote._hatnote(text, options)
 
return mHatnote._hatnote(text, options)
 
end
 
end
  
 
return p
 
return p

Revision as of 19:09, 18 April 2020

Implements {{broader}}.


--[[
-- This module produces a "For a broader coverage related to this topic" link. It implements
-- the {{broader}} template.
--]]
 
local mHatlist = require('Module:Hatnote list')
local mHatnote = require('Module:Hatnote')
local mArguments -- lazily initialize
local mTableTools --lazily initialize

local p = {}

local s = { --localizable strings
	broaderForm = 'For broader coverage of %s, see %s.',
	defaultTopic = 'this topic'
}

function p.broader(frame)
	mArguments = require('Module:Arguments')
	mTableTools = require('Module:TableTools')
	local originalArgs = mArguments.getArgs(frame, {parentOnly = true})
	local args = mTableTools.compressSparseArray(originalArgs)
	-- re-add non-numeric arguments omitted by compressSparseArray
	for name in {'category', 'selfref', 'topic'} do
		args[name] = originalArgs[name]
	end
	return p._broader(args)
end

function p._broader(args)
	if not args[1] then
		return mHatnote.makeWikitextError(
			'no page name specified',
			'Template:Broader#Errors',
			args.category
		)
	end
	local list = mHatlist.andList(args, true)
	local topic = args.topic or s.defaultTopic
	local text = string.format(s.broaderForm, topic, list)
	options = {selfref = args.selfref}
	return mHatnote._hatnote(text, options)
end

return p