1,536
edits
(don't categorise talk namespaces) |
m (49 revisions imported from templatewiki:Module:Hatnote) |
||
(21 intermediate revisions by 10 users not shown) | |||
Line 3:
-- --
-- This module produces hatnote links and links to related articles. It --
-- implements the {{hatnote}} and {{format
--
--------------------------------------------------------------------------------
Line 11:
local mArguments -- lazily initialise [[Module:Arguments]]
local yesno -- lazily initialise [[Module:Yesno]]
local p = {}
Line 35 ⟶ 34:
-- function will not work if the link is enclosed in double brackets. Colons
-- are trimmed from the start of the link by default. To skip colon
-- trimming, set the removeColon parameter to
checkType('findNamespaceId', 1, link, 'string')
checkType('findNamespaceId', 2, removeColon, 'boolean', true)
Line 76 ⟶ 75:
end
function p.makeWikitextError(msg,
-- Formats an error message to be returned to wikitext. If
-- addTrackingCategory is not false after being returned from
-- [[Module:Yesno]], and if we are not on a talk page, a tracking category
-- is added.
checkType('makeWikitextError', 1, msg, 'string')
checkType('makeWikitextError', 2, helpLink, 'string', true)
yesno = require('Module:Yesno')
title = title or mw.title.getCurrentTitle()
-- Make the help link text.
local errorCategory = 'Hatnote templates with errors'▼
local errorCategoryLink = string.format(▼
if helpLink then
'[[%s:%s]]',▼
helpText = ' ([[' .. helpLink .. '|help]])'
mw.site.namespaces[14].name,▼
else▼
end
--
local category
if not title.isTalkPage and yesno(addTrackingCategory) ~= false then
▲ '[[%s:%s]]',
▲ mw.site.namespaces[14].name,
category
)
else
end
return string.format(
'<strong class="error">Error: %s%s.</strong>%s',
msg,
helpText,
category
)
end
function p.disambiguate(page, disambiguator)
-- Formats a page title with a disambiguation parenthetical,
-- i.e. "Example" → "Example (disambiguation)".
checkType('disambiguate', 1, page, 'string')
checkType('disambiguate', 2, disambiguator, 'string', true)
disambiguator = disambiguator or 'disambiguation'
return string.format('%s (%s)', page, disambiguator)
end
Line 117 ⟶ 134:
local display = args[2]
if not link then
return p.makeWikitextError(
'no link specified',
'Template:Format hatnote link#Errors',
args.category
)
end
return p._formatLink(link, display)
Line 123 ⟶ 144:
function p._formatLink(link, display)
checkType('_formatLink', 1, link, 'string')
checkType('_formatLink', 2, display, 'string', true)
-- Remove the initial colon for links where it was specified manually.
link = removeInitialColon(link)
-- Find whether a faux display value has been added with the {{!}} magic
▲ local colon
-- word.
if not display then
▲ colon = ':'
local prePipe, postPipe = link:match('^(.-)|(.*)$')
▲ else
link = prePipe or link
▲ colon = ''
display = postPipe
end
Line 141 ⟶ 162:
local page, section = link:match('^(.-)#(.*)$')
if page then
display = page .. ' §
end
end
Line 147 ⟶ 168:
-- Assemble the link.
if display then
return string.format(
'[[:%s|%s]]',
string.gsub(link, '|(.*)$', ''), --display overwrites manual piping
display
)
else
return string.format('[[
end
end
Line 164 ⟶ 189:
local options = {}
if not s then
return p.makeWikitextError(
'no text specified',
'Template:Hatnote#Errors',
args.category
)
end
options.extraclasses = args.extraclasses
Line 174 ⟶ 203:
checkType('_hatnote', 1, s, 'string')
checkType('_hatnote', 2, options, 'table', true)
options = options or {}
local classes = {'hatnote', 'navigation-not-searchable'}
local extraclasses = options.extraclasses
local selfref = options.selfref
Line 184 ⟶ 214:
end
return string.format(
'<div role="note" class="%s">%s</div>',
table.concat(classes, ' '),
s
|