پودمان:Message box: تفاوت میان نسخه‌ها

۱٬۰۷۴ بایت اضافه‌شده ،  ‏۲۵ فوریهٔ ۲۰۲۳
جز
۱ نسخه واردشده
جز (۱ نسخه واردشده)
جز (۱ نسخه واردشده)
 
(یک نسخهٔ میانی ویرایش شده توسط یک کاربر دیگر نشان داده نشد)
خط ۳: خط ۳:


-- Load necessary modules.
-- Load necessary modules.
require('Module:No globals')
require('strict')
local getArgs
local getArgs
local yesno = require('Module:Yesno')
local yesno = require('Module:Yesno')
local lang = mw.language.getContentLanguage()


-- Get a language object for formatDate and ucfirst.
-- Get a language object for formatDate and ucfirst.
خط ۷۷: خط ۷۸:
if args.demospace and args.demospace ~= '' then
if args.demospace and args.demospace ~= '' then
-- implement demospace parameter of mbox
-- implement demospace parameter of mbox
local demospace = string.lower(args.demospace)
local demospace = mw.ustring.lower(args.demospace)
if DEMOSPACES[demospace] then
if DEMOSPACES[demospace] then
-- use template from DEMOSPACES
-- use template from DEMOSPACES
obj.cfg = cfg[DEMOSPACES[demospace]]
obj.cfg = cfg[DEMOSPACES[demospace]]
elseif string.find( demospace, 'talk' ) then
elseif mw.ustring.find( demospace, 'بحث' ) then
-- demo as a talk page
-- demo as a talk page
obj.cfg = cfg.tmbox
obj.cfg = cfg.tmbox
خط ۱۳۳: خط ۱۳۴:
end
end
if sort then
if sort then
cat = string.format('[[Category:%s|%s]]', cat, sort)
cat = mw.ustring.format('[[رده:%s|%s]]', cat, sort)
else
else
cat = string.format('[[Category:%s]]', cat)
cat = mw.ustring.format('[[رده:%s]]', cat)
end
end
self.hasCategories = true
self.hasCategories = true
خط ۱۷۶: خط ۱۷۷:
self.name = args.name
self.name = args.name
if self.name then
if self.name then
self:addClass('box-' .. string.gsub(self.name,' ','_'))
self:addClass('box-' .. mw.ustring.gsub(self.name,' ','_'))
end
end
if yesno(args.plainlinks) ~= false then
if yesno(args.plainlinks) ~= false then
خط ۲۰۶: خط ۲۰۷:
local templateName = mw.ustring.match(
local templateName = mw.ustring.match(
self.name,
self.name,
'^[tT][eE][mM][pP][lL][aA][tT][eE][%s_]*:[%s_]*(.*)$'
'^([tT][eE][mM][pP][lL][aA][tT][eE]|الگو)[%s_]*:[%s_]*(.*)$'
) or self.name
) or self.name
templateName = 'Template:' .. templateName
templateName = 'الگو:' .. templateName
self.templateTitle = getTitleObject(templateName)
self.templateTitle = getTitleObject(templateName)
end
end
خط ۲۲۴: خط ۲۲۵:
local sect
local sect
if args.sect == '' then
if args.sect == '' then
sect = 'This ' .. (cfg.sectionDefault or 'page')
sect = 'این ' .. (cfg.sectionDefault or 'صفحه')
elseif type(args.sect) == 'string' then
elseif type(args.sect) == 'string' then
sect = 'This ' .. args.sect
sect = 'این ' .. args.sect
end
end
local issue = args.issue
local issue = args.issue
خط ۲۷۱: خط ۲۷۲:
                 if self.isSmall then
                 if self.isSmall then
                     local talkLink = talkArgIsTalkPage and talk or (talkTitle.prefixedText .. '#' .. talk)
                     local talkLink = talkArgIsTalkPage and talk or (talkTitle.prefixedText .. '#' .. talk)
                     talkText = string.format('([[%s|talk]])', talkLink)
                     talkText = mw.ustring.format('([[%s|بحث]])', talkLink)
                 else
                 else
                     talkText = 'Relevant discussion may be found on'
                     talkText = 'گفتگوی مربوطه ممکن است در'
                     if talkArgIsTalkPage then
                     if talkArgIsTalkPage then
                         talkText = string.format(
                         talkText = mw.ustring.format(
                             '%s [[%s|%s]].',
                             '%s [[%s|%s]] %s',
                             talkText,
                             talkText,
                             talk,
                             talk,
                             talkTitle.prefixedText
                             talkTitle.prefixedText,
'یافت شود'
                         )
                         )
                     else
                     else
                         talkText = string.format(
                         talkText = mw.ustring.format(
                             '%s the [[%s#%s|talk page]].',
                             '%s [[%s#%s|صفحهٔ بحث]] %s.',
                             talkText,
                             talkText,
                             talkTitle.prefixedText,
                             talkTitle.prefixedText,
                             talk
                             talk,
'یافت شود'
                         )
                         )
                     end
                     end
