الفرق بين المراجعتين لصفحة: «وحدة:Message box»

ط
تم استيراد 70 مراجعة من en:Module:Message_box
ط (مراجعة واحدة)
ar>Dr-Taher
ط (تم استيراد 70 مراجعة من en:Module: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 categoryHandler = require('Module:Category handler')._main
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 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 = string.lower(args.demospace)
if DEMOSPACES[demospace] then
-- use template from DEMOSPACES
obj.cfg = cfg[DEMOSPACES[demospace]]
elseif string.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('[[Category:%s|%s]]', cat, sort)
cat = string.format('[[تصنيف:%s|%s]]', cat, sort)
else
else
cat = string.format('[[Category:%s]]', cat)
cat = string.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.
self.id = args.id
self.id = args.id
self.name = args.name
if self.name then
self:addClass('box-' .. string.gsub(self.name,' ','_'))
end
if yesno(args.plainlinks) ~= false then
if yesno(args.plainlinks) ~= false then
self:addClass('plainlinks')
self:addClass('plainlinks')
سطر ١٨٣: سطر ١٩٦:
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(
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
سطر ١٩٥: سطر ٢٠٧:
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}}.
سطر ٢٠٥: سطر ٢١٧:
local sect
local sect
if args.sect == '' then
if args.sect == '' then
sect = 'This ' .. (cfg.sectionDefault or 'page')
sect = 'هذه ' .. (cfg.sectionDefault or 'page')
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
سطر ٢٤٩: سطر ٢٦١:
end
end
if talkTitle and talkTitle.exists then
if talkTitle and talkTitle.exists then
local talkText = 'Relevant discussion may be found on'
                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 = string.format('([[%s|نقاش]])', talkLink)
talkText,
                else
talk,
                    talkText = 'قد يكون هنالك نقاشٌ ذو علاقةٍ في'
talkTitle.prefixedText
                    if talkArgIsTalkPage then
)
                        talkText = string.format(
else
                            '%s [[%s|%s]] %s.',
talkText = string.format(
                            talkText,
'%s the [[%s#%s|talk page]].',
                            talk,
talkText,
                            talkTitle.prefixedText,
talkTitle.prefixedText,
                            'المتعلّقة'
talk
                        )
)
                    else
end
                        talkText = string.format(
                            '%s [[%s#%s|صفحة النقاش]] %s.',
                            talkText,
                            talkTitle.prefixedText,
                            talk,
                            'المتعلّقة'
                        )
                    end
                end
self.talk = talkText
self.talk = talkText
end
end
سطر ٢٧٨: سطر ٢٩٨:
end
end
if date then
if date then
self.date = string.format(" <small>''(%s)''</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.
-- Right image settings.
local imageLeft = self.isSmall and args.smallimage or args.image
local imageRight = self.isSmall and args.smallimage or args.image
if cfg.imageCheckBlank and imageLeft ~= 'blank' and imageLeft ~= 'none'
if cfg.imageCheckBlank and imageRight ~= 'blank' and imageRight ~= 'none' and imageRight ~= 'بدون'
or not cfg.imageCheckBlank and imageLeft ~= 'none'
or not cfg.imageCheckBlank and imageRight ~= 'none' and imageRight ~= 'بدون'
then
then
self.imageLeft = imageLeft
self.imageRight = imageRight
if not imageLeft then
if not imageRight then
local imageSize = self.isSmall
local imageSize = self.isSmall
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.imageRight = string.format('[[File:%s|%s|link=|alt=]]', self.typeImage
or 'Imbox notice.png', imageSize)
or 'Imbox notice.png', imageSize)
end
end
end
end


