پودمان:Infobox: تفاوت میان نسخه‌ها

۱٬۵۷۶ بایت اضافه‌شده ،  ‏۲۸ دسامبر ۲۰۲۲
بروزرسانی addImageRow و افزودن has_list_class و lists
بدون خلاصۀ ویرایش
ویکی حقوق>Mojtabakd
(بروزرسانی addImageRow و افزودن has_list_class و lists)
خط ۴: خط ۴:
local root
local root
local empty_row_categories = {}
local empty_row_categories = {}
local category_in_empty_row_pattern = '%[%[%s*رده%s*:[^]]*]]'
local category_in_empty_row_pattern = '%[%[%s*[ر][د][ه]%s*:[^]]*]]'
local has_rows = false
local lists = {
plainlist_t = {
patterns = {
'^plainlist$',
'%splainlist$',
'^plainlist%s',
'%splainlist%s'
},
found = false,
styles = 'Plainlist/styles.css'
},
hlist_t = {
patterns = {
'^hlist$',
'%shlist$',
'^hlist%s',
'%shlist%s'
},
found = false,
styles = 'Hlist/styles.css'
}
}
 
local function has_list_class(args_to_check)
for _, list in pairs(lists) do
if not list.found then
for _, arg in pairs(args_to_check) do
for _, pattern in ipairs(list.patterns) do
if mw.ustring.find(arg or '', pattern) then
list.found = true
break
end
end
if list.found then break end
end
end
end
end


local function fixChildBoxes(sval, tt)
local function fixChildBoxes(sval, tt)
خط ۱۲: خط ۵۱:
local marker = '<span class=special_infobox_marker>'
local marker = '<span class=special_infobox_marker>'
local s = sval
local s = sval
-- start moving templatestyles and categories inside of table rows
local slast = ''
while slast ~= s do
slast = s
s = mw.ustring.gsub(s, '(</[Tt][Rr]%s*>%s*)(%[%[%s*[ر][د][ه]%s*:[^]]*%]%])', '%2%1')
s = mw.ustring.gsub(s, '(</[Tt][Rr]%s*>%s*)(\127[^\127]*UNIQ%-%-templatestyles%-%x+%-QINU[^\127]*\127)', '%2%1')
end
-- end moving templatestyles and categories inside of table rows
s = mw.ustring.gsub(s, '(<%s*[Tt][Rr])', marker .. '%1')
s = mw.ustring.gsub(s, '(<%s*[Tt][Rr])', marker .. '%1')
s = mw.ustring.gsub(s, '(</[Tt][Rr]%s*>)', '%1' .. marker)
s = mw.ustring.gsub(s, '(</[Tt][Rr]%s*>)', '%1' .. marker)
if s:match(marker) then
if mw.ustring.match(s, marker) then
s = mw.ustring.gsub(s, marker .. '%s*' .. marker, '')
s = mw.ustring.gsub(s, marker .. '%s*' .. marker, '')
s = mw.ustring.gsub(s, '([\r\n]|-[^\r\n]*[\r\n])%s*' .. marker, '%1')
s = mw.ustring.gsub(s, '([\r\n]|-[^\r\n]*[\r\n])%s*' .. marker, '%1')
خط ۵۶: خط ۱۰۳:
else
else
return sval
return sval
end
end
-- Cleans empty tables
local function cleanInfobox()
root = tostring(root)
if has_rows == false then
root = mw.ustring.gsub(root, '<table[^<>]*>%s*</table>', '')
end
end
end
end
خط ۸۲: خط ۱۳۷:
local nums = {}
local nums = {}
for k, v in pairs(args) do
for k, v in pairs(args) do
local num = tostring(k):match('^' .. prefix .. '([1-9]%d*)$')
local num = mw.ustring.match(tostring(k), '^' .. prefix .. '([1-9]%d*)$')
if num then table.insert(nums, tonumber(num)) end
if num then table.insert(nums, tonumber(num)) end
end
end
خط ۹۴: خط ۱۴۹:
if rowArgs.header and rowArgs.header ~= '_BLANK_' then
if rowArgs.header and rowArgs.header ~= '_BLANK_' then
has_rows = true
root
root
:tag('tr')
:tag('tr')
خط ۱۰۳: خط ۱۵۹:
:addClass(rowArgs.class)
:addClass(rowArgs.class)
:addClass(args.headerclass)
:addClass(args.headerclass)
:css('text-align', 'center')
-- @deprecated next; target .infobox-<name> .infobox-header
-- @deprecated next; target .infobox-<name> .infobox-header
:cssText(args.headerstyle)
:cssText(args.headerstyle)
خط ۱۱۴: خط ۱۶۹:
end
end
elseif rowArgs.data and rowArgs.data:gsub(
elseif rowArgs.data and rowArgs.data:gsub(
category_in_empty_row_pattern, ''
category_in_empty_row_pattern, ''
):match('^%S') then
):match('^%S') then
has_rows = true
local row = root:tag('tr')
local row = root:tag('tr')
row:addClass(rowArgs.rowclass)
row:addClass(rowArgs.rowclass)
خط ۱۴۸: خط ۲۰۴:
if not args.title then return end
if not args.title then return end


