Module:Hatnote: Difference between revisions
Content deleted Content added
add type check for makeWikitextError |
make makeWikitextError use Module:Yesno to parse the demo parameter, and remove underscores from all the function names, as that's normally done for private functions, whereas these are public |
||
Line 10:
local checkType = libraryUtil.checkType
local mArguments -- lazily initialise [[Module:Arguments]]
local yesno -- lazily initialise [[Module:Yesno]]
local p = {}
Line 29 ⟶ 30:
end
function p.
-- Finds the namespace id (namespace number) of a link or a pagename. This
-- 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 true.
checkType('
checkType('
if removeColon ~= false then
link = removeInitialColon(link)
Line 49 ⟶ 50:
end
function p.
-- Formats a list of pages using formatLink and returns it as an array. Nil
-- values are not allowed.
Line 55 ⟶ 56:
local ret = {}
for i, page in ipairs(pages) do
ret[i] = p.
end
return ret
end
function p.
-- Takes a list of page/display tables and returns it as a list of
-- formatted links. Nil values are not allowed.
Line 66 ⟶ 67:
local links = {}
for i, t in ipairs(pages) do
checkType('
local link = t[1]
local display = t[2]
links[i] = p.
end
return links
end
function p.
-- Formats an error message to be returned to wikitext. If demo is not nil
-- or false, no error category is added.
checkType('
yesno = require('Module:Yesno')
local errorCategory = 'Hatnote templates with errors'
local errorCategoryLink
if yesno(demo) then
errorCategoryLink = string.format(
'[[%s:%s]]',
Line 110 ⟶ 111:
local display = args[2]
if not link then
return p.
end
return p.
end
function p.
-- Find whether we need to use the colon trick or not. We need to use the
-- colon trick for categories and files, as otherwise category links
-- categorise the page and file links display the file.
checkType('
checkType('
link = removeInitialColon(link)
local namespace = p.
local colon
if namespace == 6 or namespace == 14 then
Line 157 ⟶ 158:
local options = {}
if not s then
return p.
end
options.extraclasses = args.extraclasses
|