Módulo:Artigo principal
A documentação para este módulo pode ser criada na página Módulo:Artigo principal/doc
--[[
Este módulo produz um link para um artigo principal ou artigos principais.
Ele implementa a predefinição {{artigo principal}}.
Se o módulo é usado em categorias ou espaços de discussão de categorias,
produz-se «O artigo principal para esta categoria é xxx».
Do contrário, produz-se «Artigo principal: xxx».
--]]
local mHatnote = require('Módulo:Hatnote')
local mHatlist = require('Módulo:Hatnote list')
local mArguments -- inicializar preguiçosamente
local p = {}
function p.main(frame)
mArguments = require('Módulo:Arguments')
local args = mArguments.getArgs(frame, {parentOnly = true})
local pages = {}
for k, v in pairs(args) do
if type(k) == 'number' then
local display = args['label ' .. k] or args['l' .. k] or args['etiqueta ' .. k] or args['e' .. k]
local page = display and
string.format('%s|%s', string.gsub(v, '|.*$', ''), display) or v
pages[#pages + 1] = page
end
end
if #pages == 0 and mw.title.getCurrentTitle().namespace == 0 then
category = args['category'] or args['categoria']
return mHatnote.makeWikitextError(
'nenhuns nomes de páginas especificados',
'Predefinição:Artigo principal#Erros',
category
)
end
local options = {
selfref = args.selfref
}
return p._main(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 currentTitle = mw.title.getCurrentTitle()
if #args == 0 then args = {currentTitle.text} end
local firstPage = string.gsub(args[1], '|.*$', '')
-- Find the pagetype.
local pageType = mHatnote.findNamespaceId(firstPage) == 0 and 'artigo' or 'página'
-- Make the formatted link text
list = mHatlist.andList(args, true)
-- Build the text.
local isPlural = #args > 1
local mainForm
local curNs = currentTitle.namespace
if (curNs == 14) or (curNs == 15) then -- domínios categoria/discussão
if mHatnote.findNamespaceId(firstPage) == 0 then
if isPlural then
mainForm = 'Os artigos principais para esta [[WP:CAT|categoria]] são %s'
else
mainForm = 'O artigo principal para esta [[WP:CAT|categoria]] é %s'
end
else
if isPlural then
mainForm = 'As páginas principais para esta [[WP:CAT|categoria]] são %s'
else
mainForm = 'A página principal para esta [[WP:CAT|categoria]] é %s'
end
end
else
if mHatnote.findNamespaceId(firstPage) == 0 then
if isPlural then
mainForm = 'Artigos principais: %s'
else
mainForm = 'Artigo principal: %s'
end
else
if isPlural then
mainForm = 'Páginas principais: %s'
else
mainForm = 'Página principal: %s'
end
end
end
local text = string.format(mainForm, list)
-- Processar as opções e passar os texto à função _rellink em
-- [[Módulo:Hatnote]].
options = options or {}
local hnOptions = {
selfref = options.selfref
}
return mHatnote._hatnote(text, hnOptions)
end
return p