has_rows = true
root
root
:tag('caption')
:tag('caption')
خط ۱۶۰: خط ۲۱۷:
if not args.above then return end
if not args.above then return end


has_rows = true
root
root
:tag('tr')
:tag('tr')
خط ۱۶۶: خط ۲۲۴:
:addClass('infobox-above')
:addClass('infobox-above')
:addClass(args.aboveclass)
:addClass(args.aboveclass)
:css('text-align', 'center')
-- @deprecated next; target .infobox-<name> .infobox-above
-- @deprecated next; target .infobox-<name> .infobox-above
:cssText(args.abovestyle)
:cssText(args.abovestyle)
خط ۱۷۵: خط ۲۳۲:
if not args.below then return end
if not args.below then return end


has_rows = true
root
root
:tag('tr')
:tag('tr')
خط ۱۸۱: خط ۲۳۹:
:addClass('infobox-below')
:addClass('infobox-below')
:addClass(args.belowclass)
:addClass(args.belowclass)
:css('text-align', 'center')
-- @deprecated next; target .infobox-<name> .infobox-below
-- @deprecated next; target .infobox-<name> .infobox-below
:cssText(args.belowstyle)
:cssText(args.belowstyle)
خط ۱۹۰: خط ۲۴۷:
if subheaderArgs.data and
if subheaderArgs.data and
subheaderArgs.data:gsub(category_in_empty_row_pattern, ''):match('^%S') then
subheaderArgs.data:gsub(category_in_empty_row_pattern, ''):match('^%S') then
has_rows = true
local row = root:tag('tr')
local row = root:tag('tr')
row:addClass(subheaderArgs.rowclass)
row:addClass(subheaderArgs.rowclass)
خط ۲۳۰: خط ۲۸۸:
if imageArgs.data and
if imageArgs.data and
imageArgs.data:gsub(category_in_empty_row_pattern, ''):match('^%S') then
imageArgs.data:gsub(category_in_empty_row_pattern, ''):match('^%S') then
has_rows = true
has_list_class({ imageArgs.rowclass, imageArgs.class })
local row = root:tag('tr')
local row = root:tag('tr')
row  
row:addClass(imageArgs.rowclass)
:addClass(imageArgs.rowclass)
:css('text-align', 'center')


local dataCell = row:tag('td')
local dataCell = row:tag('td')
خط ۲۴۱: خط ۳۰۰:
:addClass('infobox-image')
:addClass('infobox-image')
:addClass(imageArgs.class)
:addClass(imageArgs.class)
:css('text-align', 'center')
:cssText(imageArgs.datastyle)
:cssText(imageArgs.datastyle)
:wikitext(fixChildBoxes(imageArgs.data, 'td'))
:wikitext(fixChildBoxes(imageArgs.data, 'td'))
خط ۳۳۰: خط ۳۸۸:
if not args.name then return end
if not args.name then return end


