Editing Module:Infobox

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. Read the Privacy Policy to learn what information we collect about you and how we use it.

If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 2: Line 2:
-- This module implements {{Infobox}}
-- This module implements {{Infobox}}
--
--
 
local p = {}
local p = {}
local navbar = require('Module:Navbar')._navbar


local args = {}
local args = {}
local origArgs
local origArgs
local root
local root
local function notempty( s ) return s and s:match( '%S' ) end
local function fixChildBoxes(sval, tt)
if notempty(sval) then
local marker = '<span class=special_infobox_marker>'
local s = sval
s = mw.ustring.gsub(s, '(<%s*[Tt][Rr])', marker .. '%1')
s = mw.ustring.gsub(s, '(</[Tt][Rr]%s*>)', '%1' .. marker)
if s:match(marker) then
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, marker .. '%s*([\r\n]|-)', '%1')
s = mw.ustring.gsub(s, '(</[Cc][Aa][Pp][Tt][Ii][Oo][Nn]%s*>%s*)' .. marker, '%1')
s = mw.ustring.gsub(s, '(<%s*[Tt][Aa][Bb][Ll][Ee][^<>]*>%s*)' .. marker, '%1')
s = mw.ustring.gsub(s, '^(%{|[^\r\n]*[\r\n]%s*)' .. marker, '%1')
s = mw.ustring.gsub(s, '([\r\n]%{|[^\r\n]*[\r\n]%s*)' .. marker, '%1')
s = mw.ustring.gsub(s,  marker .. '(%s*</[Tt][Aa][Bb][Ll][Ee]%s*>)', '%1')
s = mw.ustring.gsub(s,  marker .. '(%s*\n|%})', '%1')
end
if s:match(marker) then
local subcells = mw.text.split(s, marker)
s = ''
for k = 1, #subcells do
if k == 1 then
s = s .. subcells[k] .. '</' .. tt .. '></tr>'
elseif k == #subcells then
local rowstyle = ' style="display:none"'
if notempty(subcells[k]) then rowstyle = '' end
s = s .. '<tr' .. rowstyle ..'><' .. tt .. ' colspan=2>\n' .. subcells[k]
elseif notempty(subcells[k]) then
if (k % 2) == 0 then
s = s .. subcells[k]
else
s = s .. '<tr><' .. tt .. ' colspan=2>\n' .. subcells[k] .. '</' .. tt .. '></tr>'
end
end
end
end
-- the next two lines add a newline at the end of lists for the PHP parser
-- https://en.wikipedia.org/w/index.php?title=Template_talk:Infobox_musical_artist&oldid=849054481
-- remove when [[:phab:T191516]] is fixed or OBE
s = mw.ustring.gsub(s, '([\r\n][%*#;:][^\r\n]*)$', '%1\n')
s = mw.ustring.gsub(s, '^([%*#;:][^\r\n]*)$', '%1\n')
return s
else
return sval
end
end


local function union(t1, t2)
local function union(t1, t2)
Line 96: Line 45:
             :tag('tr')
             :tag('tr')
                 :addClass(rowArgs.rowclass)
                 :addClass(rowArgs.rowclass)
                :cssText(rowArgs.rowstyle)
                 :attr('id', rowArgs.rowid)
                 :attr('id', rowArgs.rowid)
                 :tag('th')
                 :tag('th')
Line 105: Line 53:
                     :css('text-align', 'center')
                     :css('text-align', 'center')
                     :cssText(args.headerstyle)
                     :cssText(args.headerstyle)
                    :cssText(rowArgs.rowcellstyle)
                     :wikitext(rowArgs.header)
                     :wikitext(fixChildBoxes(rowArgs.header, 'th'))
     elseif rowArgs.data then
     elseif rowArgs.data then
         local row = root:tag('tr')
         local row = root:tag('tr')
         row:addClass(rowArgs.rowclass)
         row:addClass(rowArgs.rowclass)
        row:cssText(rowArgs.rowstyle)
         row:attr('id', rowArgs.rowid)
         row:attr('id', rowArgs.rowid)
         if rowArgs.label then
         if rowArgs.label then
