「モジュール:Message box」の版間の差分
ナビゲーションに移動
検索に移動
add class using template name, code requested by User:SD0001
temp>Frozen-mikan (Wikipedia:井戸端/subj/RemexHTML移行に関する合意形成 を受けて、特別:LintErrors を減らすため https://en.wikipedia.org/w/index.php?title=Module:Message_box&diff=803399820&oldid=742383679 の変更を取り込む) |
module:infobox>MSGJ (add class using template name, code requested by User:SD0001) |
||
5行目: | 5行目: | ||
require('Module:No globals') | require('Module:No globals') | ||
local getArgs | local getArgs | ||
local yesno = require('Module:Yesno') | local yesno = require('Module:Yesno') | ||
-- Get a language object for formatDate and ucfirst. | -- 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' | |||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
106行目: | 108行目: | ||
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) | ||
119行目: | 123行目: | ||
cat = string.format('[[Category:%s]]', cat) | 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) | ||
155行目: | 160行目: | ||
-- Add attributes, classes and styles. | -- Add attributes, classes and styles. | ||
self.id = args.id | self.id = args.id | ||
self:addClass( | self.name = args.name | ||
if self.name then | |||
self:addClass('box-' .. string.gsub(self.name,' ','_')) | |||
end | |||
if yesno(args.plainlinks) ~= false then | |||
self:addClass('plainlinks') | |||
end | |||
for _, class in ipairs(cfg.classes or {}) do | for _, class in ipairs(cfg.classes or {}) do | ||
self:addClass(class) | self:addClass(class) | ||
180行目: | 189行目: | ||
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( | ||
192行目: | 200行目: | ||
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}}. | ||
246行目: | 254行目: | ||
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, | ||
256行目: | 264行目: | ||
else | else | ||
talkText = string.format( | talkText = string.format( | ||
'%s[[%s#%s| | '%s the [[%s#%s|talk page]].', | ||
talkText, | talkText, | ||
talkTitle.prefixedText, | talkTitle.prefixedText, | ||
272行目: | 280行目: | ||
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 = string.format(" <small>(%s)</small>", date) | self.date = string.format(" <small class='date-container'>''(<span class='date'>%s</span>)''</small>", date) | ||
end | end | ||
self.info = args.info | self.info = args.info | ||
if yesno(args.removalnotice) then | |||
self.removalNotice = cfg.removalNotice | |||
end | |||
end | end | ||
337行目: | 348行目: | ||
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)] | ||
345行目: | 356行目: | ||
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 = 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('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, '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 | ||
406行目: | 417行目: | ||
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 | ||
423行目: | 434行目: | ||
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 {}), | ||
442行目: | 459行目: | ||
: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('}}') | ||
)) | )) | ||
493行目: | 510行目: | ||
:addClass('mbox-text-span') | :addClass('mbox-text-span') | ||
:wikitext(self.issue or nil) | :wikitext(self.issue or nil) | ||
if not self.isSmall then | if (self.talk or self.fix) and not self.isSmall then | ||
textCellDiv:tag('span') | textCellDiv:tag('span') | ||
:addClass('hide-when-compact') | :addClass('hide-when-compact') | ||
500行目: | 517行目: | ||
end | end | ||
textCellDiv:wikitext(self.date and (' ' .. self.date) or nil) | textCellDiv:wikitext(self.date and (' ' .. self.date) or nil) | ||
if not self.isSmall then | if self.info and not self.isSmall then | ||
textCellDiv | textCellDiv | ||
:tag('span') | :tag('span') | ||
:addClass('hide-when-compact') | :addClass('hide-when-compact') | ||
:wikitext(self.info and (' ' .. self.info) or nil) | :wikitext(self.info and (' ' .. self.info) or nil) | ||
end | |||
if self.removalNotice then | |||
textCellDiv:tag('small') | |||
:addClass('hide-when-compact') | |||
:tag('i') | |||
:wikitext(string.format(" (%s)", self.removalNotice)) | |||
end | end | ||
else | else | ||
540行目: | 563行目: | ||
: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 '' | ||
)) | )) | ||
565行目: | 588行目: | ||
function p.main(boxType, args, cfgTables) | function p.main(boxType, args, cfgTables) | ||
local box = MessageBox.new(boxType, args, cfgTables or mw.loadData( | local box = MessageBox.new(boxType, args, cfgTables or mw.loadData(CONFIG_MODULE)) | ||
box:setParameters() | box:setParameters() | ||
box:setCategories() | box:setCategories() |