پرش به محتوا

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

جز
۱ نسخه واردشده
جز (۱ نسخه واردشده)
جز (۱ نسخه واردشده)
 
(۳۴ نسخهٔ میانی ویرایش شده توسط ۶ کاربر نشان داده نشد)
خط ۱: خط ۱:
-- This is a meta-module for producing message box templates, including
require('strict')
-- {{mbox}}, {{ambox}}, {{imbox}}, {{tmbox}}, {{ombox}}, {{cmbox}} and {{fmbox}}.
 
-- Load necessary modules.
require('Module:No globals')
local getArgs
local getArgs
local yesno = require('Module:Yesno')
local yesno = require('Module:Yesno')
-- Get a language object for formatDate and ucfirst.
local lang = mw.language.getContentLanguage()
local lang = mw.language.getContentLanguage()


-- Define constants
local CONFIG_MODULE = 'Module:Message box/configuration'
local CONFIG_MODULE = 'Module:Message box/configuration'
local DEMOSPACES = {talk = 'tmbox', image = 'imbox', file = 'imbox', category = 'cmbox', article = 'ambox', main = 'ambox'}
local DEMOSPACES = {talk = 'tmbox', image = 'imbox', file = 'imbox', category = 'cmbox', article = 'ambox', main = 'ambox'}
خط ۸۱: خط ۷۴:
-- use template from DEMOSPACES
-- use template from DEMOSPACES
obj.cfg = cfg[DEMOSPACES[demospace]]
obj.cfg = cfg[DEMOSPACES[demospace]]
elseif string.find( demospace, 'بحث' ) then
elseif string.find( demospace, 'talk' ) 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('[[رده:%s|%s]]', cat, sort)
cat = string.format('[[Category:%s|%s]]', cat, sort)
else
else
cat = string.format('[[رده:%s]]', cat)
cat = string.format('[[Category:%s]]', cat)
end
end
self.hasCategories = true
self.hasCategories = true
خط ۲۰۶: خط ۱۹۹:
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 = 'الگو:' .. templateName
templateName = 'Template:' .. templateName
self.templateTitle = getTitleObject(templateName)
self.templateTitle = getTitleObject(templateName)
end
end
خط ۲۲۴: خط ۲۱۷:
local sect
local sect
if args.sect == '' then
if args.sect == '' then
sect = 'این ' .. (cfg.sectionDefault or 'صفحه')
sect = 'This ' .. (cfg.sectionDefault or 'page')
elseif type(args.sect) == 'string' then
elseif type(args.sect) == 'string' then
sect = 'این ' .. args.sect
sect = 'This ' .. args.sect
end
end
local issue = args.issue
local issue = args.issue
خط ۲۷۳: خط ۲۶۶:
                     talkText = string.format('([[%s|talk]])', talkLink)
                     talkText = string.format('([[%s|talk]])', talkLink)
                 else
                 else
                     talkText = 'گفتگوی مربوطه ممکن است در'
                     talkText = 'Relevant discussion may be found on'
                     if talkArgIsTalkPage then
                     if talkArgIsTalkPage then
                         talkText = string.format(
                         talkText = string.format(
                             '%s [[%s|%s]] %s.',
                             '%s [[%s|%s]].',
                             talkText,
                             talkText,
                             talk,
                             talk,
                             talkTitle.prefixedText,
                             talkTitle.prefixedText
'یافت شود'
                         )
                         )
                     else
                     else
                         talkText = string.format(
                         talkText = string.format(
                             '%s [[%s#%s|صفحهٔ بحث]] %s.',
                             '%s the [[%s#%s|talk page]].',
                             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('xiF xiY')
date = lang:formatDate('F Y')
end
end
if date then
if date then
self.date = string.format(" <small class='date-container'>''(<span class='date'>%s</span>)''</small>", date)
self.date = string.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.imageCellDiv = not self.isSmall and cfg.imageCellDiv
self.imageCellDiv = not self.isSmall and cfg.imageCellDiv
self.imageEmptyCell = cfg.imageEmptyCell
self.imageEmptyCell = cfg.imageEmptyCell
if cfg.imageEmptyCellStyle then
self.imageEmptyCellStyle = 'border:none;padding:0px;width:1px'
end


-- Left image settings.
-- Left image settings.
خط ۳۴۱: خط ۳۲۹:
and (cfg.imageSmallSize or '30x30px')
and (cfg.imageSmallSize or '30x30px')
or '40x40px'
or '40x40px'
self.imageLeft = string.format('[[پرونده:%s|%s|link=|alt=]]', self.typeImage
self.imageLeft = string.format('[[File:%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 = 'از'
local preposition = 'from'
for _, num in ipairs(nums) do
for _, num in ipairs(nums) do
local mainCat = args['cat' .. tostring(num)]
local mainCat = args['cat' .. tostring(num)]
خط ۳۸۰: خط ۳۷۲:
local catTitle = string.format('%s %s %s', mainCat, preposition, date)
local catTitle = string.format('%s %s %s', mainCat, preposition, date)
self:addCat(0, catTitle)
self:addCat(0, catTitle)
catTitle = getTitleObject('رده:' .. catTitle)
catTitle = getTitleObject('Category:' .. catTitle)
if not catTitle or not catTitle.exists then
if not catTitle or not catTitle.exists then
self:addCat(0, 'مقاله‌های دارای پارامتر تاریخ نادرست در الگو')
self:addCat(0, 'Articles with invalid date parameter in template')
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 = 'ر'
templateSort = 'C'
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', 'پارامتر نیازمند اصلاح الگوی پیامی امامت‌پدیا', allSort)
self:addCat('all', 'Wikipedia message box parameter needs fixing', allSort)
end
end
if self.isSubstituted then
if self.isSubstituted then
self:addCat('all', 'صفحه‌های همراه با الگوی نادرست جانشین‌شده')
self:addCat('all', 'Pages with incorrectly substituted templates')
end
end
end
end
خط ۴۸۱: خط ۴۷۳:
:addClass('error')
:addClass('error')
:wikitext(string.format(
:wikitext(string.format(
'الگوی <code>%s[[الگو:%s|%s]]%s</code> اشتباه جانشین شده‌است.',
'Template <code>%s[[Template:%s|%s]]%s</code> has been incorrectly substituted.',
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


خط ۵۴۶: خط ۵۵۲:
end
end
if self.removalNotice then
if self.removalNotice then
textCellDiv:tag('small')
textCellDiv:tag('span')
:addClass('hide-when-compact')
:addClass('hide-when-compact')
:tag('i')
:tag('i')
خط ۵۶۴: خط ۵۷۰:
-- 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(string.format(
'این جعبه پیام از پارامتر نامعتبر «type=%s» استفاده می‌کند و نیازمند اصلاح است.',
'This message box is using an invalid "type=%s" parameter and needs fixing.',
self.type or ''
self.type or ''
))
))