خط ۳۰۰: خط ۳۰۳:
date = args.date
date = args.date
elseif args.date == '' and self.isTemplatePage then
elseif args.date == '' and self.isTemplatePage then
date = lang:formatDate('F Y')
date = lang:formatDate('F Y') -- استفاده از تاریخ میلادی مرسوم است و نه تاریخ شمسی
end
end
if date then
if date then
self.date = string.format(" <span class='date-container'>''(<span class='date'>%s</span>)''</span>", date)
self.date = mw.ustring.format(" <span class='date-container'><i>(<span class='date'>%s</span>)</i></span>", date)
end
end
self.info = args.info
self.info = args.info
خط ۳۲۶: خط ۳۲۹:
self.imageEmptyCell = cfg.imageEmptyCell
self.imageEmptyCell = cfg.imageEmptyCell
if cfg.imageEmptyCellStyle then
if cfg.imageEmptyCellStyle then
self.imageEmptyCellStyle = 'border:none;padding:0;width:1px'
self.imageEmptyCellStyle = 'border:none;padding:0px;width:1px'
end
end


خط ۳۳۹: خط ۳۴۲:
and (cfg.imageSmallSize or '30x30px')
and (cfg.imageSmallSize or '30x30px')
or '40x40px'
or '40x40px'
self.imageLeft = string.format('[[File:%s|%s|link=|alt=]]', self.typeImage
self.imageLeft = mw.ustring.format('[[پرونده:%s|%s|link=|alt=]]', self.typeImage
or 'Imbox notice.png', imageSize)
or 'Imbox notice.png', imageSize)
end
end
خط ۳۴۹: خط ۳۵۲:
self.imageRight = imageRight
self.imageRight = imageRight
end
end
-- set templatestyles
self.base_templatestyles = cfg.templatestyles
self.templatestyles = args.templatestyles
end
end


