پودمان:Cat main: تفاوت میان نسخه‌ها

۳۳۱ بایت اضافه‌شده ،  ‏۲ فوریهٔ ۲۰۲۲
imported>Darafsh
جز (ویرایش Darafsh (بحث) به آخرین تغییری که علیرضا انجام داده بود واگردانده شد)
خط ۲: خط ۲:


local mHatnote = require('Module:Hatnote')
local mHatnote = require('Module:Hatnote')
local mFormatLink = require('Module:Format link')
local yesno = require('Module:Yesno')
local yesno = require('Module:Yesno')
local mTableTools -- lazily initialise
local mTableTools -- lazily initialise
خط ۱۱: خط ۱۲:
mTableTools = require('Module:TableTools')
mTableTools = require('Module:TableTools')
mArguments = require('Module:Arguments')
mArguments = require('Module:Arguments')
local args = mArguments.getArgs(frame, {wrappers = 'الگو:اصلی رده'})
local args = mArguments.getArgs(frame, {wrappers = {'الگو:Cat main', 'الگو:اصلی رده'}})
local pages = mTableTools.compressSparseArray(args)
local pages = mTableTools.compressSparseArray(args)
local options = {
local options = {
article = args.article,
article = args.article or args['مقاله'],
selfref = args.selfref
selfref = args.selfref or args['خودارجاع']
}
}
return p._catMain(options, unpack(pages))
return p._catMain(options, unpack(pages))
خط ۲۴: خط ۲۵:


-- Get the links table.
-- Get the links table.
local links = mHatnote.formatPages(...)
local links = mFormatLink.formatPages({}, {...})
if not links[1] then
if not links[1] then
local page = mw.title.getCurrentTitle().text
local page = mw.title.getCurrentTitle().text
links[1] = mHatnote._formatLink(page)
links[1] = mFormatLink._formatLink{link = page}
end
end
for i, link in ipairs(links) do
for i, link in ipairs(links) do
links[i] = string.format("'''%s'''", link)
links[i] = mw.ustring.format("'''%s'''", link)
end
end


-- Get the pagetype.
-- Get the pagetype.
local pagetype
local pages = {...}
if yesno(options.article) ~= false then
local pagetype  
pagetype = 'مقاله'
if options.article ~= nil then
pagetype = yesno(options.article) ~= false and 'مقاله' or 'صفحه'
elseif pages and pages[1] then
local page = mw.ustring.gsub(pages[1], "|.*", "")
pagetype = mw.title.new(page).namespace == 0 and "مقاله" or "صفحه"
else
else
pagetype = 'صفحه'
pagetype = "مقاله"
end
end


خط ۴۴: خط ۵۰:
local stringToFormat
local stringToFormat
if #links > 1 then
if #links > 1 then
stringToFormat = '%s‌های اصلی این [[راهنما:رده|رده]] %s هستند.'
stringToFormat = '%s‌های اصلی این [[راهنما:رده|رده]]، %s هستند.'
else
else
stringToFormat = '%sٔ اصلی این [[راهنما:رده|رده]] %s است.'
stringToFormat = '%sٔ اصلی این [[راهنما:رده|رده]]، %s است.'
end
end


-- Get the text.
-- Get the text.
local text = string.format(
local text = mw.ustring.format(
stringToFormat,
stringToFormat,
pagetype,
pagetype,
خط ۵۹: خط ۶۵:
local hnOptions = {}
local hnOptions = {}
hnOptions.selfref = options.selfref
hnOptions.selfref = options.selfref
hnOptions.extraclasses = 'relarticle mainarticle'


return mHatnote._hatnote(text, hnOptions)
return mHatnote._hatnote(text, hnOptions)
کاربر ناشناس