کاربر ناشناس
پودمان:Hatnote: تفاوت میان نسخهها
Undid revision 1062166786 by Matthiaspaul (talk); should be fixed now, and if not, please ping me with examples as I couldn't reproduce the original error
جز (۱ نسخه واردشده) |
(Undid revision 1062166786 by Matthiaspaul (talk); should be fixed now, and if not, please ping me with examples as I couldn't reproduce the original error) |
||
خط ۱۲: | خط ۱۲: | ||
local mArguments -- lazily initialise [[Module:Arguments]] | local mArguments -- lazily initialise [[Module:Arguments]] | ||
local yesno -- lazily initialise [[Module:Yesno]] | local yesno -- lazily initialise [[Module:Yesno]] | ||
local formatLink -- lazily initialise [[Module:Format link]] ._formatLink | |||
local p = {} | local p = {} | ||
خط ۱۸: | خط ۱۹: | ||
-- Helper functions | -- Helper functions | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
p.missingTargetCat = | |||
--Default missing target category, exported for use in related modules | |||
'Articles with hatnote templates targeting a nonexistent page' | |||
local function getArgs(frame) | local function getArgs(frame) | ||
خط ۲۸: | خط ۳۴: | ||
local function removeInitialColon(s) | local function removeInitialColon(s) | ||
-- Removes the initial colon from a string, if present. | -- Removes the initial colon from a string, if present. | ||
return | return s:match('^:?(.*)') | ||
end | end | ||
خط ۴۱: | خط ۴۷: | ||
link = removeInitialColon(link) | link = removeInitialColon(link) | ||
end | end | ||
local namespace = | local namespace = link:match('^(.-):') | ||
if namespace then | if namespace then | ||
local nsTable = mw.site.namespaces[namespace] | local nsTable = mw.site.namespaces[namespace] | ||
خط ۴۹: | خط ۵۵: | ||
end | end | ||
return 0 | return 0 | ||
end | end | ||
خط ۸۸: | خط ۶۹: | ||
local helpText | local helpText | ||
if helpLink then | if helpLink then | ||
helpText = ' ([[' .. helpLink .. '| | helpText = ' ([[' .. helpLink .. '|help]])' | ||
else | else | ||
helpText = '' | helpText = '' | ||
خط ۹۸: | خط ۷۹: | ||
and yesno(addTrackingCategory) ~= false -- Allow opting out | and yesno(addTrackingCategory) ~= false -- Allow opting out | ||
then | then | ||
category = ' | category = 'Hatnote templates with errors' | ||
category = mw.ustring.format( | category = mw.ustring.format( | ||
'[[%s:%s]]', | '[[%s:%s]]', | ||
خط ۱۰۸: | خط ۸۹: | ||
end | end | ||
return mw.ustring.format( | return mw.ustring.format( | ||
'<strong class="error"> | '<strong class="error">Error: %s%s.</strong>%s', | ||
msg, | msg, | ||
helpText, | helpText, | ||
خط ۱۲۰: | خط ۱۰۱: | ||
checkType('disambiguate', 1, page, 'string') | checkType('disambiguate', 1, page, 'string') | ||
checkType('disambiguate', 2, disambiguator, 'string', true) | checkType('disambiguate', 2, disambiguator, 'string', true) | ||
disambiguator = disambiguator or ' | disambiguator = disambiguator or 'disambiguation' | ||
return mw.ustring.format('%s (%s)', page, disambiguator) | return mw.ustring.format('%s (%s)', page, disambiguator) | ||
end | end | ||
خط ۲۶۶: | خط ۱۱۴: | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
local s = args[1] | local s = args[1] | ||
if not s then | if not s then | ||
return p.makeWikitextError( | return p.makeWikitextError( | ||
' | 'no text specified', | ||
' | 'Template:Hatnote#Errors', | ||
args.category | args.category | ||
) | ) | ||
end | end | ||
return p._hatnote(s, { | |||
extraclasses = args.extraclasses, | |||
selfref = args.selfref | |||
}) | |||
end | end | ||
خط ۲۸۳: | خط ۱۳۱: | ||
checkType('_hatnote', 2, options, 'table', true) | checkType('_hatnote', 2, options, 'table', true) | ||
options = options or {} | options = options or {} | ||
local | local inline = options.inline | ||
local | local hatnote = mw.html.create(inline == 1 and 'span' or 'div') | ||
local extraclasses | |||
if type(extraclasses) == 'string' then | if type(options.extraclasses) == 'string' then | ||
extraclasses = options.extraclasses | |||
end | end | ||
hatnote | |||
:attr('role', 'note') | |||
:addClass(inline == 1 and 'hatnote-inline' or 'hatnote') | |||
' | :addClass('navigation-not-searchable') | ||
mw.getCurrentFrame():extensionTag{ | :addClass(extraclasses) | ||
:addClass(options.selfref and 'selfref') | |||
:wikitext(s) | |||
return mw.getCurrentFrame():extensionTag{ | |||
name = 'templatestyles', args = { src = 'Module:Hatnote/styles.css' } | |||
} .. tostring(hatnote) | |||
end | end | ||
return p | return p |