Edición de «Módulo:Format link»
Puedes deshacer la edición. Antes de deshacer la edición, comprueba la siguiente comparación para verificar que realmente es lo que quieres hacer, y entonces publica los cambios para así efectuar la reversión.
Revisión actual | Tu texto | ||
Línea 11: | Línea 11: | ||
local checkTypeForNamedArg = libraryUtil.checkTypeForNamedArg | local checkTypeForNamedArg = libraryUtil.checkTypeForNamedArg | ||
local mArguments -- lazily initialise [[Module:Arguments]] | local mArguments -- lazily initialise [[Module:Arguments]] | ||
local yesno -- lazily initialise [[Module:Yesno]] | local yesno -- lazily initialise [[Module:Yesno]] | ||
Línea 30: | Línea 29: | ||
-- Removes the initial colon from a string, if present. | -- Removes the initial colon from a string, if present. | ||
return s:match('^:?(.*)') | return s:match('^:?(.*)') | ||
end | |||
local function italicize(s) | |||
-- Italicize a string. | |||
return '<i>' .. s .. '</i>' | |||
end | end | ||
local function maybeItalicize(s, shouldItalicize) | local function maybeItalicize(s, shouldItalicize) | ||
-- | -- italicize s if s is a string and the shouldItalicize parameter is true. | ||
if s and shouldItalicize then | if s and shouldItalicize then | ||
return | return italicize(s) | ||
else | else | ||
return s | return s | ||
Línea 78: | Línea 82: | ||
section = section, | section = section, | ||
display = display, | display = display, | ||
} | } | ||
end | end | ||
Línea 111: | Línea 93: | ||
yesno = require('Module:Yesno') | yesno = require('Module:Yesno') | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
local link = args[1] | local link = args[1] | ||
if not link then | |||
if not | return | ||
return | '<strong class="error">'.. | ||
'Error: no link specified ([[Template:Format link#Errors|help]]).'.. | |||
'</strong>' | |||
end | end | ||
return p._formatLink{ | return p._formatLink{ | ||
link = link, | link = link, | ||
display = args[2] | display = args[2], | ||
italicizePage = yesno(args.italicizepage), | italicizePage = yesno(args.italicizepage), | ||
italicizeSection = yesno(args.italicizesection), | italicizeSection = yesno(args.italicizesection), | ||
Línea 130: | Línea 112: | ||
-- The formatLink export function, for use in modules. | -- The formatLink export function, for use in modules. | ||
checkType('_formatLink', 1, options, 'table') | checkType('_formatLink', 1, options, 'table') | ||
checkTypeForNamedArg('_formatLink', 'link', options.link, 'string', false) | |||
checkTypeForNamedArg( | |||
'_formatLink', | |||
'display', | |||
options.display, | |||
'string', | |||
true | |||
) | |||
checkTypeForNamedArg( | |||
'_formatLink', | |||
'italicizePage', | |||
options.italicizePage, | |||
'boolean', | |||
true | |||
) | |||
checkTypeForNamedArg( | |||
'_formatLink', | |||
'italicizeSection', | |||
options.italicizeSection, | |||
'boolean', | |||
true | |||
) | |||
checkTypeForNamedArg( | |||
'_formatLink', | |||
'categorizeMissing', | |||
options.categorizeMissing, | |||
'string', | |||
true | |||
) | |||
local parsed = parseLink(options.link) | local parsed = parseLink(options.link) | ||
Línea 154: | Línea 147: | ||
local category = '' | local category = '' | ||
--Test if page exists if a diagnostic category is specified | |||
-- Test if page exists if a diagnostic category is specified | |||
if catMissing and (mw.ustring.len(catMissing) > 0) then | if catMissing and (mw.ustring.len(catMissing) > 0) then | ||
local title = nil | local title = nil | ||
if parsed.page then title = mw.title.new(parsed.page) end | if parsed.page then title = mw.title.new(parsed.page) end | ||
if title and (not title.isExternal) | if title and (not title.isExternal) and (not title.exists) then | ||
category = mw.ustring.format('[[Category:%s]]', catMissing) | |||
end | end | ||
end | |||
-- Deal with the case where we don't have to pipe the link | |||
if not display and not parsed.section and not options.italicizePage then | |||
return mw.ustring.format('[[:%s]]%s', parsed.link, category) | |||
end | end | ||
-- | -- Find the display text for piped links | ||
if parsed. | if not display then | ||
local page = maybeItalicize(parsed.page, options.italicizePage) | |||
local section = maybeItalicize(parsed.section, options.italicizeSection) | |||
if not page then | |||
display = mw.ustring.format('§ %s', section) | |||
elseif section then | |||
display = mw.ustring.format('%s § %s', page, section) | |||
else | |||
display = page | |||
end | |||
end | end | ||
return mw.ustring.format('[[:%s|%s]]%s', parsed.link, display, category) | |||
end | end | ||