مستخدم مجهول
الفرق بين المراجعتين لصفحة: «وحدة:Message box»
ط
تم استيراد 70 مراجعة من en:Module:Message_box
ط (مراجعة واحدة) |
ar>Dr-Taher ط (تم استيراد 70 مراجعة من en:Module:Message_box) |
||
سطر ١: | سطر ١: | ||
require('strict') | |||
require(' | |||
local getArgs | local getArgs | ||
local yesno = require('Module:Yesno') | local yesno = require('Module:Yesno') | ||
local lang = mw.language.getContentLanguage() | local lang = mw.language.getContentLanguage() | ||
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('[[ | cat = string.format('[[تصنيف:%s|%s]]', cat, sort) | ||
else | else | ||
cat = string.format('[[ | 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 | ||
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 = ' | 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 = ' | sect = 'هذه ' .. (cfg.sectionDefault or 'page') | ||
elseif type(args.sect) == 'string' then | elseif type(args.sect) == 'string' then | ||
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 | |||
if self.isSmall then | |||
local talkLink = talkArgIsTalkPage and talk or (talkTitle.prefixedText .. '#' .. talk) | |||
talkText = string.format('([[%s|نقاش]])', talkLink) | |||
else | |||
talkText = 'قد يكون هنالك نقاشٌ ذو علاقةٍ في' | |||
if talkArgIsTalkPage then | |||
talkText = string.format( | |||
'%s [[%s|%s]] %s.', | |||
talkText, | |||
talk, | |||
talkTitle.prefixedText, | |||
'المتعلّقة' | |||
) | |||
else | |||
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(" < | 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 | ||
-- | -- Right image settings. | ||
local | local imageRight = self.isSmall and args.smallimage or args.image | ||
if cfg.imageCheckBlank and | if cfg.imageCheckBlank and imageRight ~= 'blank' and imageRight ~= 'none' and imageRight ~= 'بدون' | ||
or not cfg.imageCheckBlank and | or not cfg.imageCheckBlank and imageRight ~= 'none' and imageRight ~= 'بدون' | ||
then | then | ||
self. | self.imageRight = imageRight | ||
if not | 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. | 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 | ||
-- | -- Left image settings. | ||
local | local imageLeft = self.isSmall and args.smallimageleft or args.imageleft | ||
if not (cfg. | if not (cfg.imageLeftNone and imageLeft == 'none' and imageLeft == 'بدون') then | ||
self. | 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 = ' | 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, ' | 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 | 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( | ||
' | 'قالب <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 | -- Add the right-hand image. | ||
local row = boxTable:tag('tr') | local row = boxTable:tag('tr') | ||
if self. | if self.imageRight then | ||
local | local imageRightCell = row:tag('td'):addClass('mbox-image') | ||
if self.imageCellDiv then | if self.imageCellDiv then | ||
-- If we are using a div, redefine | -- If we are using a div, redefine imageRightCell so that the image | ||
-- is inside it. Divs use style="width: | -- 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. | ||
imageRightCell = imageRightCell:tag('div'):addClass('mbox-image-div') | |||
end | end | ||
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') | ||
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) | 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(' | textCellDiv:tag('span') | ||
:addClass('hide-when-compact') | :addClass('hide-when-compact') | ||
:tag('i') | :tag('i') | ||
:wikitext(string.format(" | :wikitext(string.format("%s", self.removalNotice)) | ||
end | end | ||
else | else | ||
سطر ٥٢٥: | سطر ٥٦٦: | ||
end | end | ||
-- Add the | -- Add the left-hand image. | ||
if self. | if self.imageLeft then | ||
local | local imageLeftCell = row:tag('td'):addClass('mbox-imageleft') | ||
if self.imageCellDiv then | if self.imageCellDiv then | ||
-- If we are using a div, redefine | -- If we are using a div, redefine imageLeftCell so that the image | ||
-- is inside it. | -- is inside it. | ||
imageLeftCell = imageLeftCell:tag('div'):addClass('mbox-image-div') | |||
end | end | ||
imageLeftCell | |||
:wikitext(self. | :wikitext(self.imageLeft or nil) | ||
end | end | ||
سطر ٥٤١: | سطر ٥٨٢: | ||
boxTable:tag('tr') | boxTable:tag('tr') | ||
:tag('td') | :tag('td') | ||
:attr('colspan', self. | :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') | ||
: | :addClass('mbox-invalid-type') | ||
:wikitext(string.format( | :wikitext(string.format( | ||
' | 'صندوق الرسالة هذا يستخدم وسيط "type=%s" غير صالح، وينبغي إصلاحه.', | ||
self.type or '' | self.type or '' | ||
)) | )) |