Module:Hatnote: Difference between revisions

From Chalo Chatu, Zambia online encyclopedia
m 1 revision imported
No edit summary
 
Line 21: Line 21:


local function getArgs(frame)
local function getArgs(frame)
-- Fetches the arguments from the parent frame. Whitespace is trimmed and
-- blanks are removed.
mArguments = require('Module:Arguments')
mArguments = require('Module:Arguments')
return mArguments.getArgs(frame, {parentOnly = true})
return mArguments.getArgs(frame, {parentOnly = true})
Line 28: Line 26:


local function removeInitialColon(s)
local function removeInitialColon(s)
-- Removes the initial colon from a string, if present.
return s:match('^:?(.*)')
return s:match('^:?(.*)')
end
end


function p.defaultClasses(inline)
function p.defaultClasses(inline)
-- Provides the default hatnote classes as a space-separated string; useful
return (inline == 1 and 'hatnote-inline' or 'hatnote') .. ' navigation-not-searchable'
-- for hatnote-manipulation modules like [[Module:Hatnote group]].
return
(inline == 1 and 'hatnote-inline' or 'hatnote') .. ' ' ..
'navigation-not-searchable'
end
end


function p.disambiguate(page, disambiguator)
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', 1, page, 'string')
checkType('disambiguate', 2, disambiguator, 'string', true)
checkType('disambiguate', 2, disambiguator, 'string', true)
Line 50: Line 41:


function p.findNamespaceId(link, removeColon)
function p.findNamespaceId(link, removeColon)
-- 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 false.
checkType('findNamespaceId', 1, link, 'string')
checkType('findNamespaceId', 1, link, 'string')
checkType('findNamespaceId', 2, removeColon, 'boolean', true)
checkType('findNamespaceId', 2, removeColon, 'boolean', true)
Line 70: Line 57:


function p.makeWikitextError(msg, helpLink, addTrackingCategory, title)
function p.makeWikitextError(msg, helpLink, addTrackingCategory, title)
-- 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', 1, msg, 'string')
checkType('makeWikitextError', 2, helpLink, 'string', true)
checkType('makeWikitextError', 2, helpLink, 'string', true)
yesno = require('Module:Yesno')
yesno = require('Module:Yesno')
title = title or mw.title.getCurrentTitle()
title = title or mw.title.getCurrentTitle()
-- Make the help link text.
 
local helpText
local helpText
if helpLink then
if helpLink then
Line 85: Line 68:
helpText = ''
helpText = ''
end
end
-- Make the category text.
 
local category
local category
if not title.isTalkPage -- Don't categorise talk pages
if not title.isTalkPage
and title.namespace ~= 2 -- Don't categorise userspace
and title.namespace ~= 2
and yesno(addTrackingCategory) ~= false -- Allow opting out
and yesno(addTrackingCategory) ~= false
then
then
category = 'Hatnote templates with errors'
category = 'Hatnote templates with errors'
Line 100: Line 83:
category = ''
category = ''
end
end
return mw.ustring.format(
return mw.ustring.format(
'<strong class="error">Error: %s%s.</strong>%s',
'<strong class="error">Error: %s%s.</strong>%s',
Line 110: Line 94:
local curNs = mw.title.getCurrentTitle().namespace
local curNs = mw.title.getCurrentTitle().namespace
p.missingTargetCat =
p.missingTargetCat =
--Default missing target category, exported for use in related modules
((curNs ==  0) or (curNs == 14)) and
((curNs ==  0) or (curNs == 14)) and
'Articles with hatnote templates targeting a nonexistent page' or nil
'Articles with hatnote templates targeting a nonexistent page' or nil


function p.quote(title)
function p.quote(title)
--Wraps titles in quotation marks. If the title starts/ends with a quotation
--mark, kerns that side as with {{-'}}
local quotationMarks = {
local quotationMarks = {
["'"]=true, ['"']=true, ['“']=true, ["‘"]=true, ['”']=true, ["’"]=true
["'"]=true, ['"']=true, ['“']=true, ["‘"]=true, ['”']=true, ["’"]=true
}
}
local quoteLeft, quoteRight = -- Test if start/end are quotation marks
local quoteLeft, quoteRight =
quotationMarks[string.sub(title,  1,  1)],
quotationMarks[string.sub(title,  1,  1)],
quotationMarks[string.sub(title, -1, -1)]
quotationMarks[string.sub(title, -1, -1)]
Line 133: Line 114:
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Hatnote
-- Hatnote
--
-- Produces standard hatnote text. Implements the {{hatnote}} template.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
p[''] = function (frame) return p.hatnote(frame:newChild{ title = "Template:Hatnote" }) end
 
p[''] = function (frame)
return p.hatnote(frame:newChild{ title = "Template:Hatnote" })
end


function p.hatnote(frame)
function p.hatnote(frame)
Line 172: Line 154:
:wikitext(s)
:wikitext(s)


return mw.getCurrentFrame():extensionTag{
return tostring(hatnote)
name = 'templatestyles', args = { src = 'Module:Hatnote/styles.css' }
} .. tostring(hatnote)
end
end


return p
return p