کاربر ناشناس
ony load Category handler when needed, requested on talk page
(نمایش تاریخ به شمسی جای میلادی) |
(ony load Category handler when needed, requested on talk page) |
||
خط ۱: | خط ۱: | ||
-- 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}}. | ||
خط ۶: | خط ۵: | ||
require('Module:No globals') | require('Module:No globals') | ||
local getArgs | local getArgs | ||
local yesno = require('Module:Yesno') | local yesno = require('Module:Yesno') | ||
خط ۱۱۰: | خط ۱۰۸: | ||
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('[[Category:%s|%s]]', cat, sort) | ||
else | else | ||
cat = string.format('[[ | cat = string.format('[[Category:%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) | ||
خط ۱۸۸: | خط ۱۸۹: | ||
local templateName = mw.ustring.match( | local templateName = mw.ustring.match( | ||
self.name, | self.name, | ||
'^ | '^[tT][eE][mM][pP][lL][aA][tT][eE][%s_]*:[%s_]*(.*)$' | ||
) or self.name | ) or self.name | ||
templateName = ' | templateName = 'Template:' .. templateName | ||
self.templateTitle = getTitleObject(templateName) | self.templateTitle = getTitleObject(templateName) | ||
end | end | ||
خط ۲۰۶: | خط ۲۰۷: | ||
local sect | local sect | ||
if args.sect == '' then | if args.sect == '' then | ||
sect = ' | sect = 'This ' .. (cfg.sectionDefault or 'page') | ||
elseif type(args.sect) == 'string' then | elseif type(args.sect) == 'string' then | ||
sect = ' | sect = 'This ' .. 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 = ' | local talkText = 'Relevant discussion may be found on' | ||
if talkArgIsTalkPage then | if talkArgIsTalkPage then | ||
talkText = string.format( | talkText = string.format( | ||
'%s [[%s|%s]] | '%s [[%s|%s]].', | ||
talkText, | talkText, | ||
talk, | talk, | ||
talkTitle.prefixedText | talkTitle.prefixedText | ||
) | ) | ||
else | else | ||
talkText = string.format( | talkText = string.format( | ||
'%s [[%s#%s| | '%s the [[%s#%s|talk page]].', | ||
talkText, | talkText, | ||
talkTitle.prefixedText, | talkTitle.prefixedText, | ||
talk | talk | ||
) | ) | ||
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 | ||
خط ۳۴۶: | خط ۳۴۵: | ||
local date = args.date | local date = args.date | ||
date = type(date) == 'string' and date | date = type(date) == 'string' and date | ||
local preposition = ' | local preposition = 'from' | ||
for _, num in ipairs(nums) do | for _, num in ipairs(nums) do | ||
local mainCat = args['cat' .. tostring(num)] | local mainCat = args['cat' .. tostring(num)] | ||
خط ۳۵۶: | خط ۳۵۵: | ||
local catTitle = string.format('%s %s %s', mainCat, preposition, date) | local catTitle = string.format('%s %s %s', mainCat, preposition, date) | ||
self:addCat(0, catTitle) | self:addCat(0, catTitle) | ||
catTitle = getTitleObject(' | 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, 'Articles with invalid date parameter in template') | ||
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 = 'C' | ||
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', 'Wikipedia message box parameter needs fixing', allSort) | ||
end | end | ||
if self.isSubstituted then | if self.isSubstituted then | ||
self:addCat('all', ' | self:addCat('all', 'Pages with incorrectly substituted templates') | ||
end | end | ||
end | end | ||
خط ۴۳۲: | خط ۴۳۱: | ||
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( | ||
' | 'Template <code>%s[[Template:%s|%s]]%s</code> has been incorrectly substituted.', | ||
mw.text.nowiki('{{'), self.name, self.name, mw.text.nowiki('}}') | mw.text.nowiki('{{'), self.name, self.name, mw.text.nowiki('}}') | ||
)) | )) | ||
خط ۴۹۸: | خط ۵۰۳: | ||
-- 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) and not self.isSmall then | if (self.talk or self.fix) and not self.isSmall 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('small') | |||
:addClass('hide-when-compact') | :addClass('hide-when-compact') | ||
:tag('i') | :tag('i') | ||
خط ۵۵۵: | خط ۵۶۰: | ||
:css('text-align', 'center') | :css('text-align', 'center') | ||
:wikitext(string.format( | :wikitext(string.format( | ||
' | 'This message box is using an invalid "type=%s" parameter and needs fixing.', | ||
self.type or '' | self.type or '' | ||
)) | )) | ||
end | end | ||
-- Add categories. | -- Add categories. | ||
root:wikitext(self:renderCategories() or nil) | root:wikitext(self:renderCategories() or nil) |