Open main menu

EUSwiki β

Changes

Module:Main

212 bytes removed, 19:34, 28 June 2016
Removed extraclasses option; those classes appear to be deprecated
local mHatnote = require('Module:Hatnote')
local mTableTools -- lazily initialisemHatlist = require('Module:Hatnote list')
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})
for k, v in pairs(args) do
if type(k) == 'number' then
local display = args['label ' .. k] or args['l' .. tostring(k)] local page = {display and string.format('%s|%s', string.gsub(v, '|.*$', ''), display}) or v pages[k#pages + 1] = page
end
end
if #pages = mTableTools= 0 and mw.title.getCurrentTitle().compressSparseArraynamespace == 0 then return mHatnote.makeWikitextError(pages 'no page names specified', 'Template:Main#Errors', args.category ) end
local options = {
selfref = args.selfref
}
return p._main(pages, options, unpack(pages))
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()
local firstPageTable if #args == pages[1] local firstPage if firstPageTable 0 then firstPage args = firstPageTable[1]{currentTitle.text} end else local firstPage = currentTitlestring.text firstPageTable = {firstPage} pagesgsub(args[1] = firstPageTable end, '|.*$', '')
-- Find the pagetype.
local firstPageNs pageType = mHatnote.findNamespaceId(firstPage) local pagetype = firstPageNs == 0 and 'article' or 'page' 
-- Make the formatted link text
local links list = mHatnotemHatlist.formatPageTablesandList(unpack(pages)) links = mw.text.listToText(linksargs, true
-- Build the text.
local isPlural = #pages args > 1 local currentNs mainForm local curNs = currentTitle.namespace local isCategoryNamespace if (curNs == currentNs - currentNs % 2 14) or (curNs == 14 local stringToFormat if isCategoryNamespace 15) then--category/talk namespaces if mainForm = isPlural thenand stringToFormat = 'The main %ss for this' .. ' [[Wikipedia:Categorization|category]] are %s' else or stringToFormat = 'The main %s for this' .. ' [[Wikipedia:Categorization|category]] is %s' end
else
if mainForm = isPlural then stringToFormat = and 'Main %ss: %s' else stringToFormat = or 'Main %s: %s' end
end
local text = string.format(stringToFormatmainForm, pagetypepageType, linkslist
-- Process the options and pass the text to the _rellink function in
-- [[Module:Hatnote]].
options = options or {}
local hnOptions = {
extraclasses = 'relarticle mainarticle',
selfref = options.selfref
}
Anonymous user