وحدة:Broader
This module produces a "for a broader coverage related to this topic" link. It implements the {{broader}} template.
Use from wikitext
This module cannot be used directly from #invoke. Instead, it can only be used through the {{broader}} template. Please see the template page for documentation.
Use from other Lua modules
Load the module:
local mBroader = require('Module:Broader')
You can then use the _broader function like this:
mBroader._broader(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 . (See the {{selfref}} template for more details on self-references.)
{selfref = true}
- Example 1
mBroader._broader('Carbon dioxide data')
Produces:
<div class="hatnote">For a broader coverage related to this topic, see [[Carbon dioxide data]].</div>
Displays as:
- Example 2
mBroader._broader('Carbon dioxide data', 'the physical properties of carbon dioxide')
Produces:
<div class="hatnote">For a broader coverage related to the physical properties of carbon dioxide, see [[Carbon dioxide data]].</div>
Displays as:
- Example 3
mBroader._broader('Lua programming on Wikipedia', 'Wikipedia:Lua', {selfref = true})
Produces:
<div class="hatnote">For a broader coverage related to Lua programming on Wikipedia, see [[Wikipedia:Lua]].</div>
Displays as:
Technical details
This module uses Module:Hatnote to format the hatnote text and Module:Arguments to fetch the arguments from wikitext.
--[[
-- This module produces a رابط "لتغطية أوسع متعلقة بهذا الموضوع". 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 = 'لتغطية أوسع لـ %s، انظر %s.',
defaultTopic = 'هذا الموضوع'
}
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 pairs({'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