Module:Uses Chart
| This module depends on the following other modules: |
Implements {{Uses Chart}}.
A couple test cases
| ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
One style page
Multiple style pages
Sandbox version of style page exists
No style pages specified
Unicode
|
--Based on [[Module:Uses TemplateStyles]]
local yesno = require('Module:Yesno')
local mList = require('Module:List')
local mTableTools = require('Module:TableTools')
local mMessageBox = require('Module:Message box')
local TNT = require('Module:TNT')
local p = {}
local function format(msg, ...)
return TNT.format('I18n/Uses Chart', msg, ...)
end
local function getConfig()
return mw.loadData('Module:Uses Chart/config')
end
local function renderBox(cSources)
local boxArgs = {
type = 'notice',
small = true,
image = string.format('[[File:Chart_extension_logo.svg|32px|alt=%s]]', format('logo-alt'))
}
if #cSources < 1 then
boxArgs.text = format(mw.title.getCurrentTitle():inNamespaces(828,829) and 'emptylist-module' or 'emptylist-template')
else
local cfg = getConfig()
local cSourcesLinks = {}
for i, cs in ipairs(cSources) do
cs = mw.ustring.gsub(mw.ustring.gsub(cs, "^:?[Cc]ommons:", ""), "^[Dd]ata:", "")
local csTitle = mw.title.new(cs)
cs = csTitle.fullText
local link
if csTitle.namespace ~= 828 then
cs = "Data:" .. cs
if not (mw.ustring.find(cs, "%.chart$") or mw.ustring.find(cs, "%.tab$")) then
link = string.format('[[:commons:%s.chart|%s.chart]] ([[:commons:%s.tab|.tab]])', cs, cs, cs)
end
end
link = link or string.format('[[:commons:%s|%s]]', cs, cs)
cSourcesLinks[i] = link
end
local cSourcesList = mList.makeList('bulleted', cSourcesLinks)
boxArgs.text = format(
mw.title.getCurrentTitle():inNamespaces(828,829) and 'header-module' or 'header-template') ..
'\n' .. cSourcesList
end
return mMessageBox.main('mbox', boxArgs)
end
local function renderTrackingCategories(args, cSources, titleObj)
if yesno(args.nocat) then
return ''
end
local cfg = getConfig()
local cats = {}
-- Error category
if #cSources < 1 and cfg['error_category'] then
cats[#cats + 1] = cfg['error_category']
end
-- TemplateStyles category
titleObj = titleObj or mw.title.getCurrentTitle()
if (titleObj.namespace == 10 or titleObj.namespace == 828)
and not cfg['subpage_blacklist'][titleObj.subpageText]
then
local category = args.category or cfg['default_category']
if category then
cats[#cats + 1] = category
end
end
for i, cat in ipairs(cats) do
cats[i] = string.format('[[Category:%s]]', cat)
end
return table.concat(cats)
end
function p._main(args)
local cfg = getConfig()
local cSources = mTableTools.compressSparseArray(args)
local box = renderBox(cSources)
local trackingCategories = renderTrackingCategories(args, cSources)
return box .. trackingCategories
end
function p.main(frame)
local origArgs = frame:getParent().args
local args = {}
for k, v in pairs(origArgs) do
v = v:match('^%s*(.-)%s*$')
if v ~= '' then
args[k] = v
end
end
return p._main(args)
end
return p
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.