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.
localp={}-- Counting function accepting a string haystack and table of needleslocalfunctioncount(haystack,needles)localnumber=0localindex=1localneedle=needles[index]-- While we have needles to look forwhileneedledo-- find them all in our haystackforminstring.gmatch(haystack,needle)donumber=number+1endindex=index+1needle=needles[index]endreturnnumberend-- Function accepting any number of page names and section level numbersfunctionp.sections(frame)localindex=1localtotal=0localpage=""localpages={}localneedles={}localhaystack=""-- Iterate through the args to find the page names and section levelsforkey,valueinpairs(frame.args)do-- If the param specifies the section levels requiredifkey=='level'then-- for every section level numberforlevelinmw.text.gsplit(value,"")doiflevel~=" "then-- add the needle to our table of needlesneedles[#needles+1]="\n"..string.rep("=",tonumber(level)).."[^=]"endend-- Otherwise, add the page name to our tableelseifvaluethenpages[#pages+1]=valueendend-- For each page name in our tablepage=pages[index]whilepagedo-- get the raw markuphaystack=mw.title.new(page)-- count the sections and add to the totaltotal=total+count(haystack:getContent(),needles)index=index+1page=pages[index]end--[[ then return how many sections of the required level are in all the pages passed ]]returntotalendreturnp