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

Hasaninasab (بحث | مشارکت‌ها)
جز Hasaninasab صفحهٔ پودمان:Message box را بدون برجای‌گذاشتن تغییرمسیر به پودمان:منطقه حرم مکه منتقل کرد: تست
جز ۱ نسخه واردشده
 
(۱۹ نسخهٔ میانی ویرایش شده توسط ۸ کاربر نشان داده نشد)
خط ۱: خط ۱:
-- برای فارسی‌سازی بهتر، بعضی قسمت‌های این پودمان تغییر یافته‌است که در همان‌جا اشاره شده‌است. لطفاً هنگام به‌روزرسانی به‌دقت پودمان را تغییر دهید.
-- This is a meta-module for producing message box templates, including
-- This is a meta-module for producing message box templates, including
-- {{mbox}}, {{ambox}}, {{imbox}}, {{tmbox}}, {{ombox}}, {{cmbox}} and {{fmbox}}.
-- {{mbox}}, {{ambox}}, {{imbox}}, {{tmbox}}, {{ombox}}, {{cmbox}} and {{fmbox}}.


-- Load necessary modules.
-- Load necessary modules.
require('Module:No globals')
require('strict')
local getArgs
local getArgs
local categoryHandler = require('Module:Category handler')._main
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.
local lang = mw.language.getContentLanguage()
local lang = mw.language.getContentLanguage()
-- Define constants
local CONFIG_MODULE = 'Module:Message box/configuration'
local DEMOSPACES = {talk = 'tmbox', image = 'imbox', file = 'imbox', category = 'cmbox', article = 'ambox', main = 'ambox'}


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
خط ۷۳: خط ۷۶:
local ns = obj.title.namespace
local ns = obj.title.namespace
-- boxType is "mbox" or invalid input
-- boxType is "mbox" or invalid input
if ns == 0 then
if args.demospace and args.demospace ~= '' then
-- implement demospace parameter of mbox
local demospace = mw.ustring.lower(args.demospace)
if DEMOSPACES[demospace] then
-- use template from DEMOSPACES
obj.cfg = cfg[DEMOSPACES[demospace]]
elseif mw.ustring.find( demospace, 'بحث' ) then
-- demo as a talk page
obj.cfg = cfg.tmbox
else
-- default to ombox
obj.cfg = cfg.ombox
end
elseif ns == 0 then
obj.cfg = cfg.ambox -- main namespace
obj.cfg = cfg.ambox -- main namespace
elseif ns == 6 then
elseif ns == 6 then
خط ۱۰۷: خط ۱۲۳:
obj.categories = {}
obj.categories = {}
obj.classes = {}
obj.classes = {}
-- For lazy loading of [[Module:Category handler]].
obj.hasCategories = false


return setmetatable(obj, MessageBox)
return setmetatable(obj, MessageBox)
خط ۱۱۶: خط ۱۳۴:
end
end
if sort then
if sort then
cat = string.format('', cat, sort)
cat = mw.ustring.format('[[رده:%s|%s]]', cat, sort)
else
else
cat = string.format('', cat)
cat = mw.ustring.format('[[رده:%s]]', cat)
end
end
self.hasCategories = true
self.categories[ns] = self.categories[ns] or {}
self.categories[ns] = self.categories[ns] or {}
table.insert(self.categories[ns], cat)
table.insert(self.categories[ns], cat)
خط ۱۵۵: خط ۱۷۴:


