Module:Main: Difference between revisions

m
16 revisions imported from templatewiki:Module:Main
(update comment)
m (16 revisions imported from templatewiki:Module:Main)
 
(13 intermediate revisions by 5 users not shown)
Line 9:
 
local mHatnote = require('Module:Hatnote')
mTableToolslocal mHatlist = require('Module:TableToolsHatnote list')
local mTableTools -- lazily initialise
local mArguments -- lazily initialise
 
local p = {}
 
function p.main(frame)
mTableTools = require('Module:TableTools')
mArguments = require('Module:Arguments')
local args = mArguments.getArgs(frame, {parentOnly = true})
Line 21 ⟶ 19:
for k, v in pairs(args) do
if type(k) == 'number' then
local display = args['label ' .. k] or args['l' .. tostring(k)]
local page = {v, display} and
string.format('%s|%s', string.gsub(v, '|.*$', ''), display) or v
pages[k#pages + 1] = page
end
end
if #pages == 0 and mw.title.getCurrentTitle().namespace == 0 then
pages = mTableTools.compressSparseArray(pages)
return mHatnote.makeWikitextError(
return p._main(unpack(pages))
'no page names specified',
'Template:Main#Errors',
args.category
)
end
local pagesoptions = {...}
selfref = args.selfref
}
return p._main(unpack(pages), options)
end
 
function p._main(...args, options)
-- Get the list of pages. If no first page was specified we use the current
-- page name.
local pages = {...}
local currentTitle = mw.title.getCurrentTitle()
if #args == 0 then args = {currentTitle.text} end
local firstPageTable = pages[1]
local firstPage = string.gsub(args[1], '|.*$', '')
if firstPageTable then
firstPage = firstPageTable[1]
else
firstPage = currentTitle.text
firstPageTable = {firstPage}
pages[1] = firstPageTable
end
 
-- Find the pagetype.
local firstPageNspageType = mHatnote._findNamespaceIdfindNamespaceId(firstPage, true) == 0 and 'article' or 'page'
local pagetype = firstPageNs == 0 and 'article' or 'page'
 
-- Make the formatted link text
list = mHatlist.andList(args, true)
local links = mHatnote._formatPageTables(pages)
links = mw.text.listToText(links)
 
-- Build the text.
local isPlural = #pagesargs > 1
local mainForm
local currentNs = currentTitle.namespace
firstPage local curNs = currentTitle.textnamespace
local isCategoryNamespace = currentNs - currentNs % 2 == 14
if (curNs == 14) or (curNs == 15) then --category/talk namespaces
local stringToFormat
ifmainForm = isPlural thenand
if isCategoryNamespace then
'The main %ss for this [[Help:Categories|category]] are %s'
if isPlural then
or
stringToFormat = 'The main %ss for this'
.. 'The main %s for this [[WikipediaHelp:CategorizationCategories|category]] areis %s'
else
stringToFormat = 'The main %s for this'
.. ' [[Wikipedia:Categorization|category]] is %s'
end
else
ifmainForm = isPlural thenand 'Main %ss: %s' or 'Main %s: %s'
stringToFormat = 'Main %ss: %s'
else
stringToFormat = 'Main %s: %s'
end
end
local text = string.format(stringToFormatmainForm, pagetypepageType, linkslist)
-- Process the options and pass the text to the _rellink function in
 
-- Pass the text to the _rellink function in [[Module:Hatnote]].
options = options or {}
local extraclasses = 'relarticle mainarticle'
local hnOptions = {
return mHatnote._rellink(text, extraclasses)
selfref = options.selfref
}
return mHatnote._rellink_hatnote(text, extraclasseshnOptions)
end