Modul:Message box: Perbedaan antara revisi

Konten dihapus Konten ditambahkan
k Melindungi "Modul:Message box": 7. Templat atau modul yang banyak digunakan ([Sunting=Hanya untuk pengurus] (selamanya) [Pindahkan=Hanya untuk pengurus] (selamanya))
Nyilvoskt (bicara | kontrib)
Tidak ada ringkasan suntingan
Tag: Suntingan perangkat seluler Suntingan peramban seluler Suntingan seluler lanjutan
 
(15 revisi perantara oleh 6 pengguna tidak ditampilkan)
Baris 1:
require('strict')
-- This is a meta-module for producing message box templates, including
-- {{mbox}}, {{ambox}}, {{imbox}}, {{tmbox}}, {{ombox}}, {{cmbox}} and {{fmbox}}.
 
-- Load necessary modules.
require('Modul:No globals')
local getArgs
local categoryHandler = require('Modul:Category handler')._main
local yesno = require('Modul:Yesno')
 
-- Get a language object for formatDate and ucfirst.
local lang = mw.language.getContentLanguage()
 
-- Define constants
local CONFIG_MODULE = 'Modul:Message box/configuration'
local DEMOSPACES = {talk = 'tmbox', image = 'imbox', file = 'imbox', category = 'cmbox', article = 'ambox', main = 'ambox'}
 
--------------------------------------------------------------------------------
-- HelperFungsi functionspembantu
--------------------------------------------------------------------------------
 
local function getTitleObject(...)
-- Mendapatkan nilai objek judul dan kemudian menyalurkan fungsi ke kode pcall
-- 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, ...)
if success then
Baris 57 ⟶ 49:
 
--------------------------------------------------------------------------------
-- Definisi kelas kotak
-- Box class definition
--------------------------------------------------------------------------------
 
Baris 67 ⟶ 59:
local obj = {}
 
-- Pengaturan nilai objek judul dengan ruang nama.
-- Set the title object and the namespace.
obj.title = getTitleObject(args.page) or mw.title.getCurrentTitle()
 
-- konfigurasi kotak pesan.
-- Set the config for our box type.
obj.cfg = cfg[boxType]
if not obj.cfg then
local ns = obj.title.namespace
-- boxType isdiatur sebagai "mbox" oratau pemasukan akan bernilai invalidtidak inputterduga
if nsargs.demospace =and args.demospace ~= 0'' then
-- demospasi mbox
local demospace = string.lower(args.demospace)
if DEMOSPACES[demospace] then
-- penggunaan templat dari DEMOSPACES
obj.cfg = cfg[DEMOSPACES[demospace]]
elseif string.find( demospace, 'talk' ) 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
elseif ns == 6 then
Baris 91 ⟶ 96:
end
 
-- pengaturan argumen
-- Set the arguments, and remove all blank arguments except for the ones
-- listed in cfg.allowBlankParams.
do
Baris 106 ⟶ 111:
end
 
-- DefinePenentuan internalstruktur data structure.
obj.categories = {}
obj.classes = {}
-- Pemuatan [[Modul:Category handler]].
obj.hasCategories = false
 
return setmetatable(obj, MessageBox)
Baris 122 ⟶ 129:
cat = string.format('[[Kategori:%s]]', cat)
end
self.hasCategories = true
self.categories[ns] = self.categories[ns] or {}
table.insert(self.categories[ns], cat)
Baris 147 ⟶ 155:
self.typeImage = typeData.image
 
-- Menentukan apakah kotak yang ada mengalami kesalahan atau tidak.
-- Find if the box has been wrongly substituted.
self.isSubstituted = cfg.substCheck and args.subst == 'SUBST'
 