خط ۳۶۸: خط ۳۷۵:
local date = args.date
local date = args.date
date = type(date) == 'string' and date
date = type(date) == 'string' and date
local preposition = 'from'
local preposition = 'از'
for _, num in ipairs(nums) do
for _, num in ipairs(nums) do
local mainCat = args['cat' .. tostring(num)]
local mainCat = args['cat' .. tostring(num)]
خط ۳۷۶: خط ۳۸۳:
allCat = type(allCat) == 'string' and allCat
allCat = type(allCat) == 'string' and allCat
if mainCat and date and date ~= '' then
if mainCat and date and date ~= '' then
local catTitle = string.format('%s %s %s', mainCat, preposition, date)
local catTitle = mw.ustring.format('%s %s %s', mainCat, preposition, date)
self:addCat(0, catTitle)
self:addCat(0, catTitle)
catTitle = getTitleObject('Category:' .. catTitle)
catTitle = getTitleObject('رده:' .. catTitle)
if not catTitle or not catTitle.exists then
if not catTitle or not catTitle.exists then
self:addCat(0, 'Articles with invalid date parameter in template')
self:addCat(0, 'مقاله‌های دارای پارامتر تاریخ نادرست در الگو')
end
end
elseif mainCat and (not date or date == '') then
elseif mainCat and (not date or date == '') then
خط ۴۲۶: خط ۴۳۳:
if self.categoryNums and #self.categoryNums > 0 then
if self.categoryNums and #self.categoryNums > 0 then
templateCat = templateErrorCategory
templateCat = templateErrorCategory
templateSort = 'C'
templateSort = 'ر'
end
end
end
end
خط ۴۳۷: خط ۴۴۴:
if self.invalidTypeError then
if self.invalidTypeError then
local allSort = (self.title.namespace == 0 and 'Main:' or '') .. self.title.prefixedText
local allSort = (self.title.namespace == 0 and 'Main:' or '') .. self.title.prefixedText
self:addCat('all', 'Wikipedia message box parameter needs fixing', allSort)
self:addCat('all', 'پارامتر نیازمند اصلاح الگوی پیامی ویکی‌پدیا', allSort)
end
end
if self.isSubstituted then
if self.isSubstituted then
self:addCat('all', 'Pages with incorrectly substituted templates')
self:addCat('all', 'صفحه‌های همراه با الگوی نادرست جانشین‌شده')
end
end
end
end
خط ۴۷۸: خط ۴۸۵:
root:tag('b')
root:tag('b')
:addClass('error')
:addClass('error')
:wikitext(string.format(
:wikitext(mw.ustring.format(
'Template <code>%s[[Template:%s|%s]]%s</code> has been incorrectly substituted.',
'الگوی <code>%s[[الگو:%s|%s]]%s</code> اشتباه جانشین شده‌است.',
mw.text.nowiki('{{'), self.name, self.name, mw.text.nowiki('}}')
mw.text.nowiki('{{'), self.name, self.name, mw.text.nowiki('}}')
))
))
end
local frame = mw.getCurrentFrame()
root:wikitext(frame:extensionTag{
name = 'templatestyles',
args = { src = self.base_templatestyles },
})
-- Add support for a single custom templatestyles sheet. Undocumented as
-- need should be limited and many templates using mbox are substed; we
-- don't want to spread templatestyles sheets around to arbitrary places
if self.templatestyles then
root:wikitext(frame:extensionTag{
name = 'templatestyles',
args = { src = self.templatestyles },
})
end
end


خط ۵۰۷: خط ۵۲۸:
-- image width to 52px. If any images in a div are wider than that,
-- image width to 52px. If any images in a div are wider than that,
-- they may overlap with the text or cause other display problems.
-- they may overlap with the text or cause other display problems.
imageLeftCell = imageLeftCell:tag('div'):css('width', '52px')
imageLeftCell = imageLeftCell:tag('div'):addClass('mbox-image-div')
end
end
imageLeftCell:wikitext(self.imageLeft or nil)
imageLeftCell:wikitext(self.imageLeft or nil)
خط ۵۱۷: خط ۵۳۸:
row:tag('td')
row:tag('td')
:addClass('mbox-empty-cell')
:addClass('mbox-empty-cell')
:cssText(self.imageEmptyCellStyle or nil)
end
end


خط ۵۴۷: خط ۵۶۷:
:addClass('hide-when-compact')
:addClass('hide-when-compact')
:tag('i')
:tag('i')
:wikitext(string.format(" (%s)", self.removalNotice))
:wikitext(mw.ustring.format(" (%s)", self.removalNotice))
end
end
else
else
خط ۵۶۲: خط ۵۸۲:
-- If we are using a div, redefine imageRightCell so that the image
-- If we are using a div, redefine imageRightCell so that the image
-- is inside it.
-- is inside it.
imageRightCell = imageRightCell:tag('div'):css('width', '52px')
imageRightCell = imageRightCell:tag('div'):addClass('mbox-image-div')
end
end
imageRightCell
imageRightCell
خط ۵۸۱: خط ۶۰۱:
if self.invalidTypeError then
if self.invalidTypeError then
root:tag('div')
root:tag('div')
:css('text-align', 'center')
:addClass('mbox-invalid-type')
:wikitext(string.format(
:wikitext(mw.ustring.format(
'This message box is using an invalid "type=%s" parameter and needs fixing.',
'این جعبه پیام از پارامتر نامعتبر «type=%s» استفاده می‌کند و نیازمند اصلاح است.',
self.type or ''
self.type or ''
))
))