This is an old revision of this page, as edited by Frietjes(talk | contribs) at 20:16, 22 April 2014(←Created page with '-- This module implements {{aligned table}} local p = {} function p.table(frame) local args = (frame.args[3] ~= nil) and frame.args or frame:getParent().args...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.Revision as of 20:16, 22 April 2014 by Frietjes(talk | contribs)(←Created page with '-- This module implements {{aligned table}} local p = {} function p.table(frame) local args = (frame.args[3] ~= nil) and frame.args or frame:getParent().args...')
This Lua module is used on 14,000+ pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them.
This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing.
This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing.
-- This module implements {{aligned table}}localp={}functionp.table(frame)localargs=(frame.args[3]~=nil)andframe.argsorframe:getParent().argslocalentries={}localcolclass={}localcolstyle={}localcols=tonumber(args['cols'])or2localclass=args['class']or''localstyle=args['style']or''localleftright=args['leftright']or''localfullwidth=args['fullwidth']or''ifleftright~=''thencolstyle[1]='text-align:left;'colstyle[2]='text-align:right;'end-- create the root tablelocalroot=mw.html.create('table')-- add table style for fullwidth iffullwidth~=''thenroot:css('width','100%'):css('border-collapse','collapse'):css('border-spacing','0px'):css('border','none')end-- add table classesifclass~=''thenroot:addClass(class)end-- add table styleifstyle~=''thenroot:cssText(style)end-- build arrays with the column styles and classesfori=1,colsdocolclass[i]=colclass[i]or''colstyle[i]=colstyle[i]or''ifargs['align'..tostring(i)]thencolstyle[i]='text-align:'..args['align'..tostring(i)]..';'..colstyle[i]endifargs['nowrap'..tostring(i)]andargs['nowrap'..tostring(i)]~=''thencolstyle[i]='white-space:nowrap;'..colstyle[i]endifargs['style'..tostring(i)]thencolstyle[i]=colstyle[i]..args['style'..tostring(i)]endifargs['class'..tostring(i)]thencolclass[i]=args['class'..tostring(i)]endend-- compute the maximum cell indexlocalcellcount=0fork,vinpairs(args)doiftype(k)=='number'thencellcount=math.max(cellcount,k)endend-- compute the number of rowslocalrows=math.ceil(cellcount/cols)-- build the table contentforj=1,rowsdo-- start a new rowlocalrow=root:tag('tr')row:css('vertical-align','top')-- loop over the cells in each rowfori=1,colsdolocalcell=row:tag('td')ifargs['class'..tostring(j)..'.'..tostring(i)]thencell:addClass(args['class'..tostring(j)..'.'..tostring(i)])elseifargs['rowclass'..tostring(j)]thencell:addClass(args['rowclass'..tostring(j)]..'"')elseifcolclass[i]~=''thencell:addClass(colclass[i])endifargs['style'..tostring(j)..'.'..tostring(i)]thencell:cssText(args['style'..tostring(j)..'.'..tostring(i)])elseifargs['rowstyle'..tostring(j)]thencell:cssText(args['rowstyle'..tostring(j)])elseifcolstyle[i]~=''thencell:cssText(colstyle[i])endcell:wikitext(args[rows*(j-1)+i]or'')endend-- return the root table returntostring(root)endreturnp