-- Right image settings.
-- Left image settings.
local imageRight = self.isSmall and args.smallimageright or args.imageright
local imageLeft = self.isSmall and args.smallimageleft or args.imageleft
if not (cfg.imageRightNone and imageRight == 'none') then
if not (cfg.imageLeftNone and imageLeft == 'none' and imageLeft == 'بدون') then
self.imageRight = imageRight
self.imageLeft = imageLeft
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)]
سطر ٣٥٥: سطر ٣٧٦:
catTitle = getTitleObject('Category:' .. catTitle)
catTitle = getTitleObject('Category:' .. 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
سطر ٤٢٩: سطر ٤٥٠:


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 {}),
سطر ٤٤٨: سطر ٤٧٥:
:addClass('error')
:addClass('error')
:wikitext(string.format(
:wikitext(string.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


سطر ٤٦٧: سطر ٥٠٩:
end
end


-- Add the left-hand image.
-- Add the right-hand image.
local row = boxTable:tag('tr')
local row = boxTable:tag('tr')
if self.imageLeft then
if self.imageRight then
local imageLeftCell = row:tag('td'):addClass('mbox-image')
local imageRightCell = row:tag('td'):addClass('mbox-image')
if self.imageCellDiv then
if self.imageCellDiv then
-- If we are using a div, redefine imageLeftCell so that the image
-- If we are using a div, redefine imageRightCell so that the image
-- is inside it. Divs use style="width: 52px;", which limits the
-- is inside it. Divs use style="width: 42px;", which limits the
-- 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')
imageRightCell = imageRightCell:tag('div'):addClass('mbox-image-div')
end
end
imageLeftCell:wikitext(self.imageLeft or nil)
imageRightCell:wikitext(self.imageRight or nil)
elseif self.imageEmptyCell then
elseif self.imageEmptyCell then
-- Some message boxes define an empty cell if no image is specified, and
-- Some message boxes define an empty cell if no image is specified, and
سطر ٤٨٦: سطر ٥٢٨:
row:tag('td')
row:tag('td')
:addClass('mbox-empty-cell')
:addClass('mbox-empty-cell')
:cssText(self.imageEmptyCellStyle or nil)
end
end


سطر ٤٩٩: سطر ٥٤٠:
:addClass('mbox-text-span')
:addClass('mbox-text-span')
:wikitext(self.issue or nil)
:wikitext(self.issue or nil)
if (self.talk or self.fix) and not self.isSmall then
if (self.talk or self.fix) then
textCellDiv:tag('span')
textCellDiv:tag('span')
:addClass('hide-when-compact')
:addClass('hide-when-compact')
سطر ٥١٣: سطر ٥٥٤:
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')
:wikitext(string.format(" (%s)", self.removalNotice))
:wikitext(string.format("%s", self.removalNotice))
end
end
else
else
سطر ٥٢٥: سطر ٥٦٦:
end
end


-- Add the right-hand image.
-- Add the left-hand image.
if self.imageRight then
if self.imageLeft then
local imageRightCell = row:tag('td'):addClass('mbox-imageright')
local imageLeftCell = row:tag('td'):addClass('mbox-imageleft')
if self.imageCellDiv then
if self.imageCellDiv then
-- If we are using a div, redefine imageRightCell so that the image
-- If we are using a div, redefine imageLeftCell so that the image
-- is inside it.
-- is inside it.
imageRightCell = imageRightCell:tag('div'):css('width', '52px')
imageLeftCell = imageLeftCell:tag('div'):addClass('mbox-image-div')
end
end
imageRightCell
imageLeftCell
:wikitext(self.imageRight or nil)
:wikitext(self.imageLeft or nil)
end
end


سطر ٥٤١: سطر ٥٨٢:
boxTable:tag('tr')
boxTable:tag('tr')
:tag('td')
:tag('td')
:attr('colspan', self.imageRight and '3' or '2')
:attr('colspan', self.imageLeft and '3' or '2')
:addClass('mbox-text')
:addClass('mbox-text')
:cssText(self.textstyle or nil)
:cssText(self.textstyle or nil)
سطر ٥٥٠: سطر ٥٩١:
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(
'This message box is using an invalid "type=%s" parameter and needs fixing.',
'صندوق الرسالة هذا يستخدم وسيط "type=%s" غير صالح، وينبغي إصلاحه.',
self.type or ''
self.type or ''
))
))
مستخدم مجهول