Modul:Message box: Perbedaan antara revisi
Konten dihapus Konten ditambahkan
Tidak ada ringkasan suntingan |
Tidak ada ringkasan suntingan Tag: Suntingan perangkat seluler Suntingan peramban seluler Suntingan seluler lanjutan |
||
(25 revisi perantara oleh 7 pengguna tidak ditampilkan) | |||
Baris 1:
require('strict')
local getArgs
local yesno = require('Modul:Yesno')
local lang = mw.language.getContentLanguage()
local CONFIG_MODULE = 'Modul:Message box/configuration'
local DEMOSPACES = {talk = 'tmbox', image = 'imbox', file = 'imbox', category = 'cmbox', article = 'ambox', main = 'ambox'}
--------------------------------------------------------------------------------
--
--------------------------------------------------------------------------------
local function getTitleObject(
-- Mendapatkan nilai objek judul dan kemudian menyalurkan fungsi ke kode pcall
local success, title = pcall(mw.title.new, ...)
if success then
return title
end
end
Baris 46 ⟶ 30:
local ret = {}
for k in pairs(vals) do
end
table.sort(ret)
Baris 57 ⟶ 41:
local num = mw.ustring.match(tostring(k), '^' .. prefix .. '([1-9]%d*)$')
if num then
end
end
Baris 65 ⟶ 49:
--------------------------------------------------------------------------------
-- Definisi kelas kotak
--------------------------------------------------------------------------------
local
function
args = args or {}
local obj = {}
-- Pengaturan nilai objek judul dengan ruang nama.
obj.title = getTitleObject(args.page) or mw.title.getCurrentTitle()
-- konfigurasi kotak pesan.
obj.cfg = cfg[boxType]
if
-- boxType diatur sebagai "mbox" atau pemasukan akan bernilai tidak terduga
if args.demospace and args.demospace ~= '' then
-- demospasi mbox
local demospace = string.lower(args.demospace)
if DEMOSPACES[demospace] then
-- penggunaan templat dari DEMOSPACES
obj.cfg = cfg[DEMOSPACES[demospace]]
-- 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
elseif ns == 6 then
obj.cfg = cfg.imbox -- file namespace
elseif ns == 14 then
obj.cfg = cfg.cmbox -- category namespace
else
if nsTable and nsTable.isTalk then
obj.cfg = cfg.tmbox -- any talk namespace
else
obj.cfg = cfg.ombox -- other namespaces or invalid input
end
end
end
-- pengaturan argumen
-- listed in cfg.allowBlankParams.
do
if
end
end
for i, param in ipairs(obj.cfg.allowBlankParams or {}) do
newArgs[param] = args[param]
end
obj.args = newArgs
end
-- Penentuan struktur data.
obj.categories = {}
-- Pemuatan [[Modul:Category handler]].
obj.hasCategories = false
return setmetatable(obj, MessageBox)
end
function
if not cat then
return nil
end
if sort then
cat = string.format('[[Kategori:%s|%s]]', cat, sort)
else
cat = string.format('[[Kategori:%s]]', cat)
end
self.hasCategories = true
self.categories[ns] = self.categories[ns] or {}
table.insert(self.categories[ns], cat)
end
function
if not class then
return nil
end
table.insert(self.classes, class)
end
function
local args = self.args
local cfg = self.cfg
-- Get type data.
self.type = args.type
Baris 198 ⟶ 151:
and self.type
and not typeData
typeData = typeData or cfg.types[cfg.default]
self.typeClass = typeData.class
self.typeImage = typeData.image
-- Menentukan apakah kotak yang ada mengalami kesalahan atau tidak.
-- Menentukan penggunaan kotak pesan yang digunakan.
cfg.smallParam and args.small == cfg.smallParam
or not cfg.smallParam and yesno(args.small)
)
-- Add attributes, classes and styles.
self.id = args.id
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
self:addClass(class)
Baris 249 ⟶ 195:
and cfg.templateCategoryRequireName
then
if self.name then
local templateName = mw.ustring.match(
Baris 255 ⟶ 200:
'^[tT][eE][mM][pP][lL][aA][tT][eE][%s_]*:[%s_]*(.*)$'
) or self.name
templateName = '
self.templateTitle = getTitleObject(templateName)
end
self.isTemplatePage = self.templateTitle
and mw.title.equals(self.title, self.templateTitle)
end
-- Pemrosesan data pada
--
if self.useCollapsibleTextFields then
-- Get the self.issue value.
Baris 272 ⟶ 216:
local sect
if args.sect == '' then
sect = '
elseif type(args.sect) == 'string' then
sect = '
end
local issue = args.issue
Baris 281 ⟶ 225:
text = type(text) == 'string' and text or nil
local issues = {}
self.issue =
end
Baris 292 ⟶ 236:
-- parameter is blank.
if talk == ''
and self.templateTitle
and (
mw.title.equals(self.templateTitle, self.title)
Baris 316 ⟶ 260:
end
if talkTitle and talkTitle.exists then
local talkText
if self.isSmall then
local talkLink = talkArgIsTalkPage and talk or (talkTitle.prefixedText .. '#' .. talk)
talkText = string.format('([[%s|pembicaraan]])', talkLink)
else
talkText = 'Diskusi terkait dapat dibaca pada'
if talkArgIsTalkPage then
talkText = string.format(
'%s [[%s|%s]].',
talkText,
talk,
talkTitle.prefixedText
)
else
talkText = string.format(
'%s the [[%s#%s|halaman pembicaraan]].',
talkText,
talkTitle.prefixedText,
talk
)
end
end
self.talk = talkText
end
Baris 345 ⟶ 295:
end
if date then
self.date = string.format(" <
end
self.info = args.info
if yesno(args.removalnotice) then
self.removalNotice = cfg.removalNotice
end
end
Baris 362 ⟶ 315:
-- General image settings.
self.imageCellDiv = not self.isSmall and cfg.imageCellDiv
self.imageEmptyCell = cfg.imageEmptyCell
-- Left image settings.
Baris 378 ⟶ 328:
and (cfg.imageSmallSize or '30x30px')
or '40x40px'
self.imageLeft = string.format('[[
or 'Imbox notice.png', imageSize)
end
Baris 387 ⟶ 337:
if not (cfg.imageRightNone and imageRight == 'none') then
self.imageRight = imageRight
end
-- set templatestyles
self.base_templatestyles = cfg.templatestyles
self.templatestyles = args.templatestyles
end
function MessageBox:setMainspaceCategories()
local args = self.args
local cfg = self.cfg
if not cfg.allowMainspaceCategories then
return nil
end
local nums = {}
for _, prefix in ipairs{'cat', 'kategori', 'all'} do
args[prefix .. '1'] = args[prefix]
nums = union(nums, getArgNums(args, prefix))
end
-- The following is roughly equivalent to the old {{Ambox/category}}.
local date = args.date
date = type(date) == 'string' and date
local preposition = 'from'
for _, num in ipairs(nums) do
local mainCat = args['cat' .. tostring(num)]
or args['kategori' .. tostring(num)]
local allCat = args['all' .. tostring(num)]
mainCat = type(mainCat) == 'string' and mainCat
allCat = type(allCat) == 'string' and allCat
if mainCat and date and date ~= '' then
local catTitle = string.format('%s %s %s', mainCat, preposition, date)
self:addCat(0, catTitle)
catTitle = getTitleObject('Category:' .. catTitle)
if not catTitle or not catTitle.exists then
self:addCat(0, 'Articles with invalid date parameter in template')
end
elseif mainCat and (not date or date == '') then
self:addCat(0, mainCat)
end
if allCat then
self:addCat(0, allCat)
end
end
end
function MessageBox:setTemplateCategories()
local args = self.args
local cfg = self.cfg
-- Add template categories.
if cfg.templateCategory then
if cfg.templateCategoryRequireName then
if self.isTemplatePage then
self:addCat(
end
elseif not self.title.isSubpage then
self:addCat(
end
end
-- Add template error
if cfg.templateErrorCategory then
local templateErrorCategory = cfg.templateErrorCategory
Baris 468 ⟶ 422:
end
end
self:addCat(
end
end
function MessageBox:setAllNamespaceCategories()
-- Set categories for all namespaces.
if self.invalidTypeError then
local allSort = (self.
self:addCat('all', '
end
if self.isSubstituted then
self:addCat('all', '
end
end
function MessageBox:setCategories()
if self.title.namespace == 0 then
self:setMainspaceCategories()
elseif self.title.namespace == 10 then
self:setTemplateCategories()
end
self:setAllNamespaceCategories()
end
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
-- [[Module:Category handler]].
return require('Modul:Category handler')._main{
main =
template =
all =
nocat = self.args.nocat,
}
end
function
local root =
-- Add the subst check error.
if self.isSubstituted and self.name then
root:tag('b')
:wikitext(string.format(
'Templat <code>%s[[Template:%s|%s]]%s</code> tidak disubtitusikan dengan benar.',
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
-- Create the box table.
local boxTable = root
boxTable:attr('id', self.id or nil)
for i, class in ipairs(self.classes or {}) do
boxTable:addClass(class or nil)
end
boxTable
if self.attrs then
end
-- Add the left-hand image.
local row = boxTable
if self.imageLeft then
local imageLeftCell = row
if self.imageCellDiv then
-- If we are using a div, redefine imageLeftCell so that the image
Baris 531 ⟶ 515:
-- 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.
imageLeftCell = imageLeftCell
end
imageLeftCell:wikitext(self.imageLeft or nil)
elseif self.imageEmptyCell then
-- Some message boxes define an empty cell if no image is specified, and
Baris 540 ⟶ 523:
-- specified gives the following hint: "No image. Cell with some width
-- or padding necessary for text cell to have 100% width."
row
end
-- Add the text.
local textCell = row
if self.useCollapsibleTextFields then
-- The message box uses advanced text parameters that allow things to be
-- collapsible. At the moment, only ambox uses this.
textCell:cssText(self.textstyle or nil)
local textCellDiv = textCell:tag('div')
textCellDiv
:addClass('mbox-text-span')
:wikitext(self.issue or nil)
textCellDiv:tag('span')
:addClass('hide-when-compact')
:wikitext(self.talk and (' ' .. self.talk) or nil)
:wikitext(self.fix and (' ' .. self.fix) or nil)
end
if self.info and not self.isSmall then
textCellDiv
:tag('span')
:addClass('hide-when-compact')
:wikitext(self.info and (' ' .. self.info) or nil)
end
if self.removalNotice then
textCellDiv:tag('span')
:addClass('hide-when-compact')
:tag('i')
:wikitext(string.format(" (%s)", self.removalNotice))
end
else
-- Default text formatting - anything goes.
textCell
end
-- Add the right-hand image.
if self.imageRight then
local imageRightCell = row
if self.imageCellDiv then
-- If we are using a div, redefine imageRightCell so that the image
-- is inside it.
imageRightCell = imageRightCell
end
imageRightCell
end
-- Add the below row.
if self.below then
boxTable
end
-- Add error message for invalid type parameters.
if self.invalidTypeError then
root:tag('div')
:wikitext(string.format(
'This message box is using an invalid "type=%s" parameter and needs fixing.',
self.type or ''
))
end
-- Add categories.
root:wikitext(self:renderCategories() or nil)
return tostring(root)
end
--------------------------------------------------------------------------------
-- Exports
--------------------------------------------------------------------------------
local p, mt = {}, {}
function p._exportClasses()
-- For testing.
return {
MessageBox = MessageBox
}
end
local box = MessageBox.new(boxType, args, cfgTables or mw.loadData(CONFIG_MODULE))
box:setParameters()
box:setCategories()
return box:export()
end
function mt.__index(t, k)
return function (frame)
if not getArgs then
getArgs = require('Module:Arguments').getArgs
end
return t.main(k, getArgs(frame, {trim = false, removeBlanks = false}))
end
end
return setmetatable(p, mt)
|