-- Menentukan penggunaan kotak pesan yang digunakan.
-- Find whether we are using a small message box.
self.isSmall = cfg.allowSmall and (
cfg.smallParam and args.small == cfg.smallParam
Baris 158 ⟶ 166:
-- Add attributes, classes and styles.
self.id = args.id
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')
Baris 183 ⟶ 195:
and cfg.templateCategoryRequireName
then
self.name = args.name
if self.name then
local templateName = mw.ustring.match(
Baris 189 ⟶ 200:
'^[tT][eE][mM][pP][lL][aA][tT][eE][%s_]*:[%s_]*(.*)$'
) or self.name
templateName = 'TemplateTemplat:' .. templateName
self.templateTitle = getTitleObject(templateName)
end
Baris 195 ⟶ 206:
and mw.title.equals(self.title, self.templateTitle)
end
 
-- Pemrosesan data pada
-- Process data for collapsible text fields. At the moment these are only
-- used in {{ambox}}.
if self.useCollapsibleTextFields then
-- Get the self.issue value.
Baris 205 ⟶ 216:
local sect
if args.sect == '' then
sect = 'Halaman ' .. (cfg.sectionDefault or 'page')
elseif type(args.sect) == 'string' then
sect = 'Halaman ' .. args.sect
end
local issue = args.issue
Baris 249 ⟶ 260:
end
if talkTitle and talkTitle.exists then
local talkText
local talkText = 'Diskusi yang sesuai mungkin dapat ditemukan di'
if self.isSmall then
if talkArgIsTalkPage then
local talkLink = talkArgIsTalkPage and talk or (talkTitle.prefixedText .. '#' .. talk)
talkText = string.format(
talkText = string.format('([[%s|pembicaraan]])', talkLink)
'%s [[%s|%s]].',
else
talkText,
talkText = 'Diskusi terkait dapat dibaca pada'
talk,
if talkArgIsTalkPage then
talkTitle.prefixedText
talkText = string.format(
)
'%s [[%s|%s]].',
else
talkText,
talkText = string.format(
talk,
'%s the [[%s#%s|halaman pembicaraan]].',
talkTitle.prefixedText
talkText,
)
talkTitle.prefixedText,
else
talk
talkText = string.format(
)
'%s the [[%s#%s|halaman pembicaraan]].',
end
talkText,
talkTitle.prefixedText,
talk
)
end
end
self.talk = talkText
end
Baris 278 ⟶ 295:
end
if date then
self.date = string.format(" <small>span class='date-container'><i>(<span class='date'>%s</span>)''</smalli></span>", date)
end
self.info = args.info
Baris 300 ⟶ 317:
self.imageCellDiv = not self.isSmall and cfg.imageCellDiv
self.imageEmptyCell = cfg.imageEmptyCell
if cfg.imageEmptyCellStyle then
self.imageEmptyCellStyle = 'border:none;padding:0px;width:1px'
end
 
-- Left image settings.
Baris 324 ⟶ 338:
self.imageRight = imageRight
end
-- set templatestyles
self.base_templatestyles = cfg.templatestyles
self.templatestyles = args.templatestyles
end
 
Baris 335 ⟶ 353:
 
local nums = {}
for _, prefix in ipairs{'cat', 'categorykategori', 'all'} do
args[prefix .. '1'] = args[prefix]
nums = union(nums, getArgNums(args, prefix))
Baris 346 ⟶ 364:
for _, num in ipairs(nums) do
local mainCat = args['cat' .. tostring(num)]
or args['categorykategori' .. tostring(num)]
local allCat = args['all' .. tostring(num)]
mainCat = type(mainCat) == 'string' and mainCat
Baris 355 ⟶ 373:
catTitle = getTitleObject('Category:' .. catTitle)
if not catTitle or not catTitle.exists then
self:addCat(0, 'ArtikelArticles denganwith parameterinvalid tanggaldate yang tidak validparameter padain templattemplate')
end
elseif mainCat and (not date or date == '') then
Baris 415 ⟶ 433:
end
if self.isSubstituted then
self:addCat('all', 'Halaman dengan templatkesalahan yangsubtitusi salah disubstitusitemplat')
end
end
Baris 429 ⟶ 447:
 
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{
return categoryHandler{
main = table.concat(self.categories[0] or {}),
template = table.concat(self.categories[10] or {}),
Baris 448 ⟶ 472:
:addClass('error')
:wikitext(string.format(
'Templat <code>%s[[Template:%s|%s]]%s</code> yangtidak salahdisubtitusikan disubstitusidengan 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
 
Baris 476 ⟶ 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:tag('div'):cssaddClass('width', '52pxmbox-image-div')
end
imageLeftCell:wikitext(self.imageLeft or nil)
Baris 486 ⟶ 525:
row:tag('td')
:addClass('mbox-empty-cell')
:cssText(self.imageEmptyCellStyle or nil)
end
 
Baris 499 ⟶ 537:
:addClass('mbox-text-span')
:wikitext(self.issue or nil)
if (self.talk or self.fix) and not self.isSmall then
textCellDiv:tag('span')
:addClass('hide-when-compact')
Baris 513 ⟶ 551:
end
if self.removalNotice then
textCellDiv:tag('smallspan')
:addClass('hide-when-compact')
:tag('i')
Baris 531 ⟶ 569:
-- If we are using a div, redefine imageRightCell so that the image
-- is inside it.
imageRightCell = imageRightCell:tag('div'):cssaddClass('width', '52pxmbox-image-div')
end
imageRightCell
Baris 550 ⟶ 588:
if self.invalidTypeError then
root:tag('div')
:cssaddClass('textmbox-align', 'centerinvalid-type')
:wikitext(string.format(
'KotaThis pesanmessage inibox menggunakanis parameterusing an invalid "type=%s" yang tidak validparameter danand membutuhkanneeds perbaikanfixing.',
self.type or ''
))
Baris 586 ⟶ 624:
return function (frame)
if not getArgs then
getArgs = require('ModulModule:Arguments').getArgs
end
return t.main(k, getArgs(frame, {trim = false, removeBlanks = false}))