پودمان:Message box: تفاوت میان نسخهها
جز ۱ نسخه واردشده |
جز ۱ نسخه واردشده |
||
(۱۳ نسخهٔ میانی ویرایش شده توسط ۶ کاربر نشان داده نشد) | |||
خط ۳: | خط ۳: | ||
-- Load necessary modules. | -- Load necessary modules. | ||
require(' | 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. | ||
خط ۱۲: | خط ۱۳: | ||
-- Define constants | -- 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 = 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 | ||
خط ۱۱۹: | خط ۱۳۴: | ||
end | end | ||
if sort then | if sort then | ||
cat = | cat = mw.ustring.format('[[رده:%s|%s]]', cat, sort) | ||
else | else | ||
cat = | cat = mw.ustring.format('[[رده:%s]]', cat) | ||
end | end | ||
self.hasCategories = true | self.hasCategories = true | ||
خط ۱۶۰: | خط ۱۷۵: | ||
-- 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-' .. mw.ustring.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 'صفحه') | ||
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 = mw.ustring.format('([[%s|بحث]])', talkLink) | |||
else | |||
talkText = 'گفتگوی مربوطه ممکن است در' | |||
if talkArgIsTalkPage then | |||
talkText = mw.ustring.format( | |||
'%s [[%s|%s]] %s', | |||
talkText, | |||
talk, | |||
talkTitle.prefixedText, | |||
'یافت شود' | |||
) | |||
else | |||
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 = | 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 | ||
خط ۳۱۶: | خط ۳۴۲: | ||
and (cfg.imageSmallSize or '30x30px') | and (cfg.imageSmallSize or '30x30px') | ||
or '40x40px' | or '40x40px' | ||
self.imageLeft = | 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 = ' | 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 = | local catTitle = mw.ustring.format('%s %s %s', mainCat, preposition, date) | ||
self:addCat(0, catTitle) | self:addCat(0, catTitle) | ||
catTitle = getTitleObject(' | 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 | ||
خط ۴۰۳: | خط ۴۳۳: | ||
if self.categoryNums and #self.categoryNums > 0 then | if self.categoryNums and #self.categoryNums > 0 then | ||
templateCat = templateErrorCategory | templateCat = templateErrorCategory | ||
templateSort = ' | 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', ' | self:addCat('all', 'پارامتر نیازمند اصلاح الگوی پیامی ویکیپدیا', allSort) | ||
end | end | ||
if self.isSubstituted then | if self.isSubstituted then | ||
self:addCat('all', ' | self:addCat('all', 'صفحههای همراه با الگوی نادرست جانشینشده') | ||
end | end | ||
end | end | ||
خط ۴۵۵: | خط ۴۸۵: | ||
root:tag('b') | root:tag('b') | ||
:addClass('error') | :addClass('error') | ||
:wikitext( | :wikitext(mw.ustring.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 | ||
خط ۴۸۴: | خط ۵۲۸: | ||
-- 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'): | 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') | ||
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( | :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'): | 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') | ||
: | :addClass('mbox-invalid-type') | ||
:wikitext( | :wikitext(mw.ustring.format( | ||
' | 'این جعبه پیام از پارامتر نامعتبر «type=%s» استفاده میکند و نیازمند اصلاح است.', | ||
self.type or '' | self.type or '' | ||
)) | )) |