Modul:Message box: Perbedaan antara revisi
Loncat ke navigasi
Loncat ke pencarian
File:Cscr-featured.svg needs a link to the description page for license and attribution. Add the ability for the configuration to specify a flag to accomplish this.
dw>Nyilvoskt Tidak ada ringkasan suntingan |
dw>Anomie (File:Cscr-featured.svg needs a link to the description page for license and attribution. Add the ability for the configuration to specify a flag to accomplish this.) |
||
Baris 1: | Baris 1: | ||
require('strict') | require('strict') | ||
local getArgs | local getArgs | ||
local yesno = require(' | local yesno = require('Module:Yesno') | ||
local lang = mw.language.getContentLanguage() | local lang = mw.language.getContentLanguage() | ||
local CONFIG_MODULE = ' | local CONFIG_MODULE = 'Module:Message box/configuration' | ||
local DEMOSPACES = {talk = 'tmbox', image = 'imbox', file = 'imbox', category = 'cmbox', article = 'ambox', main = 'ambox'} | local DEMOSPACES = {talk = 'tmbox', image = 'imbox', file = 'imbox', category = 'cmbox', article = 'ambox', main = 'ambox'} | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
-- | -- Helper functions | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
local function getTitleObject(...) | local function getTitleObject(...) | ||
-- | -- Get the title object, passing the function through pcall | ||
-- in case we are over the expensive function count limit. | |||
local success, title = pcall(mw.title.new, ...) | local success, title = pcall(mw.title.new, ...) | ||
if success then | if success then | ||
Baris 49: | Baris 50: | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
-- | -- Box class definition | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
Baris 59: | Baris 60: | ||
local obj = {} | local obj = {} | ||
-- | -- Set the title object and the namespace. | ||
obj.title = getTitleObject(args.page) or mw.title.getCurrentTitle() | obj.title = getTitleObject(args.page) or mw.title.getCurrentTitle() | ||
-- | -- Set the config for our box type. | ||
obj.cfg = cfg[boxType] | obj.cfg = cfg[boxType] | ||
if not obj.cfg then | if not obj.cfg then | ||
local ns = obj.title.namespace | local ns = obj.title.namespace | ||
-- boxType | -- boxType is "mbox" or invalid input | ||
if args.demospace and args.demospace ~= '' then | if args.demospace and args.demospace ~= '' then | ||
-- | -- implement demospace parameter of mbox | ||
local demospace = string.lower(args.demospace) | local demospace = string.lower(args.demospace) | ||
if DEMOSPACES[demospace] then | if DEMOSPACES[demospace] then | ||
-- | -- use template from DEMOSPACES | ||
obj.cfg = cfg[DEMOSPACES[demospace]] | obj.cfg = cfg[DEMOSPACES[demospace]] | ||
elseif string.find( demospace, 'talk' ) then | elseif string.find( demospace, 'talk' ) then | ||
Baris 96: | Baris 97: | ||
end | end | ||
-- | -- Set the arguments, and remove all blank arguments except for the ones | ||
-- listed in cfg.allowBlankParams. | -- listed in cfg.allowBlankParams. | ||
do | do | ||
Baris 111: | Baris 112: | ||
end | end | ||
-- | -- Define internal data structure. | ||
obj.categories = {} | obj.categories = {} | ||
obj.classes = {} | obj.classes = {} | ||
-- | -- For lazy loading of [[Module:Category handler]]. | ||
obj.hasCategories = false | obj.hasCategories = false | ||
Baris 125: | Baris 126: | ||
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.hasCategories = true | ||
Baris 154: | Baris 155: | ||
self.typeClass = typeData.class | self.typeClass = typeData.class | ||
self.typeImage = typeData.image | self.typeImage = typeData.image | ||
self.typeImageNeedsLink = typeData.imageNeedsLink | |||
-- | -- Find if the box has been wrongly substituted. | ||
self.isSubstituted = cfg.substCheck and args.subst == 'SUBST' | self.isSubstituted = cfg.substCheck and args.subst == 'SUBST' | ||
-- | -- Find whether we are using a small message box. | ||
self.isSmall = cfg.allowSmall and ( | self.isSmall = cfg.allowSmall and ( | ||
cfg.smallParam and args.small == cfg.smallParam | cfg.smallParam and args.small == cfg.smallParam | ||
Baris 200: | Baris 202: | ||
'^[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 = 'Template:' .. templateName | ||
self.templateTitle = getTitleObject(templateName) | self.templateTitle = getTitleObject(templateName) | ||
end | end | ||
Baris 207: | Baris 209: | ||
end | end | ||
-- | -- Process data for collapsible text fields. At the moment these are only | ||
-- {{ambox}}. | -- used in {{ambox}}. | ||
if self.useCollapsibleTextFields then | if self.useCollapsibleTextFields then | ||
-- Get the self.issue value. | -- Get the self.issue value. | ||
Baris 216: | Baris 218: | ||
local sect | local sect | ||
if args.sect == '' then | if args.sect == '' then | ||
sect = '' .. (cfg.sectionDefault or 'page') | sect = 'This ' .. (cfg.sectionDefault or 'page') | ||
elseif type(args.sect) == 'string' then | elseif type(args.sect) == 'string' then | ||
sect = '' .. args.sect | sect = 'This ' .. args.sect | ||
end | end | ||
local issue = args.issue | local issue = args.issue | ||
Baris 263: | Baris 265: | ||
if self.isSmall then | if self.isSmall then | ||
local talkLink = talkArgIsTalkPage and talk or (talkTitle.prefixedText .. '#' .. talk) | local talkLink = talkArgIsTalkPage and talk or (talkTitle.prefixedText .. '#' .. talk) | ||
talkText = string.format('([[%s| | talkText = string.format('([[%s|talk]])', talkLink) | ||
else | else | ||
talkText = ' | talkText = 'Relevant discussion may be found on' | ||
if talkArgIsTalkPage then | if talkArgIsTalkPage then | ||
talkText = string.format( | talkText = string.format( | ||
Baris 275: | Baris 277: | ||
else | else | ||
talkText = string.format( | talkText = string.format( | ||
'%s the [[%s#%s| | '%s the [[%s#%s|talk page]].', | ||
talkText, | talkText, | ||
talkTitle.prefixedText, | talkTitle.prefixedText, | ||
Baris 328: | Baris 330: | ||
and (cfg.imageSmallSize or '30x30px') | and (cfg.imageSmallSize or '30x30px') | ||
or '40x40px' | or '40x40px' | ||
self.imageLeft = string.format('[[ | self.imageLeft = string.format('[[File:%s|%s%s|alt=]]', self.typeImage | ||
or ' | or 'Information icon4.svg', imageSize, self.typeImageNeedsLink and "" or "|link=" ) | ||
end | end | ||
end | end | ||
Baris 353: | Baris 355: | ||
local nums = {} | local nums = {} | ||
for _, prefix in ipairs{'cat', ' | for _, prefix in ipairs{'cat', 'category', 'all'} do | ||
args[prefix .. '1'] = args[prefix] | args[prefix .. '1'] = args[prefix] | ||
nums = union(nums, getArgNums(args, prefix)) | nums = union(nums, getArgNums(args, prefix)) | ||
Baris 364: | Baris 366: | ||
for _, num in ipairs(nums) do | for _, num in ipairs(nums) do | ||
local mainCat = args['cat' .. tostring(num)] | local mainCat = args['cat' .. tostring(num)] | ||
or args[' | or args['category' .. tostring(num)] | ||
local allCat = args['all' .. tostring(num)] | local allCat = args['all' .. tostring(num)] | ||
mainCat = type(mainCat) == 'string' and mainCat | mainCat = type(mainCat) == 'string' and mainCat | ||
Baris 430: | Baris 432: | ||
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 | ||
Baris 455: | Baris 457: | ||
-- 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 require(' | 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 {}), | ||
Baris 472: | Baris 474: | ||
: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('}}') | ||
)) | )) |