Line 117: Line 63:
                     :attr('scope', 'row')
                     :attr('scope', 'row')
                     :attr('id', rowArgs.labelid)
                     :attr('id', rowArgs.labelid)
                    :css('text-align', 'left')
                     :cssText(args.labelstyle)
                     :cssText(args.labelstyle)
                    :cssText(rowArgs.rowcellstyle)
                     :wikitext(rowArgs.label)
                     :wikitext(rowArgs.label)
                     :done()
                     :done()
Line 133: Line 79:
             :addClass(rowArgs.class)
             :addClass(rowArgs.class)
             :cssText(rowArgs.datastyle)
             :cssText(rowArgs.datastyle)
            :cssText(rowArgs.rowcellstyle)
             :newline()
             :newline()
             :wikitext(fixChildBoxes(rowArgs.data, 'td'))
             :wikitext(rowArgs.data)
     end
     end
end
end
Line 161: Line 106:
                 :css('font-weight', 'bold')
                 :css('font-weight', 'bold')
                 :cssText(args.abovestyle)
                 :cssText(args.abovestyle)
                 :wikitext(fixChildBoxes(args.above,'th'))
                 :wikitext(args.above)
end
end


Line 175: Line 120:
                 :cssText(args.belowstyle)
                 :cssText(args.belowstyle)
                 :newline()
                 :newline()
                 :wikitext(fixChildBoxes(args.below,'td'))
                 :wikitext(args.below)
end
end


Line 235: Line 180:
             class = args['class' .. tostring(num)],
             class = args['class' .. tostring(num)],
             rowclass = args['rowclass' .. tostring(num)],
             rowclass = args['rowclass' .. tostring(num)],
            rowstyle = args['rowstyle' .. tostring(num)],
            rowcellstyle = args['rowcellstyle' .. tostring(num)],
             dataid = args['dataid' .. tostring(num)],
             dataid = args['dataid' .. tostring(num)],
             labelid = args['labelid' .. tostring(num)],
             labelid = args['labelid' .. tostring(num)],
Line 253: Line 196:
                 :attr('colspan', '2')
                 :attr('colspan', '2')
                 :css('text-align', 'right')
                 :css('text-align', 'right')
                 :wikitext(navbar{
                 :wikitext(mw.getCurrentFrame():expandTemplate({
                     args.name,
                    title = 'navbar',
                    mini = 1,
                     args = { args.name, mini = 1 }
                 })
                 }))
end
end


Line 268: Line 211:
local function renderTrackingCategories()
local function renderTrackingCategories()
     if args.decat ~= 'yes' then
     if args.decat ~= 'yes' then
    if args.child == 'yes' then
        if #(getArgNums('data')) == 0 and mw.title.getCurrentTitle().namespace == 0 then
        if args.title then
            root:wikitext('[[Category:Pages which use embedded infobox templates with the title parameter]]')
        end
        elseif #(getArgNums('data')) == 0 and mw.title.getCurrentTitle().namespace == 0 then
             root:wikitext('[[Category:Articles which use infobox templates with no data rows]]')
             root:wikitext('[[Category:Articles which use infobox templates with no data rows]]')
        end
        if args.child == 'yes' and args.title then
            root:wikitext('[[Category:Articles which use embedded infobox templates with the title parameter]]')
         end
         end
     end
     end
Line 285: Line 227:
          
          
         root
         root
             :addClass((args.subbox ~= 'yes') and 'infobox' or nil)
             :addClass('infobox')
             :addClass(args.bodyclass)
             :addClass(args.bodyclass)
            :attr('cellspacing', 3)
            :css('border-spacing', '3px')
              
              
             if args.subbox == 'yes' then
             if args.subbox == 'yes' then
Line 430: Line 374:
         {prefix = 'data', depend = {'label'}},
         {prefix = 'data', depend = {'label'}},
         {prefix = 'rowclass'},
         {prefix = 'rowclass'},
        {prefix = 'rowstyle'},
        {prefix = 'rowcellstyle'},
         {prefix = 'class'},
         {prefix = 'class'},
         {prefix = 'dataid'},
         {prefix = 'dataid'},
Please note that all contributions to Nonbinary Wiki are considered to be released under the Creative Commons Attribution-ShareAlike (see Nonbinary Wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)

Template used on this page: