وحدة:Running header
المظهر
توثيق الوحدة [أنشئ] [محو الاختزان][استخدامات] [قوالب]
--[=[
Implements [[Template:RunningHeader]]
]=]
require('strict')
local getArgs = require('Module:Arguments with aliases').getArgs
local p = {}
function p._running_header(args)
-- holds tracking categories
local tracking_cats = {}
-- aliases for first 3 parameters
if args.right or args.center or args.left then
-- this is fine but it's worth keeping track of
table.insert(tracking_cats, '[[تصنيف:رأس صفحة مع وسائط مسماة]]')
-- check for duplicates (which are a problem)
if (args[3] and args.left) or (args[2] and args.center) or (args[1] and args.right) then
table.insert(tracking_cats, '[[تصنيف:صفحات مع وسائط مكررة]]')
end
-- use aliases
args[1] = args[1] or args.right
args[2] = args[2] or args.center
args[3] = args[3] or args.left
end
-- get number of cells (largest-numbered parameter)
-- can't use #args because that doesn't work consistently on tables that aren't sequences
-- table.maxn also seems not to work
local cell_count = 0
for k, v in pairs(args) do
local i = tonumber(k)
if i and i > cell_count then
cell_count = i
end
end
-- track headers which don't set the contents of every cell
local undefined_entries = false
-- track how many cells have content
local content_entries = 0
for i = 1, cell_count do
if not args[i] then
undefined_entries = true
elseif args[i] and args[i] ~= '' then
content_entries = content_entries + 1
end
end
if undefined_entries then
-- track headers with undefined entries (fine but worth keeping track of)
table.insert(tracking_cats, '[[تصنيف:رأس صفحة بدون تعيين وسائط]]')
end
if content_entries == 1 then
-- track headers with only one non-blank entry
table.insert(tracking_cats, '[[تصنيف:رأس صفحة مع مدخل وحيد]]')
end
if cell_count == 0 or content_entries == 0 then
-- track headers with no entries (pointless)
table.insert(tracking_cats, '[[تصنيف:رأس صفحة فارغ]]')
elseif cell_count == 1 then
-- track 1-cell headers (fine but worth keeping track of)
table.insert(tracking_cats, '[[تصنيف:رأس صفحة مع مدخل وحيد]]')
elseif cell_count == 2 then
-- track 2-cell headers (fine but worth keeping track of)
table.insert(tracking_cats, '[[تصنيف:رأس صفحة مع مدخلين]]')
elseif cell_count > 4 then
-- track headers with more than 4 cells (fine but worth keeping track of)
table.insert(tracking_cats, '[[تصنيف:رأس صفحة مع أكثر من 4 مداخل]]')
end
-- TEMPORARY FOR MIGRATION: enforce 3-cell minimum
cell_count = math.max(cell_count, 3)
-- assemble cells
local cells = {}
-- classes
local base_class = 'wst-rh'
local cell_class = base_class .. '-cell'
local extra_cell_classes = {
[3] = {'wst-rh-right', 'wst-rh-center', 'wst-rh-left'}
}
extra_cell_classes = extra_cell_classes[cell_count] or {}
for i = 1, cell_count do
cells[i] = mw.html.create('div')
:addClass(cell_class)
:wikitext(args[i] or '')
if extra_cell_classes[i] then
cells[i]:addClass(extra_cell_classes[i])
end
cells[i] = tostring(cells[i])
end
-- assemble header
local header_class = table.concat({
base_class,
base_class .. '-' .. cell_count,
args.class or (base_class .. '-default')
}, ' ')
local header_div = mw.html.create('div')
:addClass(header_class)
:wikitext(table.concat(cells))
return tostring(header_div) .. table.concat(tracking_cats)
end
function p.running_header(frame)
local args = getArgs(frame, {trim = true, removeBlanks = false, aliases={left = 'يسار', right = 'يمين', center={'centre', 'وسط'}}})
return p._running_header(args)
end
return p