has_rows = true
root
root
:tag('tr')
:tag('tr')
خط ۳۳۵: خط ۳۹۴:
:attr('colspan', '2')
:attr('colspan', '2')
:addClass('infobox-navbar')
:addClass('infobox-navbar')
:css('align', 'center')
:wikitext(require('Module:Navbar')._navbar{
:wikitext(require('Module:Navbar')._navbar{
args.name,
args.name,
خط ۳۷۶: خط ۴۳۴:
Loads the templatestyles for the infobox.
Loads the templatestyles for the infobox.


TODO: load base templatestyles here rather than in MediaWiki:Common.css
TODO: FINISH loading base templatestyles here rather than in
We aren't doing it here yet because there are 4-5000 pages with 'raw' infobox
MediaWiki:Common.css. There are 4-5000 pages with 'raw' infobox tables.
tables. See [[Mediawiki_talk:Common.css/to_do#Infobox]] and/or come help :).
See [[Mediawiki_talk:Common.css/to_do#Infobox]] and/or come help :).
When we do this we should clean up the inline CSS below too.
When we do this we should clean up the inline CSS below too.
Will have to do some bizarre conversion category like with sidebar.
Will have to do some bizarre conversion category like with sidebar.
 
]=]
]=]
local function loadTemplateStyles()
local function loadTemplateStyles()
local frame = mw.getCurrentFrame()
local frame = mw.getCurrentFrame()
-- See function description
-- See function description
-- local base_templatestyles = frame:extensionTag{
local base_templatestyles = frame:extensionTag{
-- name = 'templatestyles', args = { src = cfg.i18n.templatestyles }
name = 'templatestyles', args = { src = 'Module:Infobox/styles.css' }
-- }
}
 
local templatestyles = ''
local templatestyles = ''
if args['templatestyles'] then templatestyles = frame:extensionTag{
if args['templatestyles'] then templatestyles = frame:extensionTag{
خط ۴۱۰: خط ۴۶۸:


return table.concat({
return table.concat({
-- base_templatestyles, -- see function description
base_templatestyles, -- see function description
templatestyles,
templatestyles,
child_templatestyles,
child_templatestyles,
grandchild_templatestyles
grandchild_templatestyles
})
})
end
 
-- common functions between the child and non child cases
local function structure_infobox_common()
renderSubheaders()
renderImages()
preprocessRows()
renderRows()
renderBelowRow()
renderNavBar()
renderItalicTitle()
renderEmptyRowCategories()
renderTrackingCategories()
cleanInfobox()
end
end


خط ۴۳۸: خط ۵۰۹:
:wikitext(args.title)
:wikitext(args.title)
end
end
 
structure_infobox_common()
renderSubheaders()
renderImages()
return loadTemplateStyles() .. root
preprocessRows()
renderRows()
renderBelowRow()
renderNavBar()
renderItalicTitle()
renderEmptyRowCategories()
renderTrackingCategories()
 
return loadTemplateStyles() .. tostring(root)
end
end


خط ۴۶۹: خط ۵۳۱:
local function preprocessArgs(prefixTable, step)
local function preprocessArgs(prefixTable, step)
if type(prefixTable) ~= 'table' then
if type(prefixTable) ~= 'table' then
error("Non-table value detected for the prefix table", 2)
error("مقدار غیر جدولی برای جدول پیشوند شناسایی شد", 2)
end
end
if type(step) ~= 'number' then
if type(step) ~= 'number' then
error("Invalid step value detected", 2)
error("مقدار نامعتبر برای مرحله شناسایی شد", 2)
end
end


خط ۴۷۹: خط ۵۴۱:
if type(v) ~= 'table' or type(v.prefix) ~= "string" or
if type(v) ~= 'table' or type(v.prefix) ~= "string" or
(v.depend and type(v.depend) ~= 'table') then
(v.depend and type(v.depend) ~= 'table') then
error('Invalid input detected to preprocessArgs prefix table', 2)
error('ورودی نامعتبر برای جدول پیشوند preprocessArgs شناسایی شد', 2)
end
end
preprocessSingleArg(v.prefix)
preprocessSingleArg(v.prefix)
خط ۴۸۷: خط ۵۴۹:
for j, dependValue in ipairs(v.depend) do
for j, dependValue in ipairs(v.depend) do
if type(dependValue) ~= 'string' then
if type(dependValue) ~= 'string' then
error('Invalid "depend" parameter value detected in preprocessArgs')
error('مقدار نامعتبر برای پارامتر «depend» در تابع preprocessArgs شناسایی شد')
end
end
preprocessSingleArg(dependValue)
preprocessSingleArg(dependValue)
کاربر ناشناس