-- Add attributes, classes and styles.
-- Add attributes, classes and styles.
if cfg.allowId then
self.id = args.id
self.id = args.id
self.name = args.name
if self.name then
self:addClass('box-' .. mw.ustring.gsub(self.name,' ','_'))
end
if yesno(args.plainlinks) ~= false then
self:addClass('plainlinks')
end
end
self:addClass(
cfg.usePlainlinksParam and yesno(args.plainlinks or true) and 'plainlinks'
)
for _, class in ipairs(cfg.classes or {}) do
for _, class in ipairs(cfg.classes or {}) do
self:addClass(class)
self:addClass(class)
خط ۱۸۳: خط ۲۰۴:
and cfg.templateCategoryRequireName
and cfg.templateCategoryRequireName
then
then
self.name = args.name
if self.name then
if self.name then
local templateName = mw.ustring.match(
local templateName = mw.ustring.match(
خط ۱۹۵: خط ۲۱۵:
and mw.title.equals(self.title, self.templateTitle)
and mw.title.equals(self.title, self.templateTitle)
end
end
 
-- Process data for collapsible text fields. At the moment these are only
-- Process data for collapsible text fields. At the moment these are only
-- used in {{ambox}}.
-- used in {{ambox}}.
خط ۲۴۹: خط ۲۶۹:
end
end
if talkTitle and talkTitle.exists then
if talkTitle and talkTitle.exists then
local talkText = 'گفتگوی مربوطه ممکن است در'
                local talkText
if talkArgIsTalkPage then
                if self.isSmall then
talkText = string.format(
                    local talkLink = talkArgIsTalkPage and talk or (talkTitle.prefixedText .. '#' .. talk)
'%s [[%s|%s]].',
                    talkText = mw.ustring.format('([[%s|بحث]])', talkLink)
talkText,
                else
talk,
                    talkText = 'گفتگوی مربوطه ممکن است در'
talkTitle.prefixedText
                    if talkArgIsTalkPage then
)
                        talkText = mw.ustring.format(
else
                            '%s [[%s|%s]] %s',
talkText = string.format(
                            talkText,
'%s [[%s#%s|صفحهٔ بحث]].',
                            talk,
talkText,
                            talkTitle.prefixedText,
talkTitle.prefixedText,
'یافت شود'
talk
                        )
)
                    else
end
                        talkText = mw.ustring.format(
                            '%s [[%s#%s|صفحهٔ بحث]] %s.',
                            talkText,
                            talkTitle.prefixedText,
                            talk,
'یافت شود'
                        )
                    end
                end
self.talk = talkText
self.talk = talkText
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(" <small>''(%s)''</small>", 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
if yesno(args.removalnotice) then
self.removalNotice = cfg.removalNotice
end
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


خط ۳۴۵: خط ۳۸۰:
or args['category' .. tostring(num)]
or args['category' .. tostring(num)]
local allCat = args['all' .. tostring(num)]
local allCat = args['all' .. tostring(num)]
--mainCat = type(mainCat) == 'string' and mainCat
mainCat = type(mainCat) == 'string' and mainCat
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', mainCat)
local catTitle = mw.ustring.format('%s %s %s', mainCat, preposition, date)
--self:addCat(0, catTitle)
self:addCat(0, catTitle)
-- catTitle = getTitleObject('رده:' .. catTitle)
catTitle = getTitleObject('رده:' .. catTitle)
--if not catTitle or not catTitle.exists then
if not catTitle or not catTitle.exists then
--self:addCat(0, 'مقاله‌های دارای پارامتر تاریخ نادرست در الگو')
self:addCat(0, 'مقاله‌های دارای پارامتر تاریخ نادرست در الگو')
--end
end
--elseif mainCat and (not date or date == '') then
elseif mainCat and (not date or date == '') then
--self:addCat(0, mainCat)
self:addCat(0, mainCat)
--end
end
if allCat then
if allCat then
self:addCat(0, allCat)
self:addCat(0, allCat)
خط ۳۹۸: خط ۴۳۳:
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', 'پارامتر نیازمند اصلاح الگوی پیامی ویکی‌حج', allSort)
self:addCat('all', 'پارامتر نیازمند اصلاح الگوی پیامی ویکی‌پدیا', allSort)
end
end
if self.isSubstituted then
if self.isSubstituted then
خط ۴۲۶: خط ۴۶۱:


function MessageBox:renderCategories()
function MessageBox:renderCategories()
if not self.hasCategories then
-- No categories added, no need to pass them to Category handler so,
-- if it was invoked, it would return the empty string.
-- So we shortcut and return the empty string.
return ""
end
-- Convert category tables to strings and pass them through
-- Convert category tables to strings and pass them through
-- [[Module:Category handler]].
-- [[Module:Category handler]].
return categoryHandler{
return require('Module:Category handler')._main{
main = table.concat(self.categories[0] or {}),
main = table.concat(self.categories[0] or {}),
template = table.concat(self.categories[10] or {}),
template = table.concat(self.categories[10] or {}),
خط ۴۴۴: خط ۴۸۵:
root:tag('b')
root:tag('b')
:addClass('error')
:addClass('error')
:wikitext(string.format(
:wikitext(mw.ustring.format(
'الگوی <code>%s[[الگو:%s|%s]]%s</code> به طور اشتباه جانشین شده‌است.',
'الگوی <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


خط ۴۹۲: خط ۵۴۶:
-- collapsible. At the moment, only ambox uses this.
-- collapsible. At the moment, only ambox uses this.
textCell:cssText(self.textstyle or nil)
textCell:cssText(self.textstyle or nil)
local textCellSpan = textCell:tag('span')
local textCellDiv = textCell:tag('div')
textCellSpan
textCellDiv
:addClass('mbox-text-span')
:addClass('mbox-text-span')
:wikitext(self.issue or nil)
:wikitext(self.issue or nil)
if not self.isSmall then
if (self.talk or self.fix) then
textCellSpan:tag('span')
textCellDiv:tag('span')
:addClass('hide-when-compact')
:addClass('hide-when-compact')
:wikitext(self.talk and (' ' .. self.talk) or nil)
:wikitext(self.talk and (' ' .. self.talk) or nil)
:wikitext(self.fix and (' ' .. self.fix) or nil)
:wikitext(self.fix and (' ' .. self.fix) or nil)
end
end
textCellSpan:wikitext(self.date and (' ' .. self.date) or nil)
textCellDiv:wikitext(self.date and (' ' .. self.date) or nil)
if not self.isSmall then
if self.info and not self.isSmall then
textCellSpan
textCellDiv
:tag('span')
:tag('span')
:addClass('hide-when-compact')
:addClass('hide-when-compact')
:wikitext(self.info and (' ' .. self.info) or nil)
:wikitext(self.info and (' ' .. self.info) or nil)
end
if self.removalNotice then
textCellDiv:tag('span')
:addClass('hide-when-compact')
:tag('i')
: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(
'این جعبه پیام از پارامتر «نوع=%s» نامعتبر استفاده می‌کند و نیازمند اصلاح است.',
'این جعبه پیام از پارامتر نامعتبر «type=%s» استفاده می‌کند و نیازمند اصلاح است.',
self.type or ''
self.type or ''
))
))
خط ۵۶۸: خط ۶۲۸:


function p.main(boxType, args, cfgTables)
function p.main(boxType, args, cfgTables)
local box = MessageBox.new(boxType, args, cfgTables or mw.loadData('Module:Message box/configuration'))
local box = MessageBox.new(boxType, args, cfgTables or mw.loadData(CONFIG_MODULE))
box:setParameters()
box:setParameters()
box:setCategories()
box:setCategories()