پودمان:Message box: تفاوت میان نسخهها
fa>علیرضا نمایش تاریخ به شمسی جای میلادی |
Nazarzadeh (بحث | مشارکتها) جز ۱ نسخه واردشده |
||
(۶ نسخهٔ میانی ویرایش شده توسط ۳ کاربر نشان داده نشد) | |||
خط ۱: | خط ۱: | ||
-- 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(' | 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 | ||
خط ۱۱۰: | خط ۱۲۳: | ||
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 = | cat = mw.ustring.format('[[رده:%s|%s]]', cat, sort) | ||
else | else | ||
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. | ||
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( | ||
خط ۱۹۶: | خط ۲۱۵: | ||
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 | |||
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(' | 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 | ||
خط ۳۵۴: | خط ۳۸۳: | ||
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) | catTitle = getTitleObject('رده:' .. catTitle) | ||
خط ۴۳۲: | خط ۴۶۱: | ||
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 {}), | ||
خط ۴۵۰: | خط ۴۸۵: | ||
root:tag('b') | root:tag('b') | ||
:addClass('error') | :addClass('error') | ||
:wikitext( | :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'): | 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 | ||
خط ۴۹۸: | خط ۵۴۶: | ||
-- 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 | local textCellDiv = textCell:tag('div') | ||
textCellDiv | |||
: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') | |||
: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 | ||
textCellDiv:wikitext(self.date and (' ' .. self.date) or nil) | |||
if self.info and not self.isSmall then | if self.info and not self.isSmall then | ||
textCellDiv | |||
:tag('span') | :tag('span') | ||
:addClass('hide-when-compact') | :addClass('hide-when-compact') | ||
خط ۵۱۶: | خط ۵۶۴: | ||
end | end | ||
if self.removalNotice then | if self.removalNotice then | ||
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» استفاده میکند و نیازمند اصلاح است.', | 'این جعبه پیام از پارامتر نامعتبر «type=%s» استفاده میکند و نیازمند اصلاح است.', | ||
self.type or '' | self.type or '' | ||
)) | )) | ||
end | end | ||
-- Add categories. | -- Add categories. | ||
root:wikitext(self:renderCategories() or nil) | root:wikitext(self:renderCategories() or nil) |